Skip to content

Commit 16fbbb7

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

File tree

5 files changed

+65
-28
lines changed

5 files changed

+65
-28
lines changed

.github/workflow-gen/Program.cs

Lines changed: 55 additions & 18 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

@@ -100,8 +107,7 @@ void GenerateReleaseWorkflow(Component component)
100107
.Name("Tag and Pack")
101108
.RunsOn(GitHubHostedRunners.UbuntuLatest)
102109
.Permissions(contents: Permission.Write, packages: Permission.Write)
103-
.Defaults().Run("pwsh", component.Name)
104-
.Job;
110+
.Defaults().Run("bash", component.Name).Job;
105111

106112
tagJob.Step()
107113
.ActionsCheckout();
@@ -110,12 +116,10 @@ void GenerateReleaseWorkflow(Component component)
110116

111117
tagJob.Step()
112118
.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-
""");
119+
.Run($@"git config --global user.email ""github-bot@duendesoftware.com""
120+
git config --global user.name ""Duende Software GitHub Bot""
121+
git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}""
122+
git push origin {component.TagPrefix}-{contexts.Event.Input.Version}");
119123

120124
tagJob.StepInstallCACerts();
121125

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

131135
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 }}"));
136+
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
137+
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));
134138

135139
tagJob.StepUploadArtifacts(component.Name);
136140

@@ -164,7 +168,7 @@ void WriteWorkflow(Workflow workflow, string fileName)
164168
Console.WriteLine($"Wrote workflow to {filePath}");
165169
}
166170

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

169173
public static class StepExtensions
170174
{
@@ -219,7 +223,6 @@ sudo update-ca-certificates
219223
public static void StepToolRestore(this Job job)
220224
=> job.Step()
221225
.Name("Tool restore")
222-
//.IfRefMain()
223226
.Run("dotnet tool restore");
224227

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
packages: write
2222
defaults:
2323
run:
24-
shell: pwsh
24+
shell: bash
2525
working-directory: access-token-management
2626
steps:
2727
- name: Checkout
@@ -36,8 +36,8 @@ jobs:
3636
run: |-
3737
git config --global user.email "github-bot@duendesoftware.com"
3838
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 }}
39+
git tag -a atm-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
40+
git push origin atm-${{ github.event.inputs.version }}
4141
- name: Install Sectigo CodeSiging CA certificates
4242
run: |-
4343
sudo apt-get update

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
packages: write
2222
defaults:
2323
run:
24-
shell: pwsh
24+
shell: bash
2525
working-directory: identity-model-oidc-client
2626
steps:
2727
- name: Checkout
@@ -36,8 +36,8 @@ jobs:
3636
run: |-
3737
git config --global user.email "github-bot@duendesoftware.com"
3838
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 }}
39+
git tag -a imoc-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
40+
git push origin imoc-${{ github.event.inputs.version }}
4141
- name: Install Sectigo CodeSiging CA certificates
4242
run: |-
4343
sudo apt-get update

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
packages: write
2222
defaults:
2323
run:
24-
shell: pwsh
24+
shell: bash
2525
working-directory: identity-model
2626
steps:
2727
- name: Checkout
@@ -36,8 +36,8 @@ jobs:
3636
run: |-
3737
git config --global user.email "github-bot@duendesoftware.com"
3838
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 }}
39+
git tag -a im-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
40+
git push origin im-${{ github.event.inputs.version }}
4141
- name: Install Sectigo CodeSiging CA certificates
4242
run: |-
4343
sudo apt-get update

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
packages: write
2222
defaults:
2323
run:
24-
shell: pwsh
24+
shell: bash
2525
working-directory: ignore-this
2626
steps:
2727
- name: Checkout

0 commit comments

Comments
 (0)