Skip to content

Commit

Permalink
Fix release workflows tag prefixes
Browse files Browse the repository at this point in the history
Also nicer way to manage of contexts
  • Loading branch information
damianh committed Nov 11, 2024
1 parent b70084a commit caec2eb
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 28 deletions.
75 changes: 57 additions & 18 deletions .github/workflow-gen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using Logicality.GitHub.Actions.Workflow;
using static GitHubContexts;


var contexts = Instance;
Component[] components = [
new("ignore-this",
["IgnoreThis"],
["IgnoreThis.Tests"]),
["IgnoreThis.Tests"],
"it"),

new("access-token-management",
["AccessTokenManagement", "AccessTokenManagement.OpenIdConnect"],
["AccessTokenManagement.Tests"]),
["AccessTokenManagement.Tests"],
"atm"),

new("identity-model",
["IdentityModel"],
["IdentityModel.Tests"]),
["IdentityModel.Tests"],
"im"),

new("identity-model-oidc-client",
["IdentityModel.OidcClient", "IdentityModel.OidcClient.Extensions"],
["IdentityModel.OidcClient.Tests"])
["IdentityModel.OidcClient.Tests"],
"imoc")
];

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

job.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
.Env(("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}"),
("NUGET_AUTH_TOKEN", "${{ secrets.GITHUB_TOKEN }}"));
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));

job.StepUploadArtifacts(component.Name);

Expand All @@ -100,8 +107,7 @@ void GenerateReleaseWorkflow(Component component)
.Name("Tag and Pack")
.RunsOn(GitHubHostedRunners.UbuntuLatest)
.Permissions(contents: Permission.Write, packages: Permission.Write)
.Defaults().Run("pwsh", component.Name)
.Job;
.Defaults().Run("bash", component.Name).Job;

tagJob.Step()
.ActionsCheckout();
Expand All @@ -110,12 +116,10 @@ void GenerateReleaseWorkflow(Component component)

tagJob.Step()
.Name("Git tag")
.Run("""
git config --global user.email "[email protected]"
git config --global user.name "Duende Software GitHub Bot"
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin it-${{ github.event.inputs.version }}
""");
.Run($@"git config --global user.email ""[email protected]""
git config --global user.name ""Duende Software GitHub Bot""
git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}""
git push origin {component.TagPrefix}-{contexts.Event.Input.Version}");

tagJob.StepInstallCACerts();

Expand All @@ -124,13 +128,15 @@ git push origin it-${{ github.event.inputs.version }}
tagJob.StepPack(project);
}

tagJob.StepToolRestore();

tagJob.StepSign();

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

tagJob.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
.Env(("GITHUB_TOKEN", "${{ secrets.GITHUB_TOKEN }}"),
("NUGET_AUTH_TOKEN", "${{ secrets.GITHUB_TOKEN }}"));
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));

tagJob.StepUploadArtifacts(component.Name);

Expand Down Expand Up @@ -164,7 +170,7 @@ void WriteWorkflow(Workflow workflow, string fileName)
Console.WriteLine($"Wrote workflow to {filePath}");
}

record Component(string Name, string[] Projects, string[] Tests);
record Component(string Name, string[] Projects, string[] Tests, string TagPrefix);

public static class StepExtensions
{
Expand Down Expand Up @@ -219,7 +225,6 @@ sudo update-ca-certificates
public static void StepToolRestore(this Job job)
=> job.Step()
.Name("Tool restore")
//.IfRefMain()
.Run("dotnet tool restore");

public static void StepPack(this Job job, string project)
Expand Down Expand Up @@ -271,3 +276,37 @@ public static void StepUploadArtifacts(this Job job, string componentName)
("retention-days", "15"));
}
}

public class GitHubContexts
{
public static GitHubContexts Instance { get; } = new();
public virtual GitHubContext GitHub { get; } = new();
public virtual SecretsContext Secrets { get; } = new();
public virtual EventContext Event { get; } = new();

public abstract class Context(string name)
{
protected string Name => name;

protected string Expression(string s) => "${{ " + s + " }}";
}

public class GitHubContext() : Context("github")
{
}

public class SecretsContext() : Context("secrets")
{
public string GitHubToken => Expression($"{Name}.GITHUB_TOKEN");
}

public class EventContext() : Context("github.event")
{
public EventsInputContext Input { get; } = new ();
}

public class EventsInputContext() : Context("github.event.inputs")
{
public string Version => Expression($"{Name}.version");
}
}
8 changes: 5 additions & 3 deletions .github/workflows/access-token-management-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
packages: write
defaults:
run:
shell: pwsh
shell: bash
working-directory: access-token-management
steps:
- name: Checkout
Expand All @@ -36,8 +36,8 @@ jobs:
run: |-
git config --global user.email "[email protected]"
git config --global user.name "Duende Software GitHub Bot"
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin it-${{ github.event.inputs.version }}
git tag -a atm-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin atm-${{ github.event.inputs.version }}
- name: Install Sectigo CodeSiging CA certificates
run: |-
sudo apt-get update
Expand All @@ -49,6 +49,8 @@ jobs:
run: dotnet pack -c Release src/AccessTokenManagement -o artifacts
- name: Pack AccessTokenManagement.OpenIdConnect
run: dotnet pack -c Release src/AccessTokenManagement.OpenIdConnect -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
run: |-
for file in artifacts/*.nupkg; do
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/identity-model-oidc-client-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
packages: write
defaults:
run:
shell: pwsh
shell: bash
working-directory: identity-model-oidc-client
steps:
- name: Checkout
Expand All @@ -36,8 +36,8 @@ jobs:
run: |-
git config --global user.email "[email protected]"
git config --global user.name "Duende Software GitHub Bot"
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin it-${{ github.event.inputs.version }}
git tag -a imoc-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin imoc-${{ github.event.inputs.version }}
- name: Install Sectigo CodeSiging CA certificates
run: |-
sudo apt-get update
Expand All @@ -49,6 +49,8 @@ jobs:
run: dotnet pack -c Release src/IdentityModel.OidcClient -o artifacts
- name: Pack IdentityModel.OidcClient.Extensions
run: dotnet pack -c Release src/IdentityModel.OidcClient.Extensions -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
run: |-
for file in artifacts/*.nupkg; do
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/identity-model-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
packages: write
defaults:
run:
shell: pwsh
shell: bash
working-directory: identity-model
steps:
- name: Checkout
Expand All @@ -36,8 +36,8 @@ jobs:
run: |-
git config --global user.email "[email protected]"
git config --global user.name "Duende Software GitHub Bot"
git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin it-${{ github.event.inputs.version }}
git tag -a im-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin im-${{ github.event.inputs.version }}
- name: Install Sectigo CodeSiging CA certificates
run: |-
sudo apt-get update
Expand All @@ -47,6 +47,8 @@ jobs:
working-directory: .github/workflows
- name: Pack IdentityModel
run: dotnet pack -c Release src/IdentityModel -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
run: |-
for file in artifacts/*.nupkg; do
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ignore-this-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
packages: write
defaults:
run:
shell: pwsh
shell: bash
working-directory: ignore-this
steps:
- name: Checkout
Expand All @@ -47,6 +47,8 @@ jobs:
working-directory: .github/workflows
- name: Pack IgnoreThis
run: dotnet pack -c Release src/IgnoreThis -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
run: |-
for file in artifacts/*.nupkg; do
Expand Down

0 comments on commit caec2eb

Please sign in to comment.