11using Logicality . GitHub . Actions . Workflow ;
2- using System . IO ;
2+
3+ Component [ ] components = [
4+ new ( "ignore-this" ,
5+ [ "IgnoreThis" ] ,
6+ [ "IgnoreThis.Tests" ] ) ,
7+
8+ new ( "access-token-management" ,
9+ [ "AccessTokenManagement" , "AccessTokenManagement.OpenIdConnect" ] ,
10+ [ "AccessTokenManagement.Tests" ] ) ,
11+
12+ new ( "identity-model" ,
13+ [ "IdentityModel" ] ,
14+ [ "IdentityModel.Tests" ] ) ,
15+
16+ new ( "identity-model-oidc-client" ,
17+ [ "IdentityModel.OidcClient" , "IdentityModel.OidcClient.DPoP" , "IdentityModel.OidcClient.IdentityTokenValidator" ] ,
18+ [ "IdentityModel.OidcClient.Tests" , "IdentityModel.OidcClient.DPoP.Tests" , "IdentityModel.OidcClient.IdentityTokenValidator.Tests" ] )
19+ ] ;
320
421void WriteWorkflow ( Workflow workflow , string fileName )
522{
@@ -8,23 +25,15 @@ void WriteWorkflow(Workflow workflow, string fileName)
825 Console . WriteLine ( $ "Wrote workflow to { filePath } ") ;
926}
1027
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 )
28+ void GenerateCIWorkflow ( Component component )
2029{
2130 var workflow = new Workflow ( $ "{ component . Name } -ci") ;
22- var paths = new [ ] { $ ".github/workflows/{ component . Name } -ci ", $ "src/{ component . Name } /**" } ;
31+ var paths = new [ ] { $ ".github/workflows/{ component . Name } -** ", $ "src/{ component . Name } /**" } ;
2332
2433 workflow . On . WorkflowDispatch ( ) ;
2534 workflow . On
2635 . Push ( )
27- . Branches ( "main" ) ;
36+ . Paths ( paths ) ;
2837 workflow . On
2938 . PullRequest ( )
3039 . Paths ( paths ) ;
@@ -37,16 +46,60 @@ void WriteWorkflow(Workflow workflow, string fileName)
3746 . Job ( "build" )
3847 . Name ( "Build" )
3948 . RunsOn ( GitHubHostedRunners . UbuntuLatest )
40- . Defaults ( ) . Run ( "pwsh " , component . Name )
49+ . Defaults ( ) . Run ( "bash " , component . Name )
4150 . Job ;
4251
43- job . Step ( ) . ActionsCheckout ( ) ;
52+ job . Step ( )
53+ . ActionsCheckout ( ) ;
54+
55+ job . Step ( )
56+ . ActionsSetupDotNet ( "8.0.x" ) ;
57+
58+ foreach ( var testProject in component . Tests )
59+ {
60+ job . StepTestAndReport ( component . Name , testProject ) ;
61+ }
62+
63+ job . StepInstallCACerts ( ) ;
64+
65+ job . StepToolRestore ( ) ;
66+
67+ foreach ( var project in component . Projects )
68+ {
69+ job . StepPack ( component . Name , project ) ;
70+ }
71+
72+ job . StepSign ( ) ;
73+
74+ job . StepPush ( "MyGet" , "https://www.myget.org/F/duende_identityserver/api/v2/package" , "MYGET" ) ;
75+
76+ job . StepPush ( "GitHub" , "https://nuget.pkg.github.com/DuendeSoftware/index.json" , "GITHUB_TOKEN" )
77+ . Env (
78+ ( "GITHUB_TOKEN" , "${{ secrets.GITHUB_TOKEN }}" ) ,
79+ ( "NUGET_AUTH_TOKEN" , "${{ secrets.GITHUB_TOKEN }}" ) ) ;
80+
81+ job . StepUploadArtifacts ( component . Name ) ;
82+
83+ var fileName = $ "{ component . Name } -ci";
4484
45- job . Step ( ) . ActionsSetupDotNet ( "8.0.x" ) ;
85+ WriteWorkflow ( workflow , fileName ) ;
86+ }
87+
88+ foreach ( var component in components )
89+ {
90+ GenerateCIWorkflow ( component ) ;
91+ }
92+
93+ record Component ( string Name , string [ ] Projects , string [ ] Tests ) ;
94+
95+ public static class StepExtensions
96+ {
97+ public static Step IfRefMain ( this Step step )
98+ => step . If ( "github.ref == 'refs/heads/main'" ) ;
4699
47- foreach ( var testProject in component . Tests )
100+ public static void StepTestAndReport ( this Job job , string componentName , string testProject )
48101 {
49- var path = $ "{ component . Name } / test/{ testProject } ";
102+ var path = $ "test/{ testProject } ";
50103 var logFileName = "Tests.trx" ;
51104 var flags = $ "--logger \" console;verbosity=normal\" " +
52105 $ "--logger \" trx;LogFileName={ logFileName } \" " +
@@ -61,25 +114,77 @@ void WriteWorkflow(Workflow workflow, string fileName)
61114 . If ( "success() || failure()" )
62115 . With (
63116 ( "name" , "Test Report" ) ,
64- ( "path" , $ "{ path } /TestResults/{ logFileName } ") ,
117+ ( "path" , $ "{ componentName } / { path } /TestResults/{ logFileName } ") ,
65118 ( "reporter" , "dotnet-trx" ) ,
66119 ( "fail-on-error" , "true" ) ,
67120 ( "fail-on-empty" , "true" ) ) ;
68121 }
69122
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";
123+ public static void StepInstallCACerts ( this Job job )
124+ => job . Step ( )
125+ . Name ( "Install Sectigo CodeSiging CA certificates" )
126+ . IfRefMain ( )
127+ . Run ( """
128+ sudo apt-get update
129+ sudo apt-get install -y ca-certificates
130+ sudo cp build/SectigoPublicCodeSigningRootCrossAAA.crt /usr/local/share/ca-certificates/
131+ sudo update-ca-certificates
132+ """ ) ;
133+
134+ public static void StepToolRestore ( this Job job )
135+ => job . Step ( )
136+ . Name ( "Tool restore" )
137+ . IfRefMain ( )
138+ . Run ( "dotnet tool restore" ) ;
139+
140+ public static void StepPack ( this Job job , string componentName , string project )
141+ {
142+ var path = $ "{ componentName } /src/{ project } ";
143+ job . Step ( )
144+ . Name ( $ "Pack { project } ")
145+ . IfRefMain ( )
146+ . Run ( $ "dotnet pack -c Release { path } --no-build -o artifacts") ;
147+ }
81148
82- WriteWorkflow ( workflow , fileName ) ;
83- }
149+ public static void StepSign ( this Job job )
150+ {
151+ var flags = "--file-digest sha256 " +
152+ "--timestamp-rfc3161 http://timestamp.digicert.com " +
153+ "--azure-key-vault-url https://duendecodesigning.vault.azure.net/ " +
154+ "--azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 " +
155+ "--azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 " +
156+ "--azure-key-vault-client-secret ${{ secrets.SignClientSecret }} " +
157+ "--azure-key-vault-certificate CodeSigning" ;
158+ job . Step ( )
159+ . Name ( "Sign packages" )
160+ . IfRefMain ( )
161+ . Run ( $ """
162+ for file in artifacts/*.nupkg; do
163+ dotnet NuGetKeyVaultSignTool sign \"$file\" { flags }
164+ done
165+ """ ) ;
166+ }
84167
85- record Component ( string Name , string [ ] Projects , string [ ] Tests ) ;
168+ public static Step StepPush ( this Job job , string destination , string sourceUrl , string secretName )
169+ {
170+ var apiKey = $ "${{ secrets.{ secretName } }}";
171+ return job . Step ( )
172+ . Name ( $ "Push packages to { destination } ")
173+ . IfRefMain ( )
174+ . Run ( $ "dotnet nuget push artifacts/*.nupkg --source { sourceUrl } --api-key { apiKey } --skip-duplicate") ;
175+ }
176+
177+ public static void StepUploadArtifacts ( this Job job , string componentName )
178+ {
179+ var path = $ "{ componentName } /artifacts/*.nupkg";
180+ job . Step ( )
181+ . Name ( "Upload Artifacts" )
182+ . IfRefMain ( )
183+ . Uses ( "actions/upload-artifact@v4" )
184+ . With (
185+ ( "name" , "Upload Artifacts" ) ,
186+ ( "path" , path ) ,
187+ ( "overwrite" , "true" ) ,
188+ ( "retention-days" , "15" ) ) ;
189+ }
190+ }
0 commit comments