Skip to content

Commit 702c466

Browse files
committed
wip
1 parent 709eed0 commit 702c466

File tree

3 files changed

+132
-3
lines changed

3 files changed

+132
-3
lines changed

.github/workflow-gen/Program.cs

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,85 @@
1-
// See https://aka.ms/new-console-template for more information
2-
Console.WriteLine("Hello, World!");
1+
using Logicality.GitHub.Actions.Workflow;
2+
using System.IO;
3+
4+
void WriteWorkflow(Workflow workflow, string fileName)
5+
{
6+
var filePath = $"../workflows/{fileName}.yml";
7+
workflow.WriteYaml(filePath);
8+
Console.WriteLine($"Wrote workflow to {filePath}");
9+
}
10+
11+
12+
Component[] components = [
13+
new("ignore-this", ["IgnoreThis"], ["IgnoreThis.Tests"]),
14+
];
15+
16+
(string Key, string Value) EnvSecret(string key) => (key, $"${{secrets.{key}}}");
17+
18+
19+
foreach (var component in components)
20+
{
21+
var workflow = new Workflow($"{component.Name}-ci");
22+
var paths = new[] { $".github/workflows/{component.Name}-ci", $"src/{component.Name}/**" };
23+
24+
workflow.On.WorkflowDispatch();
25+
workflow.On
26+
.Push()
27+
.Branches("main");
28+
workflow.On
29+
.PullRequest()
30+
.Paths(paths);
31+
32+
workflow.Env(
33+
("DOTNETT_NOLOGO", "true"),
34+
("DOTNET_CLI_TELEMETRY_OPTOUT", "true"));
35+
36+
var job = workflow
37+
.Job("build")
38+
.Name("Build")
39+
.RunsOn(GitHubHostedRunners.UbuntuLatest)
40+
.Defaults().Run("pwsh", component.Name)
41+
.Job;
42+
43+
job.Step().ActionsCheckout();
44+
45+
job.Step().ActionsSetupDotNet("8.0.x");
46+
47+
foreach(var testProject in component.Tests)
48+
{
49+
var path = $"{component.Name}/test/{testProject}";
50+
var logFileName = "Tests.trx";
51+
var flags = $"--logger \"console;verbosity=normal\" " +
52+
$"--logger \"trx;LogFileName={logFileName}\" " +
53+
$"--collect:\"XPlat Code Coverage\"";
54+
job.Step()
55+
.Name("Test")
56+
.Run($"dotnet test -c Release {path} {flags}");
57+
58+
job.Step("test-report")
59+
.Name("Test report")
60+
.Uses("dorny/test-reporter@v1")
61+
.If("success() || failure()")
62+
.With(
63+
("name", "Test Report"),
64+
("path", $"{path}/TestResults/{logFileName}"),
65+
("reporter", "dotnet-trx"),
66+
("fail-on-error", "true"),
67+
("fail-on-empty", "true"));
68+
}
69+
70+
job.Step()
71+
.Name("Install Sectigo CodeSiging CA certificates")
72+
.Run("""
73+
sudo apt-get update
74+
sudo apt-get install -y ca-certificates
75+
sudo cp build/SectigoPublicCodeSigningRootCrossAAA.crt /usr/local/share/ca-certificates/
76+
sudo update-ca-certificates
77+
78+
""");
79+
80+
var fileName = $"{component.Name}-ci-gen";
81+
82+
WriteWorkflow(workflow, fileName);
83+
}
84+
85+
record Component(string Name, string[] Projects, string[] Tests);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This was generated by tool. Edits will be overwritten.
2+
3+
name: ignore-this-ci
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
paths:
11+
- .github/workflows/ignore-this-ci
12+
- src/ignore-this/**
13+
env:
14+
DOTNETT_NOLOGO: true
15+
DOTNET_CLI_TELEMETRY_OPTOUT: true
16+
jobs:
17+
build:
18+
name: Build
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
shell: pwsh
23+
working-directory: ignore-this
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
- name: Setup Dotnet
30+
uses: actions/setup-dotnet@v4
31+
with:
32+
dotnet-version: 8.0.x
33+
- name: Test
34+
run: dotnet test -c Release ignore-this/test/IgnoreThis.Tests --logger "console;verbosity=normal" --logger "trx;LogFileName=Tests.trx" --collect:"XPlat Code Coverage"
35+
- id: test-report
36+
name: Test report
37+
if: success() || failure()
38+
uses: dorny/test-reporter@v1
39+
with:
40+
name: Test Report
41+
path: ignore-this/test/IgnoreThis.Tests/TestResults/Tests.trx
42+
reporter: dotnet-trx
43+
fail-on-error: true
44+
fail-on-empty: true
45+
- name: Install Sectigo CodeSiging CA certificates
46+
run: "sudo apt-get update\r\nsudo apt-get install -y ca-certificates\r\nsudo cp build/SectigoPublicCodeSigningRootCrossAAA.crt /usr/local/share/ca-certificates/\r\nsudo update-ca-certificates "

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
fail-on-empty: true
5757

5858
- name: Install Sectigo CodeSiging CA certificates
59-
run: |
59+
run: |-
6060
sudo apt-get update
6161
sudo apt-get install -y ca-certificates
6262
sudo cp build/SectigoPublicCodeSigningRootCrossAAA.crt /usr/local/share/ca-certificates/

0 commit comments

Comments
 (0)