2
2
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3
3
4
4
using Logicality . GitHub . Actions . Workflow ;
5
+ using static GitHubContexts ;
5
6
7
+
8
+ var contexts = Instance ;
6
9
Component [ ] components = [
7
10
new ( "ignore-this" ,
8
11
[ "IgnoreThis" ] ,
9
- [ "IgnoreThis.Tests" ] ) ,
12
+ [ "IgnoreThis.Tests" ] ,
13
+ "it" ) ,
10
14
11
15
new ( "access-token-management" ,
12
16
[ "AccessTokenManagement" , "AccessTokenManagement.OpenIdConnect" ] ,
13
- [ "AccessTokenManagement.Tests" ] ) ,
17
+ [ "AccessTokenManagement.Tests" ] ,
18
+ "atm" ) ,
14
19
15
20
new ( "identity-model" ,
16
21
[ "IdentityModel" ] ,
17
- [ "IdentityModel.Tests" ] ) ,
22
+ [ "IdentityModel.Tests" ] ,
23
+ "im" ) ,
18
24
19
25
new ( "identity-model-oidc-client" ,
20
26
[ "IdentityModel.OidcClient" , "IdentityModel.OidcClient.Extensions" ] ,
21
- [ "IdentityModel.OidcClient.Tests" ] )
27
+ [ "IdentityModel.OidcClient.Tests" ] ,
28
+ "imoc" )
22
29
] ;
23
30
24
31
foreach ( var component in components )
@@ -76,8 +83,8 @@ void GenerateCiWorkflow(Component component)
76
83
job . StepPush ( "MyGet" , "https://www.myget.org/F/duende_identityserver/api/v2/package" , "MYGET" ) ;
77
84
78
85
job . StepPush ( "GitHub" , "https://nuget.pkg.github.com/DuendeSoftware/index.json" , "GITHUB_TOKEN" )
79
- . Env ( ( "GITHUB_TOKEN" , "${{ secrets.GITHUB_TOKEN }}" ) ,
80
- ( "NUGET_AUTH_TOKEN" , "${{ secrets.GITHUB_TOKEN }}" ) ) ;
86
+ . Env ( ( "GITHUB_TOKEN" , contexts . Secrets . GitHubToken ) ,
87
+ ( "NUGET_AUTH_TOKEN" , contexts . Secrets . GitHubToken ) ) ;
81
88
82
89
job . StepUploadArtifacts ( component . Name ) ;
83
90
@@ -99,9 +106,7 @@ void GenerateReleaseWorkflow(Component component)
99
106
. Job ( "tag" )
100
107
. Name ( "Tag and Pack" )
101
108
. RunsOn ( GitHubHostedRunners . UbuntuLatest )
102
- . Permissions ( contents : Permission . Write , packages : Permission . Write )
103
- . Defaults ( ) . Run ( "pwsh" , component . Name )
104
- . Job ;
109
+ . Permissions ( contents : Permission . Write , packages : Permission . Write ) ;
105
110
106
111
tagJob . Step ( )
107
112
. ActionsCheckout ( ) ;
@@ -110,12 +115,10 @@ void GenerateReleaseWorkflow(Component component)
110
115
111
116
tagJob . Step ( )
112
117
. Name ( "Git tag" )
113
- . Run ( """
114
- git config --global user.email "github-bot@duendesoftware.com"
115
- git config --global user.name "Duende Software GitHub Bot"
116
- git tag -a it-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
117
- git push origin it-${{ github.event.inputs.version }}
118
- """ ) ;
118
+ . Run ( $@ "git config --global user.email ""github-bot@duendesoftware.com""
119
+ git config --global user.name ""Duende Software GitHub Bot""
120
+ git tag -a { component . TagPrefix } -{ contexts . Event . Input . Version } -m ""Release v{ contexts . Event . Input . Version } ""
121
+ git push origin { component . TagPrefix } -{ contexts . Event . Input . Version } " ) ;
119
122
120
123
tagJob . StepInstallCACerts ( ) ;
121
124
@@ -129,8 +132,8 @@ git push origin it-${{ github.event.inputs.version }}
129
132
tagJob . StepPush ( "MyGet" , "https://www.myget.org/F/duende_identityserver/api/v2/package" , "MYGET" ) ;
130
133
131
134
tagJob . StepPush ( "GitHub" , "https://nuget.pkg.github.com/DuendeSoftware/index.json" , "GITHUB_TOKEN" )
132
- . Env ( ( "GITHUB_TOKEN" , "${{ secrets.GITHUB_TOKEN }}" ) ,
133
- ( "NUGET_AUTH_TOKEN" , "${{ secrets.GITHUB_TOKEN }}" ) ) ;
135
+ . Env ( ( "GITHUB_TOKEN" , contexts . Secrets . GitHubToken ) ,
136
+ ( "NUGET_AUTH_TOKEN" , contexts . Secrets . GitHubToken ) ) ;
134
137
135
138
tagJob . StepUploadArtifacts ( component . Name ) ;
136
139
@@ -164,7 +167,7 @@ void WriteWorkflow(Workflow workflow, string fileName)
164
167
Console . WriteLine ( $ "Wrote workflow to { filePath } ") ;
165
168
}
166
169
167
- record Component ( string Name , string [ ] Projects , string [ ] Tests ) ;
170
+ record Component ( string Name , string [ ] Projects , string [ ] Tests , string TagPrefix ) ;
168
171
169
172
public static class StepExtensions
170
173
{
@@ -219,7 +222,6 @@ sudo update-ca-certificates
219
222
public static void StepToolRestore ( this Job job )
220
223
=> job . Step ( )
221
224
. Name ( "Tool restore" )
222
- //.IfRefMain()
223
225
. Run ( "dotnet tool restore" ) ;
224
226
225
227
public static void StepPack ( this Job job , string project )
@@ -271,3 +273,37 @@ public static void StepUploadArtifacts(this Job job, string componentName)
271
273
( "retention-days" , "15" ) ) ;
272
274
}
273
275
}
276
+
277
+ public class GitHubContexts
278
+ {
279
+ public static GitHubContexts Instance { get ; } = new ( ) ;
280
+ public virtual GitHubContext GitHub { get ; } = new ( ) ;
281
+ public virtual SecretsContext Secrets { get ; } = new ( ) ;
282
+ public virtual EventContext Event { get ; } = new ( ) ;
283
+
284
+ public abstract class Context ( string name )
285
+ {
286
+ protected string Name => name ;
287
+
288
+ protected string Expression ( string s ) => "${{ " + s + " }}" ;
289
+ }
290
+
291
+ public class GitHubContext ( ) : Context ( "github" )
292
+ {
293
+ }
294
+
295
+ public class SecretsContext ( ) : Context ( "secrets" )
296
+ {
297
+ public string GitHubToken => Expression ( $ "{ Name } .GITHUB_TOKEN") ;
298
+ }
299
+
300
+ public class EventContext ( ) : Context ( "github.event" )
301
+ {
302
+ public EventsInputContext Input { get ; } = new ( ) ;
303
+ }
304
+
305
+ public class EventsInputContext ( ) : Context ( "github.event.inputs" )
306
+ {
307
+ public string Version => Expression ( $ "{ Name } .version") ;
308
+ }
309
+ }
0 commit comments