Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget package from private feed not found on nuget.org results in error ("Central Directory corrupt.") #748

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ jobs:
json: true
github-bearer-token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish package to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" ${{ steps.package_release.outputs.package_filename }}

- name: Publish Docker image to Docker Hub
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
run: |
REPO=cyclonedx/cyclonedx-dotnet
docker login --username coderpatros --password "$DOCKER_TOKEN"
docker push $REPO:latest
docker push $REPO:${{ steps.package_release.outputs.version }}
# - name: Publish package to NuGet
# env:
# NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
# run: |
# dotnet nuget push --source https://api.nuget.org/v3/index.json --api-key "$NUGET_API_KEY" ${{ steps.package_release.outputs.package_filename }}
#
# - name: Publish Docker image to Docker Hub
# env:
# DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
# run: |
# REPO=cyclonedx/cyclonedx-dotnet
# docker login --username coderpatros --password "$DOCKER_TOKEN"
# docker push $REPO:latest
# docker push $REPO:${{ steps.package_release.outputs.version }}

- name: Create github release and git tag for release
id: create_release
Expand Down
52 changes: 42 additions & 10 deletions CycloneDX/Services/NugetV3Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using System.Diagnostics.Contracts;
using System.IO;
using System.IO.Abstractions;
using System.IO.Compression;
using System.Net.Http;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -306,23 +308,53 @@ private static Component SetupComponentProperties(Component component, NuspecMod
return component;
}

private async Task<NuspecModel> GetNuspec(string name, string version, string nuspecFilename,
FindPackageByIdResource resource)
private async Task<NuspecModel> GetNuspec(string name, string version, string nuspecFilename, FindPackageByIdResource resource)
{
var nuspecModel = new NuspecModel();
if (nuspecFilename == null)
{
var packageVersion = new NuGetVersion(version);
await using MemoryStream packageStream = new MemoryStream();
await resource.CopyNupkgToStreamAsync(name, packageVersion, packageStream, _sourceCacheContext,
_logger, _cancellationToken);
try
{
var packageVersion = new NuGetVersion(version);


//using (MemoryStream ms = new MemoryStream())
//{
// // Create new ZIP archive within prepared MemoryStream
// using (ZipArchive zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
// {
// zip.CreateEntry(logoimage);
// // ...
// }
// ms.WriteTo(HttpContext.Current.Response.OutputStream);
//}
var doesPackageExist = await resource.DoesPackageExistAsync(name, packageVersion, _sourceCacheContext, _logger, _cancellationToken);
if(doesPackageExist)
{
await using MemoryStream packageStream = new MemoryStream();
await resource.CopyNupkgToStreamAsync(name, packageVersion, packageStream, _sourceCacheContext, _logger, _cancellationToken);
//await resource.CopyNupkgToStreamAsync(name, packageVersion, packageStream, _sourceCacheContext,_logger, _cancellationToken);

using PackageArchiveReader packageReader = new PackageArchiveReader(packageStream);
nuspecModel.nuspecReader = await packageReader.GetNuspecReaderAsync(_cancellationToken);
using PackageArchiveReader packageReader = new PackageArchiveReader(packageStream);
nuspecModel.nuspecReader = await packageReader.GetNuspecReaderAsync(_cancellationToken);

if (!_disableHashComputation)
if (!_disableHashComputation)
{
nuspecModel.hashBytes = ComputeSha215Hash(packageStream);
}
}
else
{
Console.WriteLine($"Package {name} {version} does not exist on {_sourceRepository.PackageSource.Source}");
}

}
catch (Exception ex)
{
nuspecModel.hashBytes = ComputeSha215Hash(packageStream);
Console.WriteLine($"Error while processing package {name} {version}");
_logger.LogError($"Error while processing package {name} {version}");
_logger.LogError(ex.Message);
_logger.LogError(ex.StackTrace);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion semver.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.1
2.8.2