|
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); |
0 commit comments