Skip to content

Commit 368f47d

Browse files
add tag override
1 parent 3a6c226 commit 368f47d

5 files changed

Lines changed: 138 additions & 55 deletions

File tree

.github/workflow-gen/Program.cs

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Duende Software. All rights reserved.
1+
// Copyright (c) Duende Software. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44
using Logicality.GitHub.Actions.Workflow;
@@ -110,8 +110,9 @@ void GenerateReleaseWorkflow(Component component)
110110
workflow.On
111111
.WorkflowDispatch()
112112
.Inputs(
113-
new StringInput("version", "Version in format X.Y.Z or X.Y.Z-preview.", true, "0.0.0")
114-
, new StringInput("target-branch", "(Optional) the name of the branch to release from", false, "main"));
113+
new StringInput("version", "Version in format X.Y.Z or X.Y.Z-preview.", true, "0.0.0"),
114+
new StringInput("branch", "(Optional) the name of the branch to release from", false, "main"),
115+
new BooleanInput("remove-tag-if-exists", "If set, will remove the existing tag. Use this if you have issues with the previous release action", false, false));
115116

116117
workflow.EnvDefaults();
117118

@@ -132,11 +133,26 @@ void GenerateReleaseWorkflow(Component component)
132133

133134
tagJob.StepSetupDotNet();
134135

136+
137+
tagJob.Step()
138+
.Name("Git Config")
139+
.Run(@"git config --global user.email ""github-bot@duendesoftware.com""
140+
git config --global user.name ""Duende Software GitHub Bot""");
141+
142+
tagJob.Step()
143+
.Name("Remove previous git tag")
144+
.If("github.event.inputs['remove-tag-if-exists'] == 'true'")
145+
.Run($@"if git rev-parse {component.TagPrefix}-{contexts.Event.Input.Version} >/dev/null 2>&1; then
146+
git tag -d {component.TagPrefix}-{contexts.Event.Input.Version}
147+
git push --delete origin {component.TagPrefix}-{contexts.Event.Input.Version}
148+
else
149+
echo 'Tag {component.TagPrefix}-{contexts.Event.Input.Version} does not exist.'
150+
fi");
151+
152+
135153
tagJob.Step()
136154
.Name("Git tag")
137-
.Run($@"git config --global user.email ""github-bot@duendesoftware.com""
138-
git config --global user.name ""Duende Software GitHub Bot""
139-
git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}""
155+
.Run($@"git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}""
140156
git push origin {component.TagPrefix}-{contexts.Event.Input.Version}");
141157

142158
foreach (var project in component.Projects)
@@ -146,20 +162,20 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
146162

147163
tagJob.StepToolRestore();
148164

149-
tagJob.StepSign(true);
150-
151-
tagJob.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET");
165+
tagJob.StepSign(always: true);
152166

153-
tagJob.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
167+
tagJob.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN", pushAlways: true)
154168
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
155169
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));
156170

157-
tagJob.StepUploadArtifacts(component.Name);
171+
tagJob.StepUploadArtifacts(component.Name, uploadAlways: true);
158172

159173
var publishJob = workflow.Job("publish")
160174
.Name("Publish to nuget.org")
161175
.RunsOn(GitHubHostedRunners.UbuntuLatest)
162-
.Needs("tag");
176+
.Needs("tag")
177+
.Environment("nuget.org", "");
178+
;
163179

164180
publishJob.Step()
165181
.Uses("actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16") // 4.1.8
@@ -172,7 +188,9 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
172188
.Shell("bash")
173189
.Run("tree");
174190

175-
publishJob.StepPush("nuget.org", "https://api.nuget.org/v3/index.json", "NUGET_ORG_API_KEY");
191+
tagJob.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET", pushAlways: true);
192+
193+
publishJob.StepPush("nuget.org", "https://api.nuget.org/v3/index.json", "NUGET_ORG_API_KEY", pushAlways: true);
176194

177195
var fileName = $"{component.Name}-release";
178196
WriteWorkflow(workflow, fileName);
@@ -320,22 +338,31 @@ dotnet NuGetKeyVaultSignTool sign "$file" {flags}
320338
public static Step IfGithubEventIsPush(this Step step)
321339
=> step.If("github.event_name == 'push'");
322340

323-
public static Step StepPush(this Job job, string destination, string sourceUrl, string secretName)
341+
public static Step StepPush(this Job job, string destination, string sourceUrl, string secretName, bool pushAlways = false)
324342
{
325343
var apiKey = $"${{{{ secrets.{secretName} }}}}";
326-
return job.Step()
327-
.Name($"Push packages to {destination}")
328-
.IfRefMain()
329-
.Run($"dotnet nuget push artifacts/*.nupkg --source {sourceUrl} --api-key {apiKey} --skip-duplicate");
344+
var step = job.Step()
345+
.Name($"Push packages to {destination}");
346+
347+
if (!pushAlways)
348+
{
349+
step.IfRefMain();
350+
}
351+
return step.Run($"dotnet nuget push artifacts/*.nupkg --source {sourceUrl} --api-key {apiKey} --skip-duplicate");
330352
}
331353

332-
public static void StepUploadArtifacts(this Job job, string componentName)
354+
public static void StepUploadArtifacts(this Job job, string componentName, bool uploadAlways = false)
333355
{
334356
var path = $"{componentName}/artifacts/*.nupkg";
335-
job.Step()
336-
.Name("Upload Artifacts")
337-
.IfGithubEventIsPush()
338-
.Uses("actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882") // 4.4.3
357+
var step = job.Step()
358+
.Name("Upload Artifacts");
359+
360+
if (!uploadAlways)
361+
{
362+
step.IfGithubEventIsPush();
363+
}
364+
365+
step.Uses("actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882") // 4.4.3
339366
.With(
340367
("name", "artifacts"),
341368
("path", path),

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ on:
99
type: string
1010
required: true
1111
default: '0.0.0'
12-
target-branch:
12+
branch:
1313
description: '(Optional) the name of the branch to release from'
1414
type: string
1515
required: false
1616
default: 'main'
17+
remove-tag-if-exists:
18+
description: 'If set, will remove the existing tag. Use this if you have issues with the previous release action'
19+
type: boolean
20+
required: false
21+
default: false
1722
env:
1823
DOTNET_NOLOGO: true
1924
DOTNET_CLI_TELEMETRY_OPTOUT: true
@@ -43,10 +48,21 @@ jobs:
4348
6.0.x
4449
8.0.x
4550
9.0.x
46-
- name: Git tag
51+
- name: Git Config
4752
run: |-
4853
git config --global user.email "github-bot@duendesoftware.com"
4954
git config --global user.name "Duende Software GitHub Bot"
55+
- name: Remove previous git tag
56+
if: github.event.inputs['remove-tag-if-exists'] == 'true'
57+
run: |-
58+
if git rev-parse atm-${{ github.event.inputs.version }} >/dev/null 2>&1; then
59+
git tag -d atm-${{ github.event.inputs.version }}
60+
git push --delete origin atm-${{ github.event.inputs.version }}
61+
else
62+
echo 'Tag atm-${{ github.event.inputs.version }} does not exist.'
63+
fi
64+
- name: Git tag
65+
run: |-
5066
git tag -a atm-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
5167
git push origin atm-${{ github.event.inputs.version }}
5268
- name: Pack AccessTokenManagement
@@ -60,28 +76,27 @@ jobs:
6076
for file in artifacts/*.nupkg; do
6177
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
6278
done
63-
- name: Push packages to MyGet
64-
if: github.ref == 'refs/heads/main'
65-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
6679
- name: Push packages to GitHub
67-
if: github.ref == 'refs/heads/main'
6880
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
6981
env:
7082
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7183
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7284
- name: Upload Artifacts
73-
if: github.event_name == 'push'
7485
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
7586
with:
7687
name: artifacts
7788
path: access-token-management/artifacts/*.nupkg
7889
overwrite: true
7990
retention-days: 15
91+
- name: Push packages to MyGet
92+
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
8093
publish:
8194
name: Publish to nuget.org
8295
needs:
8396
- tag
8497
runs-on: ubuntu-latest
98+
environment:
99+
name: nuget.org
85100
steps:
86101
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
87102
with:
@@ -98,5 +113,4 @@ jobs:
98113
run: tree
99114
shell: bash
100115
- name: Push packages to nuget.org
101-
if: github.ref == 'refs/heads/main'
102116
run: dotnet nuget push artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} --skip-duplicate

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ on:
99
type: string
1010
required: true
1111
default: '0.0.0'
12-
target-branch:
12+
branch:
1313
description: '(Optional) the name of the branch to release from'
1414
type: string
1515
required: false
1616
default: 'main'
17+
remove-tag-if-exists:
18+
description: 'If set, will remove the existing tag. Use this if you have issues with the previous release action'
19+
type: boolean
20+
required: false
21+
default: false
1722
env:
1823
DOTNET_NOLOGO: true
1924
DOTNET_CLI_TELEMETRY_OPTOUT: true
@@ -43,10 +48,21 @@ jobs:
4348
6.0.x
4449
8.0.x
4550
9.0.x
46-
- name: Git tag
51+
- name: Git Config
4752
run: |-
4853
git config --global user.email "github-bot@duendesoftware.com"
4954
git config --global user.name "Duende Software GitHub Bot"
55+
- name: Remove previous git tag
56+
if: github.event.inputs['remove-tag-if-exists'] == 'true'
57+
run: |-
58+
if git rev-parse imoc-${{ github.event.inputs.version }} >/dev/null 2>&1; then
59+
git tag -d imoc-${{ github.event.inputs.version }}
60+
git push --delete origin imoc-${{ github.event.inputs.version }}
61+
else
62+
echo 'Tag imoc-${{ github.event.inputs.version }} does not exist.'
63+
fi
64+
- name: Git tag
65+
run: |-
5066
git tag -a imoc-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
5167
git push origin imoc-${{ github.event.inputs.version }}
5268
- name: Pack IdentityModel.OidcClient
@@ -60,28 +76,27 @@ jobs:
6076
for file in artifacts/*.nupkg; do
6177
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
6278
done
63-
- name: Push packages to MyGet
64-
if: github.ref == 'refs/heads/main'
65-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
6679
- name: Push packages to GitHub
67-
if: github.ref == 'refs/heads/main'
6880
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
6981
env:
7082
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7183
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7284
- name: Upload Artifacts
73-
if: github.event_name == 'push'
7485
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
7586
with:
7687
name: artifacts
7788
path: identity-model-oidc-client/artifacts/*.nupkg
7889
overwrite: true
7990
retention-days: 15
91+
- name: Push packages to MyGet
92+
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
8093
publish:
8194
name: Publish to nuget.org
8295
needs:
8396
- tag
8497
runs-on: ubuntu-latest
98+
environment:
99+
name: nuget.org
85100
steps:
86101
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
87102
with:
@@ -98,5 +113,4 @@ jobs:
98113
run: tree
99114
shell: bash
100115
- name: Push packages to nuget.org
101-
if: github.ref == 'refs/heads/main'
102116
run: dotnet nuget push artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} --skip-duplicate

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ on:
99
type: string
1010
required: true
1111
default: '0.0.0'
12-
target-branch:
12+
branch:
1313
description: '(Optional) the name of the branch to release from'
1414
type: string
1515
required: false
1616
default: 'main'
17+
remove-tag-if-exists:
18+
description: 'If set, will remove the existing tag. Use this if you have issues with the previous release action'
19+
type: boolean
20+
required: false
21+
default: false
1722
env:
1823
DOTNET_NOLOGO: true
1924
DOTNET_CLI_TELEMETRY_OPTOUT: true
@@ -43,10 +48,21 @@ jobs:
4348
6.0.x
4449
8.0.x
4550
9.0.x
46-
- name: Git tag
51+
- name: Git Config
4752
run: |-
4853
git config --global user.email "github-bot@duendesoftware.com"
4954
git config --global user.name "Duende Software GitHub Bot"
55+
- name: Remove previous git tag
56+
if: github.event.inputs['remove-tag-if-exists'] == 'true'
57+
run: |-
58+
if git rev-parse im-${{ github.event.inputs.version }} >/dev/null 2>&1; then
59+
git tag -d im-${{ github.event.inputs.version }}
60+
git push --delete origin im-${{ github.event.inputs.version }}
61+
else
62+
echo 'Tag im-${{ github.event.inputs.version }} does not exist.'
63+
fi
64+
- name: Git tag
65+
run: |-
5066
git tag -a im-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
5167
git push origin im-${{ github.event.inputs.version }}
5268
- name: Pack IdentityModel
@@ -58,28 +74,27 @@ jobs:
5874
for file in artifacts/*.nupkg; do
5975
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
6076
done
61-
- name: Push packages to MyGet
62-
if: github.ref == 'refs/heads/main'
63-
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
6477
- name: Push packages to GitHub
65-
if: github.ref == 'refs/heads/main'
6678
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
6779
env:
6880
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6981
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7082
- name: Upload Artifacts
71-
if: github.event_name == 'push'
7283
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
7384
with:
7485
name: artifacts
7586
path: identity-model/artifacts/*.nupkg
7687
overwrite: true
7788
retention-days: 15
89+
- name: Push packages to MyGet
90+
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
7891
publish:
7992
name: Publish to nuget.org
8093
needs:
8194
- tag
8295
runs-on: ubuntu-latest
96+
environment:
97+
name: nuget.org
8398
steps:
8499
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
85100
with:
@@ -96,5 +111,4 @@ jobs:
96111
run: tree
97112
shell: bash
98113
- name: Push packages to nuget.org
99-
if: github.ref == 'refs/heads/main'
100114
run: dotnet nuget push artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} --skip-duplicate

0 commit comments

Comments
 (0)