Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate build job from pack job and add matrix support #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 79 additions & 35 deletions .github/workflow-gen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@
new("ignore-this",
["IgnoreThis"],
["IgnoreThis.Tests"],
"it"),
"it",
["ubuntu-latest", "windows-latest"]),

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

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

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

foreach (var component in components)
Expand Down Expand Up @@ -54,49 +58,76 @@ void GenerateCiWorkflow(Component component)

workflow.EnvDefaults();

var job = workflow
var buildJob = workflow
.Job("build")
.Name("Build")
.RunsOn(GitHubHostedRunners.UbuntuLatest)
.Defaults().Run("bash", component.Name)
.Job;
.Strategy()
.Matrix(("os", component.RunsOn))
.FailFast(false)
.Job
.RunsOn("${{ matrix.os }}")
.Defaults()
.Run("bash", component.Name)
.Job;

job.Permissions(
actions: Permission.Read,
contents: Permission.Read,
checks: Permission.Write,
packages: Permission.Write);
buildJob.Permissions(checks: Permission.Write, contents: Permission.Read);

job.TimeoutMinutes(15);
buildJob.TimeoutMinutes(15);

job.Step()
buildJob.Step()
.ActionsCheckout();

job.StepSetupDotNet();
buildJob.StepSetupDotNet();

foreach (var testProject in component.Tests)
{
job.StepTestAndReport(component.Name, testProject);
buildJob.StepTestAndReport(component.Name, testProject, "net8.0");
buildJob.StepTestAndReport(component.Name, testProject, "net9.0");
if (component.RunsOn.Contains("windows-latest"))
{
buildJob.StepTestAndReport(component.Name, testProject, "net481");
}
}

job.StepInstallCACerts();
var packJob = workflow.Job("pack")
.Name("Pack")
.RunsOn(GitHubHostedRunners.UbuntuLatest)
.Needs("build")
.Defaults()
.Run("bash", component.Name)
.Job;

packJob.Permissions(
actions: Permission.Read,
contents: Permission.Read,
checks: Permission.Write,
packages: Permission.Write);

packJob.TimeoutMinutes(15);

job.StepToolRestore();
packJob.Step()
.ActionsCheckout();

packJob.StepSetupDotNet();

packJob.StepInstallCACerts();

packJob.StepToolRestore();

foreach (var project in component.Projects)
{
job.StepPack(project);
packJob.StepPack(project);
}

job.StepSign();
packJob.StepSign();

job.StepPush("MyGet", "https://www.myget.org/F/duende_identityserver/api/v2/package", "MYGET");
packJob.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")
packJob.StepPush("GitHub", "https://nuget.pkg.github.com/DuendeSoftware/index.json", "GITHUB_TOKEN")
.Env(("GITHUB_TOKEN", contexts.Secrets.GitHubToken),
("NUGET_AUTH_TOKEN", contexts.Secrets.GitHubToken));

job.StepUploadArtifacts(component.Name);
packJob.StepUploadArtifacts(component.Name);

var fileName = $"{component.Name}-ci";
WriteWorkflow(workflow, fileName);
Expand All @@ -120,7 +151,7 @@ void GenerateReleaseWorkflow(Component component)
.Defaults().Run("bash", component.Name).Job;

tagJob.Step()
.ActionsCheckout();
.ActionsCheckout("11bd71901bbe5b1630ceea73d27597364c9af683");
damianh marked this conversation as resolved.
Show resolved Hide resolved

tagJob.StepSetupDotNet();

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

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

public static class StepExtensions
{
Expand All @@ -197,27 +228,40 @@ public static void StepSetupDotNet(this Job job)
public static Step IfRefMain(this Step step)
=> step.If("github.ref == 'refs/heads/main'");

public static void StepTestAndReport(this Job job, string componentName, string testProject)
public static Step IfWindows(this Step step)
=> step.If("matrix.os == 'windows-latest'");

public static void StepTestAndReport(this Job job, string componentName, string testProject, string framework)
{
var path = $"test/{testProject}";
var logFileName = "Tests.trx";
var flags = $"--logger \"console;verbosity=normal\" " +
var logFileName = $"tests-{framework}.trx";
var flags = $"--configuration Release " +
$"--framework {framework} " +
$"--logger \"console;verbosity=normal\" " +
$"--logger \"trx;LogFileName={logFileName}\" " +
$"--collect:\"XPlat Code Coverage\"";
job.Step()
.Name($"Test - {testProject}")
.Run($"dotnet test -c Release {path} {flags}");
var isWindows = framework == "net481";

job.Step()
.Name($"Test report - {testProject}")
var testStep = job.Step()
.Name($"Test - {testProject}-{framework}")
.Run($"dotnet test {path} {flags}");

var testReportStep = job.Step()
.Name($"Test report {testProject}-{framework}")
.Uses("dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5") // v1.9.1
.If("success() || failure()")
.With(
("name", $"Test Report - {testProject}"),
("name", $"Test Report {testProject}-{framework}"),
("path", $"{componentName}/{path}/TestResults/{logFileName}"),
("reporter", "dotnet-trx"),
("fail-on-error", "true"),
("fail-on-empty", "true"));

if (isWindows)
{
testStep.IfWindows();
testReportStep.IfWindows();
}
}

// These intermediate certificates are required for signing and are not installed on the GitHub runners by default.
Expand Down
57 changes: 49 additions & 8 deletions .github/workflows/access-token-management-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ env:
jobs:
build:
name: Build
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
permissions:
actions: read
checks: write
contents: read
packages: write
defaults:
run:
shell: bash
working-directory: access-token-management
strategy:
matrix:
os:
- ubuntu-latest
fail-fast: false
timeout-minutes: 15
steps:
- name: Checkout
Expand All @@ -42,17 +45,55 @@ jobs:
6.0.x
8.0.x
9.0.x
- name: Test - AccessTokenManagement.Tests
run: dotnet test -c Release test/AccessTokenManagement.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
- name: Test report - AccessTokenManagement.Tests
- name: Test - AccessTokenManagement.Tests-net8.0
run: dotnet test test/AccessTokenManagement.Tests --configuration Release --framework net8.0 --logger "console;verbosity=normal" --logger "trx;LogFileName=tests-net8.0.trx" --collect:"XPlat Code Coverage"
- name: Test report AccessTokenManagement.Tests-net8.0
if: success() || failure()
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
name: Test Report AccessTokenManagement.Tests-net8.0
path: access-token-management/test/AccessTokenManagement.Tests/TestResults/tests-net8.0.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Test - AccessTokenManagement.Tests-net9.0
run: dotnet test test/AccessTokenManagement.Tests --configuration Release --framework net9.0 --logger "console;verbosity=normal" --logger "trx;LogFileName=tests-net9.0.trx" --collect:"XPlat Code Coverage"
- name: Test report AccessTokenManagement.Tests-net9.0
if: success() || failure()
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
name: Test Report - AccessTokenManagement.Tests
path: access-token-management/test/AccessTokenManagement.Tests/TestResults/Tests.trx
name: Test Report AccessTokenManagement.Tests-net9.0
path: access-token-management/test/AccessTokenManagement.Tests/TestResults/tests-net9.0.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
pack:
name: Pack
needs:
- build
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
contents: read
packages: write
defaults:
run:
shell: bash
working-directory: access-token-management
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Dotnet
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25
with:
dotnet-version: |-
6.0.x
8.0.x
9.0.x
- name: Install Sectigo CodeSiging CA certificates
run: |-
sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/access-token-management-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
working-directory: access-token-management
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
- name: Setup Dotnet
Expand Down
70 changes: 62 additions & 8 deletions .github/workflows/identity-model-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ env:
jobs:
build:
name: Build
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
permissions:
actions: read
checks: write
contents: read
packages: write
defaults:
run:
shell: bash
working-directory: identity-model
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
fail-fast: false
timeout-minutes: 15
steps:
- name: Checkout
Expand All @@ -42,17 +46,67 @@ jobs:
6.0.x
8.0.x
9.0.x
- name: Test - IdentityModel.Tests
run: dotnet test -c Release test/IdentityModel.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
- name: Test report - IdentityModel.Tests
- name: Test - IdentityModel.Tests-net8.0
run: dotnet test test/IdentityModel.Tests --configuration Release --framework net8.0 --logger "console;verbosity=normal" --logger "trx;LogFileName=tests-net8.0.trx" --collect:"XPlat Code Coverage"
- name: Test report IdentityModel.Tests-net8.0
if: success() || failure()
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
name: Test Report IdentityModel.Tests-net8.0
path: identity-model/test/IdentityModel.Tests/TestResults/tests-net8.0.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Test - IdentityModel.Tests-net9.0
run: dotnet test test/IdentityModel.Tests --configuration Release --framework net9.0 --logger "console;verbosity=normal" --logger "trx;LogFileName=tests-net9.0.trx" --collect:"XPlat Code Coverage"
- name: Test report IdentityModel.Tests-net9.0
if: success() || failure()
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
name: Test Report - IdentityModel.Tests
path: identity-model/test/IdentityModel.Tests/TestResults/Tests.trx
name: Test Report IdentityModel.Tests-net9.0
path: identity-model/test/IdentityModel.Tests/TestResults/tests-net9.0.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Test - IdentityModel.Tests-net481
if: matrix.os == 'windows-latest'
run: dotnet test test/IdentityModel.Tests --configuration Release --framework net481 --logger "console;verbosity=normal" --logger "trx;LogFileName=tests-net481.trx" --collect:"XPlat Code Coverage"
- name: Test report IdentityModel.Tests-net481
if: matrix.os == 'windows-latest'
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5
with:
name: Test Report IdentityModel.Tests-net481
path: identity-model/test/IdentityModel.Tests/TestResults/tests-net481.trx
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
pack:
name: Pack
needs:
- build
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
contents: read
packages: write
defaults:
run:
shell: bash
working-directory: identity-model
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Dotnet
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25
with:
dotnet-version: |-
6.0.x
8.0.x
9.0.x
- name: Install Sectigo CodeSiging CA certificates
run: |-
sudo apt-get update
Expand Down
Loading
Loading