Skip to content

Commit d87faa8

Browse files
committed
Always sign packages in release workflow
1 parent 5a6ecd3 commit d87faa8

9 files changed

+29
-49
lines changed

.github/workflow-gen/Program.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ void GenerateCiWorkflow(Component component)
8888

8989
job.StepSign();
9090

91-
job.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET");
92-
9391
job.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
9492
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
9593
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));
@@ -136,7 +134,7 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
136134

137135
tagJob.StepToolRestore();
138136

139-
tagJob.StepSign();
137+
tagJob.StepSign(true);
140138

141139
tagJob.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET");
142140

@@ -149,8 +147,7 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
149147
var publishJob = workflow.Job("publish")
150148
.Name("Publish to nuget.org")
151149
.RunsOn(GitHubHostedRunners.UbuntuLatest)
152-
.Needs("tag")
153-
.Environment("nuget.org", "");
150+
.Needs("tag");
154151

155152
publishJob.Step()
156153
.Uses("actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16") // 4.1.8
@@ -193,6 +190,10 @@ public static void StepSetupDotNet(this Job job)
193190
public static Step IfRefMain(this Step step)
194191
=> step.If("github.ref == 'refs/heads/main'");
195192

193+
public static Job RunEitherOnBranchOrAsPR(this Job job)
194+
=> job.If(
195+
"(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || (github.event_name == 'push')");
196+
196197
public static void StepTestAndReport(this Job job, string componentName, string testProject)
197198
{
198199
var path = $"test/{testProject}";
@@ -207,7 +208,7 @@ public static void StepTestAndReport(this Job job, string componentName, string
207208
job.Step()
208209
.Name($"Test report - {testProject}")
209210
.Uses("dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5") // v1.9.1
210-
.If("github.event == 'push' && (success() || failure())")
211+
.If("github.event_name == 'push' && (success() || failure())")
211212
.With(
212213
("name", $"Test Report - {testProject}"),
213214
("path", $"{componentName}/{path}/TestResults/{logFileName}"),
@@ -229,7 +230,7 @@ public static void StepPack(this Job job, string project)
229230
.Run($"dotnet pack -c Release {path} -o artifacts");
230231
}
231232

232-
public static void StepSign(this Job job)
233+
public static void StepSign(this Job job, bool always = false)
233234
{
234235
var flags = "--file-digest sha256 " +
235236
"--timestamp-rfc3161 http://timestamp.digicert.com " +
@@ -238,21 +239,24 @@ public static void StepSign(this Job job)
238239
"--azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 " +
239240
"--azure-key-vault-client-secret ${{ secrets.SignClientSecret }} " +
240241
"--azure-key-vault-certificate NuGetPackageSigning";
241-
job.Step()
242-
.Name("Sign packages")
243-
.IfGithubEventIsPushOrWorkflowDispatch()
244-
.Run($"""
245-
for file in artifacts/*.nupkg; do
246-
dotnet NuGetKeyVaultSignTool sign "$file" {flags}
247-
done
248-
""");
242+
var step = job.Step()
243+
.Name("Sign packages");
244+
if (!always)
245+
{
246+
step = step.IfGithubEventIsPush();
247+
}
248+
step.Run($"""
249+
for file in artifacts/*.nupkg; do
250+
dotnet NuGetKeyVaultSignTool sign "$file" {flags}
251+
done
252+
""");
249253
}
250254
/// <summary>
251255
/// Only run this if the build is triggered on a branch IN the same repo
252256
/// this means it's from a trusted contributor.
253257
/// </summary>
254-
public static Step IfGithubEventIsPushOrWorkflowDispatch(this Step step)
255-
=> step.If("github.event == 'push' || github.event == 'workflow_dispatch'");
258+
public static Step IfGithubEventIsPush(this Step step)
259+
=> step.If("github.event_name == 'push'");
256260

257261
public static Step StepPush(this Job job, string destination, string sourceUrl, string secretName)
258262
{

.github/workflows/access-token-management-ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Test - AccessTokenManagement.Tests
4646
run: dotnet test -c Release test/AccessTokenManagement.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
4747
- name: Test report - AccessTokenManagement.Tests
48-
if: github.event == 'push' && (success() || failure())
48+
if: github.event_name == 'push' && (success() || failure())
4949
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
5050
with:
5151
name: Test Report - AccessTokenManagement.Tests
@@ -60,14 +60,11 @@ jobs:
6060
- name: Pack AccessTokenManagement.OpenIdConnect
6161
run: dotnet pack -c Release src/AccessTokenManagement.OpenIdConnect -o artifacts
6262
- name: Sign packages
63-
if: github.event == 'push' || github.event == 'workflow_dispatch'
63+
if: github.event_name == 'push'
6464
run: |-
6565
for file in artifacts/*.nupkg; do
6666
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
6767
done
68-
- name: Push packages to MyGet
69-
if: github.ref == 'refs/heads/main'
70-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
7168
- name: Push packages to GitHub
7269
if: github.ref == 'refs/heads/main'
7370
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

.github/workflows/access-token-management-release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ jobs:
4848
- name: Tool restore
4949
run: dotnet tool restore
5050
- name: Sign packages
51-
if: github.event == 'push' || github.event == 'workflow_dispatch'
5251
run: |-
5352
for file in artifacts/*.nupkg; do
5453
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
@@ -75,8 +74,6 @@ jobs:
7574
needs:
7675
- tag
7776
runs-on: ubuntu-latest
78-
environment:
79-
name: nuget.org
8077
steps:
8178
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
8279
with:

.github/workflows/identity-model-ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Test - IdentityModel.Tests
4646
run: dotnet test -c Release test/IdentityModel.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
4747
- name: Test report - IdentityModel.Tests
48-
if: github.event == 'push' && (success() || failure())
48+
if: github.event_name == 'push' && (success() || failure())
4949
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
5050
with:
5151
name: Test Report - IdentityModel.Tests
@@ -58,14 +58,11 @@ jobs:
5858
- name: Pack IdentityModel
5959
run: dotnet pack -c Release src/IdentityModel -o artifacts
6060
- name: Sign packages
61-
if: github.event == 'push' || github.event == 'workflow_dispatch'
61+
if: github.event_name == 'push'
6262
run: |-
6363
for file in artifacts/*.nupkg; do
6464
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
6565
done
66-
- name: Push packages to MyGet
67-
if: github.ref == 'refs/heads/main'
68-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
6966
- name: Push packages to GitHub
7067
if: github.ref == 'refs/heads/main'
7168
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

.github/workflows/identity-model-oidc-client-ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Test - IdentityModel.OidcClient.Tests
4646
run: dotnet test -c Release test/IdentityModel.OidcClient.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
4747
- name: Test report - IdentityModel.OidcClient.Tests
48-
if: github.event == 'push' && (success() || failure())
48+
if: github.event_name == 'push' && (success() || failure())
4949
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
5050
with:
5151
name: Test Report - IdentityModel.OidcClient.Tests
@@ -60,14 +60,11 @@ jobs:
6060
- name: Pack IdentityModel.OidcClient.Extensions
6161
run: dotnet pack -c Release src/IdentityModel.OidcClient.Extensions -o artifacts
6262
- name: Sign packages
63-
if: github.event == 'push' || github.event == 'workflow_dispatch'
63+
if: github.event_name == 'push'
6464
run: |-
6565
for file in artifacts/*.nupkg; do
6666
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
6767
done
68-
- name: Push packages to MyGet
69-
if: github.ref == 'refs/heads/main'
70-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
7168
- name: Push packages to GitHub
7269
if: github.ref == 'refs/heads/main'
7370
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

.github/workflows/identity-model-oidc-client-release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ jobs:
4848
- name: Tool restore
4949
run: dotnet tool restore
5050
- name: Sign packages
51-
if: github.event == 'push' || github.event == 'workflow_dispatch'
5251
run: |-
5352
for file in artifacts/*.nupkg; do
5453
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
@@ -75,8 +74,6 @@ jobs:
7574
needs:
7675
- tag
7776
runs-on: ubuntu-latest
78-
environment:
79-
name: nuget.org
8077
steps:
8178
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
8279
with:

.github/workflows/identity-model-release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
- name: Tool restore
4747
run: dotnet tool restore
4848
- name: Sign packages
49-
if: github.event == 'push' || github.event == 'workflow_dispatch'
5049
run: |-
5150
for file in artifacts/*.nupkg; do
5251
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
@@ -73,8 +72,6 @@ jobs:
7372
needs:
7473
- tag
7574
runs-on: ubuntu-latest
76-
environment:
77-
name: nuget.org
7875
steps:
7976
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
8077
with:

.github/workflows/ignore-this-ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Test - IgnoreThis.Tests
4646
run: dotnet test -c Release test/IgnoreThis.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
4747
- name: Test report - IgnoreThis.Tests
48-
if: github.event == 'push' && (success() || failure())
48+
if: github.event_name == 'push' && (success() || failure())
4949
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
5050
with:
5151
name: Test Report - IgnoreThis.Tests
@@ -58,14 +58,11 @@ jobs:
5858
- name: Pack IgnoreThis
5959
run: dotnet pack -c Release src/IgnoreThis -o artifacts
6060
- name: Sign packages
61-
if: github.event == 'push' || github.event == 'workflow_dispatch'
61+
if: github.event_name == 'push'
6262
run: |-
6363
for file in artifacts/*.nupkg; do
6464
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
6565
done
66-
- name: Push packages to MyGet
67-
if: github.ref == 'refs/heads/main'
68-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
6966
- name: Push packages to GitHub
7067
if: github.ref == 'refs/heads/main'
7168
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

.github/workflows/ignore-this-release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ jobs:
4646
- name: Tool restore
4747
run: dotnet tool restore
4848
- name: Sign packages
49-
if: github.event == 'push' || github.event == 'workflow_dispatch'
5049
run: |-
5150
for file in artifacts/*.nupkg; do
5251
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.vault.azure.net/ --azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 --azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 --azure-key-vault-client-secret ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
@@ -73,8 +72,6 @@ jobs:
7372
needs:
7473
- tag
7574
runs-on: ubuntu-latest
76-
environment:
77-
name: nuget.org
7875
steps:
7976
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
8077
with:

0 commit comments

Comments
 (0)