forked from logicality-io/libs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
139 lines (111 loc) · 3.38 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using Logicality.GitHub.Actions.Workflow;
void WriteWorkflow(Workflow workflow, string fileName)
{
var filePath = $"../workflows/{fileName}.yml";
workflow.WriteYaml(filePath);
Console.WriteLine($"Wrote workflow to {filePath}");
}
void GenerateWorkflowsForLibs()
{
var libs = new[]
{
"aspnet-core",
"bullseye",
"configuration",
"github",
"hosting",
"lambda",
"pulumi",
"system-extensions",
"testing"
};
foreach (var lib in libs)
{
var workflow = new Workflow($"{lib}-ci");
var paths = new[] { $".github/workflows/{lib}-**", $"libs/{lib}**", "build/**" };
workflow.On
.PullRequest()
.Paths(paths);
workflow.On
.Push()
.Branches("main")
.Paths(paths)
.Tags($"{lib}-**");
var buildJob = workflow
.Job("build")
.RunsOn(GitHubHostedRunners.UbuntuLatest)
.Env(
("GITHUB_TOKEN", "${{secrets.GITHUB_TOKEN}}"),
("LOGICALITY_NUGET_ORG", "${{secrets.LOGICALITY_NUGET_ORG}}"));
buildJob.Step().ActionsCheckout();
buildJob.Step().LogIntoGitHubContainerRegistry();
buildJob.Step().PrintEnvironment();
buildJob.Step()
.Name("Test")
.Run($"./build.ps1 {lib}-test")
.Shell(Shells.Pwsh);
buildJob.Step()
.Name("Pack")
.Run($"./build.ps1 {lib}-pack")
.Shell(Shells.Pwsh);
buildJob.Step()
.Name("Push to GitHub")
.If("github.event_name == 'push'")
.Run("./build.ps1 push-github")
.ContinueOnError(true)
.Shell(Shells.Pwsh);
buildJob.Step()
.Name("Push to Nuget.org (on tag)")
.If($"startsWith(github.ref, 'refs/tags/{lib}')")
.Run("./build.ps1 push-nugetorg")
.ContinueOnError(true)
.Shell(Shells.Pwsh);
buildJob.Step().ActionsUploadArtifact();
var fileName = $"{lib}-ci";
WriteWorkflow(workflow, fileName);
}
}
void GenerateCodeAnalysisWorkflow()
{
var workflow = new Workflow("CodeQL");
workflow.On
.Push()
.Branches("main");
workflow.On
.PullRequest()
.Branches("main");
workflow.On
.Schedule("39 8 * * 1");
var job = workflow
.Job("analyze")
.Name("Analyse")
.RunsOn("ubuntu-latest")
.Permissions(
actions: Permission.Read,
contents: Permission.Read,
securityEvents: Permission.Write)
.Strategy()
.FailFast(false)
.Matrix(("language", new[] { "csharp" }))
.Job;
job.Step().ActionsCheckout();
job.Step()
.Name("Setup dotnet")
.Uses("actions/setup-dotnet@v2")
.With(("dotnet-version", "6.0.x"));
job.Step()
.Run("dotnet --info");
job.Step()
.Name("Initialize CodeQL")
.Uses("github/codeql-action/init@v1")
.With(("languages", "${{ matrix.language }}"));
job.Step()
.Run("./build.ps1 local build")
.Shell(Shells.Pwsh);
job.Step()
.Name("Perform CodeQL Analysis")
.Uses("github/codeql-action/analyze@v1");
WriteWorkflow(workflow, "codeql-analysis");
}
GenerateWorkflowsForLibs();
GenerateCodeAnalysisWorkflow();