Skip to content
Merged
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
30 changes: 30 additions & 0 deletions .github/scripts/csharp-workflow-policy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,36 @@ test("gates both package publishers on a release preflight", () => {
}
});

test("packs and publishes each NuGet package in separate ordered steps", () => {
for (const [jobName, outputDirectory] of [
["pushNuGetPackageToGitHubPackageRegistry", "github-packages"],
["pushToNuget", "nuget-packages"],
]) {
const job = jobs.get(jobName);
const output = `"$RUNNER_TEMP/${outputDirectory}"`;
const pack = job.indexOf("- name: Pack NuGet package");
const push = job.indexOf("- name: Push NuGet package");

assert.ok(pack >= 0, `${jobName} has no pack step`);
assert.ok(push > pack, `${jobName} must push after packing`);
assert.match(job.slice(pack, push), /run: dotnet pack /);
assert.ok(job.slice(pack, push).includes(`--output ${output}`));
assert.match(job.slice(push), /run: dotnet nuget push /);
assert.ok(job.slice(push).includes(`${output}/*.nupkg`));
assert.equal(
job.slice(pack, push).includes("dotnet nuget push"),
false,
`${jobName} pushes inside the pack step`,
);
}

const github = jobs.get("pushNuGetPackageToGitHubPackageRegistry");
const addSource = github.indexOf("- name: Add GitHub NuGet source");
assert.ok(addSource > github.indexOf("- name: Pack NuGet package"));
assert.ok(addSource < github.indexOf("- name: Push NuGet package"));
assert.match(github.slice(addSource), /run: dotnet nuget add source /);
});

test("builds PDF and API documentation in parallel before publishing both", () => {
const pdf = jobs.get("generatePdfWithCode");
const documentation = jobs.get("buildDocumentation");
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: Publish NuGet package to GitHub Package Registry
- name: Pack NuGet package
run: dotnet pack Platform.Interfaces/Platform.Interfaces.csproj --configuration Release --output "$RUNNER_TEMP/github-packages" --nologo -warnaserror

- name: Add GitHub NuGet source
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
package_output="$RUNNER_TEMP/github-packages"
dotnet pack Platform.Interfaces/Platform.Interfaces.csproj --configuration Release --output "$package_output" --nologo -warnaserror
dotnet nuget add source https://nuget.pkg.github.com/linksplatform/index.json --name GitHub --username linksplatform --password "$GITHUB_TOKEN" --store-password-in-clear-text
dotnet nuget push "$package_output"/*.nupkg --source GitHub --skip-duplicate
run: dotnet nuget add source https://nuget.pkg.github.com/linksplatform/index.json --name GitHub --username linksplatform --password "$GITHUB_TOKEN" --store-password-in-clear-text

- name: Push NuGet package to GitHub Package Registry
run: dotnet nuget push "$RUNNER_TEMP/github-packages"/*.nupkg --source GitHub --skip-duplicate

pushToNuget:
needs: [test, releasePreflight]
Expand All @@ -109,13 +111,13 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: Publish NuGet package
- name: Pack NuGet package
run: dotnet pack Platform.Interfaces/Platform.Interfaces.csproj --configuration Release --output "$RUNNER_TEMP/nuget-packages" --nologo -warnaserror

- name: Push NuGet package to NuGet.org
env:
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}
run: |
package_output="$RUNNER_TEMP/nuget-packages"
dotnet pack Platform.Interfaces/Platform.Interfaces.csproj --configuration Release --output "$package_output" --nologo -warnaserror
dotnet nuget push "$package_output"/*.nupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_TOKEN" --skip-duplicate
run: dotnet nuget push "$RUNNER_TEMP/nuget-packages"/*.nupkg --source https://api.nuget.org/v3/index.json --api-key "$NUGET_TOKEN" --skip-duplicate

publishRelease:
needs: [pushNuGetPackageToGitHubPackageRegistry, pushToNuget]
Expand Down
Loading