Skip to content

Commit ebb5dd8

Browse files
committed
Fix release workflows tag prefixes
Also nicer way to manage of contexts
1 parent b70084a commit ebb5dd8

File tree

5 files changed

+61
-41
lines changed

5 files changed

+61
-41
lines changed

.github/workflow-gen/Program.cs

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,30 @@
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;
5+
using static GitHubContexts;
56

7+
8+
var contexts = Instance;
69
Component[] components = [
710
new("ignore-this",
811
["IgnoreThis"],
9-
["IgnoreThis.Tests"]),
12+
["IgnoreThis.Tests"],
13+
"it"),
1014

1115
new("access-token-management",
1216
["AccessTokenManagement", "AccessTokenManagement.OpenIdConnect"],
13-
["AccessTokenManagement.Tests"]),
17+
["AccessTokenManagement.Tests"],
18+
"atm"),
1419

1520
new("identity-model",
1621
["IdentityModel"],
17-
["IdentityModel.Tests"]),
22+
["IdentityModel.Tests"],
23+
"im"),
1824

1925
new("identity-model-oidc-client",
2026
["IdentityModel.OidcClient", "IdentityModel.OidcClient.Extensions"],
21-
["IdentityModel.OidcClient.Tests"])
27+
["IdentityModel.OidcClient.Tests"],
28+
"imoc")
2229
];
2330

2431
foreach (var component in components)
@@ -76,8 +83,8 @@ void GenerateCiWorkflow(Component component)
7683
job.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET");
7784

7885
job.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
79-
.Env(("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}"),
80-
("NUGET_AUTH_TOKEN", "${{ secrets.GITHUB_TOKEN }}"));
86+
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
87+
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));
8188

8289
job.StepUploadArtifacts(component.Name);
8390

@@ -99,9 +106,7 @@ void GenerateReleaseWorkflow(Component component)
99106
.Job("tag")
100107
.Name("Tag and Pack")
101108
.RunsOn(GitHubHostedRunners.UbuntuLatest)
102-
.Permissions(contents: Permission.Write, packages: Permission.Write)
103-
.Defaults().Run("pwsh", component.Name)
104-
.Job;
109+
.Permissions(contents: Permission.Write, packages: Permission.Write);
105110

106111
tagJob.Step()
107112
.ActionsCheckout();
@@ -110,12 +115,10 @@ void GenerateReleaseWorkflow(Component component)
110115

111116
tagJob.Step()
112117
.Name("Git tag")
113-
.Run("""
114-
git config --global user.email "github-bot@duendesoftware.com"
115-
git config --global user.name "Duende Software GitHub Bot"
116-
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
117-
git push origin it-${{ github.event.inputs.version }}
118-
""");
118+
.Run($@"git config --global user.email ""github-bot@duendesoftware.com""
119+
git config --global user.name ""Duende Software GitHub Bot""
120+
git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}""
121+
git push origin {component.TagPrefix}-{contexts.Event.Input.Version}");
119122

120123
tagJob.StepInstallCACerts();
121124

@@ -129,8 +132,8 @@ git push origin it-${{ github.event.inputs.version }}
129132
tagJob.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET");
130133

131134
tagJob.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
132-
.Env(("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}"),
133-
("NUGET_AUTH_TOKEN", "${{ secrets.GITHUB_TOKEN }}"));
135+
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
136+
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));
134137

135138
tagJob.StepUploadArtifacts(component.Name);
136139

@@ -164,7 +167,7 @@ void WriteWorkflow(Workflow workflow, string fileName)
164167
Console.WriteLine($"Wrote workflow to {filePath}");
165168
}
166169

167-
record Component(string Name, string[] Projects, string[] Tests);
170+
record Component(string Name, string[] Projects, string[] Tests, string TagPrefix);
168171

169172
public static class StepExtensions
170173
{
@@ -219,7 +222,6 @@ sudo update-ca-certificates
219222
public static void StepToolRestore(this Job job)
220223
=> job.Step()
221224
.Name("Tool restore")
222-
//.IfRefMain()
223225
.Run("dotnet tool restore");
224226

225227
public static void StepPack(this Job job, string project)
@@ -271,3 +273,37 @@ public static void StepUploadArtifacts(this Job job, string componentName)
271273
("retention-days", "15"));
272274
}
273275
}
276+
277+
public class GitHubContexts
278+
{
279+
public static GitHubContexts Instance { get; } = new();
280+
public virtual GitHubContext GitHub { get; } = new();
281+
public virtual SecretsContext Secrets { get; } = new();
282+
public virtual EventContext Event { get; } = new();
283+
284+
public abstract class Context(string name)
285+
{
286+
protected string Name => name;
287+
288+
protected string Expression(string s) => "${{ " + s + " }}";
289+
}
290+
291+
public class GitHubContext() : Context("github")
292+
{
293+
}
294+
295+
public class SecretsContext() : Context("secrets")
296+
{
297+
public string GitHubToken => Expression($"{Name}.GITHUB_TOKEN");
298+
}
299+
300+
public class EventContext() : Context("github.event")
301+
{
302+
public EventsInputContext Input { get; } = new ();
303+
}
304+
305+
public class EventsInputContext() : Context("github.event.inputs")
306+
{
307+
public string Version => Expression($"{Name}.version");
308+
}
309+
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ jobs:
1919
permissions:
2020
contents: write
2121
packages: write
22-
defaults:
23-
run:
24-
shell: pwsh
25-
working-directory: access-token-management
2622
steps:
2723
- name: Checkout
2824
uses: actions/checkout@v4
@@ -36,8 +32,8 @@ jobs:
3632
run: |-
3733
git config --global user.email "github-bot@duendesoftware.com"
3834
git config --global user.name "Duende Software GitHub Bot"
39-
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
40-
git push origin it-${{ github.event.inputs.version }}
35+
git tag -a atm-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
36+
git push origin atm-${{ github.event.inputs.version }}
4137
- name: Install Sectigo CodeSiging CA certificates
4238
run: |-
4339
sudo apt-get update

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ jobs:
1919
permissions:
2020
contents: write
2121
packages: write
22-
defaults:
23-
run:
24-
shell: pwsh
25-
working-directory: identity-model-oidc-client
2622
steps:
2723
- name: Checkout
2824
uses: actions/checkout@v4
@@ -36,8 +32,8 @@ jobs:
3632
run: |-
3733
git config --global user.email "github-bot@duendesoftware.com"
3834
git config --global user.name "Duende Software GitHub Bot"
39-
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
40-
git push origin it-${{ github.event.inputs.version }}
35+
git tag -a imoc-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
36+
git push origin imoc-${{ github.event.inputs.version }}
4137
- name: Install Sectigo CodeSiging CA certificates
4238
run: |-
4339
sudo apt-get update

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ jobs:
1919
permissions:
2020
contents: write
2121
packages: write
22-
defaults:
23-
run:
24-
shell: pwsh
25-
working-directory: identity-model
2622
steps:
2723
- name: Checkout
2824
uses: actions/checkout@v4
@@ -36,8 +32,8 @@ jobs:
3632
run: |-
3733
git config --global user.email "github-bot@duendesoftware.com"
3834
git config --global user.name "Duende Software GitHub Bot"
39-
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
40-
git push origin it-${{ github.event.inputs.version }}
35+
git tag -a im-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
36+
git push origin im-${{ github.event.inputs.version }}
4137
- name: Install Sectigo CodeSiging CA certificates
4238
run: |-
4339
sudo apt-get update

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ jobs:
1919
permissions:
2020
contents: write
2121
packages: write
22-
defaults:
23-
run:
24-
shell: pwsh
25-
working-directory: ignore-this
2622
steps:
2723
- name: Checkout
2824
uses: actions/checkout@v4

0 commit comments

Comments
 (0)