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
43 changes: 43 additions & 0 deletions .github/scripts/check-csharp-nuget-consumer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

set -euo pipefail

version="${1:?Usage: check-csharp-nuget-consumer.sh <version> [local package]}"
local_package="${2:-}"
repository_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

cp "$repository_root/examples/NuGetConsumer/"{NuGetConsumer.csproj,CollectionMethods.cs} "$work"
if [[ -n "$local_package" ]]; then
mkdir "$work/feed"
cp "$local_package" "$work/feed/"
fi
cd "$work"

sources=(--source https://api.nuget.org/v3/index.json)
if [[ -n "$local_package" ]]; then
cat > NuGet.Config <<'XML'
<configuration>
<packageSources>
<clear />
<add key="local" value="feed" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="local">
<package pattern="Platform.Collections.Methods" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
XML
sources=(--configfile NuGet.Config)
fi

properties=(-p:CollectionsMethodsVersion="$version" -p:TargetFramework="${CONSUMER_FRAMEWORK:-net8.0}")
dotnet restore NuGetConsumer.csproj --nologo --packages "$work/packages" \
-p:RestoreNoCache=true -p:RestoreNoHttpCache=true "${sources[@]}" "${properties[@]}"
dotnet build NuGetConsumer.csproj --nologo --no-restore --configuration Release "${properties[@]}"
13 changes: 10 additions & 3 deletions .github/scripts/cpp-workflow-policy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ test("packs with dotnet and verifies the package on every run", () => {

test("deploys only what the local test workflow built and tested", () => {
assert.match(deployJobs.get("test"), /uses: \.\/\.github\/workflows\/cpp-test\.yml/);
assert.match(deployJobs.get("releasePreflight"), /needs: test/);
assert.match(deployJobs.get("releasePreflight"), /preflight-nuget-release\.mjs/);
assert.match(deployJobs.get("test"), /needs: releasePreflight/);
assert.doesNotMatch(deployJobs.get("releasePreflight"), /needs: test/);
assert.match(deployJobs.get("releasePreflight"), /NUSPEC: .*TemplateLibrary\.nuspec/);
assert.match(deployJobs.get("releasePreflight"), /preflight-nuget-release\.mjs check-version/);
assert.match(deployJobs.get("releasePreflight"), /github\.ref == 'refs\/heads\/main'/);
assert.match(deployJobs.get("releasePreflight"), /continue-on-error: true\n +uses: NuGet\/login@/);
assert.match(deployJobs.get("pushToNuget"), /needs: \[test, releasePreflight\]/);
assert.match(deployJobs.get("pushToNuget"), /push-nuget-package\.sh "\$RUNNER_TEMP\/cpp-nuget"\/\*\.nupkg/);
});
Expand All @@ -88,7 +92,10 @@ test("supports trusted publishing with the API key as a fallback", () => {
const job = deployJobs.get("pushToNuget");
assert.match(job, /\n id-token: write/);
assert.match(job, /uses: NuGet\/login@[0-9a-f]{40} # v\d/);
assert.match(job, /NUGET_API_KEY: \$\{\{ steps\.nuget-login\.outputs\.NUGET_API_KEY \|\| secrets\.NUGET_TOKEN \}\}/);
assert.match(job, /NUGET_OIDC_KEY: .*steps\.nuget-login\.outputs\.NUGET_API_KEY/);
assert.match(job, /NUGET_TOKEN: \$\{\{ secrets\.NUGET_TOKEN \}\}/);
assert.match(job, /continue-on-error: true\n +uses: NuGet\/login@/);
assert.match(job, /wait-for-package/);
});

test("creates the GitHub release only after the NuGet push succeeded", () => {
Expand Down
12 changes: 9 additions & 3 deletions .github/scripts/csharp-workflow-policy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ test("gates both package publishers on a release preflight", () => {
assert.match(preflight, /NUGET_TOKEN: \$\{\{ secrets\.NUGET_TOKEN \}\}/);
assert.match(preflight, /GITHUB_TOKEN: \$\{\{ secrets\.GITHUB_TOKEN \}\}/);
assert.match(preflight, /NUGET_USER: \$\{\{ vars\.NUGET_USER \}\}/);
assert.match(preflight, /preflight-nuget-release\.mjs/);
assert.match(preflight, /preflight-nuget-release\.mjs check-version/);
assert.match(preflight, /github\.event_name == 'push'/);
assert.match(preflight, /continue-on-error: true\n +uses: NuGet\/login@/);

for (const name of [
"pushNuGetPackageToGitHubPackageRegistry",
Expand Down Expand Up @@ -120,10 +122,14 @@ test("publishes to nuget.org only when the preflight found the version missing",
assert.match(job, /uses: NuGet\/login@[0-9a-f]{40} # v\d/);
assert.match(
job,
/if: \$\{\{ needs\.releasePreflight\.outputs\.auth == 'trusted-publishing' && needs\.releasePreflight\.outputs\.publishRequired == 'true' \}\}/,
/if: \$\{\{ needs\.releasePreflight\.outputs\.publishRequired == 'true' && vars\.NUGET_USER != '' \}\}/,
);
assert.match(job, /PUBLISH_REQUIRED: \$\{\{ needs\.releasePreflight\.outputs\.publishRequired \}\}/);
assert.match(job, /NUGET_API_KEY: \$\{\{ steps\.nuget-login\.outputs\.NUGET_API_KEY \|\| secrets\.NUGET_TOKEN \}\}/);
assert.match(job, /NUGET_OIDC_KEY: .*steps\.nuget-login\.outputs\.NUGET_API_KEY/);
assert.match(job, /NUGET_TOKEN: \$\{\{ secrets\.NUGET_TOKEN \}\}/);
assert.match(job, /continue-on-error: true\n +uses: NuGet\/login@/);
assert.match(job, /wait-for-package/);
assert.match(job, /check-csharp-nuget-consumer\.sh/);
assert.doesNotMatch(job, /run: dotnet nuget push/);
});

Expand Down
Loading
Loading