From 2a436f4b601cef9314cf9cd1a24cd5f3fc2bf595 Mon Sep 17 00:00:00 2001 From: Damian Hickey <57436+damianh@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:51:39 +0100 Subject: [PATCH] Fix release workflows tag prefixes Also nicer way to manage of contexts --- .github/workflow-gen/Program.cs | 70 ++++++++++++++----- .../access-token-management-release.yml | 4 +- .../identity-model-oidc-client-release.yml | 4 +- .github/workflows/identity-model-release.yml | 4 +- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/.github/workflow-gen/Program.cs b/.github/workflow-gen/Program.cs index cdcbe3db..be9ec26d 100644 --- a/.github/workflow-gen/Program.cs +++ b/.github/workflow-gen/Program.cs @@ -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 = GitHubContexts.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) @@ -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); @@ -110,12 +117,10 @@ void GenerateReleaseWorkflow(Component component) tagJob.Step() .Name("Git tag") - .Run(""" - git config --global user.email "github-bot@duendesoftware.com" - 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 ""github-bot@duendesoftware.com"" +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(); @@ -129,8 +134,8 @@ git push origin it-${{ github.event.inputs.version }} 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); @@ -164,7 +169,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 { @@ -219,7 +224,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) @@ -271,3 +275,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"); + } +} diff --git a/.github/workflows/access-token-management-release.yml b/.github/workflows/access-token-management-release.yml index 9ec13c63..2c544bf5 100644 --- a/.github/workflows/access-token-management-release.yml +++ b/.github/workflows/access-token-management-release.yml @@ -36,8 +36,8 @@ jobs: run: |- git config --global user.email "github-bot@duendesoftware.com" 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 diff --git a/.github/workflows/identity-model-oidc-client-release.yml b/.github/workflows/identity-model-oidc-client-release.yml index 76b4fffe..49169e56 100644 --- a/.github/workflows/identity-model-oidc-client-release.yml +++ b/.github/workflows/identity-model-oidc-client-release.yml @@ -36,8 +36,8 @@ jobs: run: |- git config --global user.email "github-bot@duendesoftware.com" 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 diff --git a/.github/workflows/identity-model-release.yml b/.github/workflows/identity-model-release.yml index eb060d75..1d5a9468 100644 --- a/.github/workflows/identity-model-release.yml +++ b/.github/workflows/identity-model-release.yml @@ -36,8 +36,8 @@ jobs: run: |- git config --global user.email "github-bot@duendesoftware.com" 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