-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also nicer way to manage of contexts
- Loading branch information
Showing
5 changed files
with
75 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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); | ||
|
||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
||
|
@@ -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); | ||
|
||
|
@@ -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 | ||
{ | ||
|
@@ -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) | ||
|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ jobs: | |
packages: write | ||
defaults: | ||
run: | ||
shell: pwsh | ||
shell: bash | ||
working-directory: access-token-management | ||
steps: | ||
- name: Checkout | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ jobs: | |
packages: write | ||
defaults: | ||
run: | ||
shell: pwsh | ||
shell: bash | ||
working-directory: identity-model-oidc-client | ||
steps: | ||
- name: Checkout | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ jobs: | |
packages: write | ||
defaults: | ||
run: | ||
shell: pwsh | ||
shell: bash | ||
working-directory: identity-model | ||
steps: | ||
- name: Checkout | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters