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

Push nuget nupkg and snupkg together #459

Merged
merged 1 commit into from
Feb 8, 2023
Merged
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
24 changes: 22 additions & 2 deletions src/targets/nuget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const NUGET_DOTNET_BIN = process.env.NUGET_DOTNET_BIN || 'dotnet';
export const DEFAULT_NUGET_SERVER_URL = 'https://api.nuget.org/v3/index.json';

/** A regular expression used to find the package tarball */
const DEFAULT_NUGET_REGEX = /^.*\d\.\d.*\.s?nupkg$/;
const DEFAULT_NUGET_REGEX = /^.*\d\.\d.*\.nupkg$/;
const SYMBOLS_NUGET_REGEX = /^.*\d\.\d.*\.snupkg$/;

/** Nuget target configuration options */
export interface NugetTargetOptions {
Expand Down Expand Up @@ -87,6 +88,9 @@ export class NugetTarget extends BaseTarget {
const packageFiles = await this.getArtifactsForRevision(revision, {
includeNames: DEFAULT_NUGET_REGEX,
});
const symbolFiles = await this.getArtifactsForRevision(revision, {
includeNames: SYMBOLS_NUGET_REGEX,
});

if (!packageFiles.length) {
reportError(
Expand All @@ -106,8 +110,24 @@ export class NugetTarget extends BaseTarget {
await Promise.all(
packageFiles.map(async (file: RemoteArtifact) => {
const path = await this.artifactProvider.downloadArtifact(file);

// If an artifact containing a .snupkg file exists with the same base
// name as the .nupkg file, then download it to the same location.
// It will be picked up automatically when pushing the .nupkg.

// Note, this approach is required vs sending them separately, because
// we need to send the .nupkg *first*, and it must succeed before the
// .snupkg is sent.

const symbolFileName = file.filename.replace('.nupkg', '.snupkg');
const symbolFile = symbolFiles.find(f => f.filename === symbolFileName);
if (symbolFile) {
await this.artifactProvider.downloadArtifact(symbolFile);
}

this.logger.info(
`Uploading file "${file.filename}" via "dotnet nuget"`
`Uploading file "${file.filename}" via "dotnet nuget"` +
(symbolFile ? `, including symbol file "${symbolFile.filename}"` : '')
);
return this.uploadAsset(path);
})
Expand Down