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
@@ -100,8 +107,7 @@ void GenerateReleaseWorkflow(Component component)
100
107
. Name ( "Tag and Pack" )
101
108
. RunsOn ( GitHubHostedRunners . UbuntuLatest )
102
109
. Permissions ( contents : Permission . Write , packages : Permission . Write )
103
- . Defaults ( ) . Run ( "pwsh" , component . Name )
104
- . Job ;
110
+ . Defaults ( ) . Run ( "bash" , component . Name ) . Job ;
105
111
106
112
tagJob . Step ( )
107
113
. ActionsCheckout ( ) ;
@@ -110,12 +116,10 @@ void GenerateReleaseWorkflow(Component component)
110
116
111
117
tagJob . Step ( )
112
118
. 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
- """ ) ;
119
+ . Run ( $@ "git config --global user.email ""github-bot@duendesoftware.com""
120
+ git config --global user.name ""Duende Software GitHub Bot""
121
+ git tag -a { component . TagPrefix } -{ contexts . Event . Input . Version } -m ""Release v{ contexts . Event . Input . Version } ""
122
+ git push origin { component . TagPrefix } -{ contexts . Event . Input . Version } " ) ;
119
123
120
124
tagJob . StepInstallCACerts ( ) ;
121
125
@@ -129,8 +133,8 @@ git push origin it-${{ github.event.inputs.version }}
129
133
tagJob . StepPush ( "MyGet" , "https://www.myget.org/F/duende_identityserver/api/v2/package" , "MYGET" ) ;
130
134
131
135
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 }}" ) ) ;
136
+ . Env ( ( "GITHUB_TOKEN" , contexts . Secrets . GitHubToken ) ,
137
+ ( "NUGET_AUTH_TOKEN" , contexts . Secrets . GitHubToken ) ) ;
134
138
135
139
tagJob . StepUploadArtifacts ( component . Name ) ;
136
140
@@ -164,7 +168,7 @@ void WriteWorkflow(Workflow workflow, string fileName)
164
168
Console . WriteLine ( $ "Wrote workflow to { filePath } ") ;
165
169
}
166
170
167
- record Component ( string Name , string [ ] Projects , string [ ] Tests ) ;
171
+ record Component ( string Name , string [ ] Projects , string [ ] Tests , string TagPrefix ) ;
168
172
169
173
public static class StepExtensions
170
174
{
@@ -219,7 +223,6 @@ sudo update-ca-certificates
219
223
public static void StepToolRestore ( this Job job )
220
224
=> job . Step ( )
221
225
. Name ( "Tool restore" )
222
- //.IfRefMain()
223
226
. Run ( "dotnet tool restore" ) ;
224
227
225
228
public static void StepPack ( this Job job , string project )
@@ -271,3 +274,37 @@ public static void StepUploadArtifacts(this Job job, string componentName)
271
274
( "retention-days" , "15" ) ) ;
272
275
}
273
276
}
277
+
278
+ public class GitHubContexts
279
+ {
280
+ public static GitHubContexts Instance { get ; } = new ( ) ;
281
+ public virtual GitHubContext GitHub { get ; } = new ( ) ;
282
+ public virtual SecretsContext Secrets { get ; } = new ( ) ;
283
+ public virtual EventContext Event { get ; } = new ( ) ;
284
+
285
+ public abstract class Context ( string name )
286
+ {
287
+ protected string Name => name ;
288
+
289
+ protected string Expression ( string s ) => "${{ " + s + " }}" ;
290
+ }
291
+
292
+ public class GitHubContext ( ) : Context ( "github" )
293
+ {
294
+ }
295
+
296
+ public class SecretsContext ( ) : Context ( "secrets" )
297
+ {
298
+ public string GitHubToken => Expression ( $ "{ Name } .GITHUB_TOKEN") ;
299
+ }
300
+
301
+ public class EventContext ( ) : Context ( "github.event" )
302
+ {
303
+ public EventsInputContext Input { get ; } = new ( ) ;
304
+ }
305
+
306
+ public class EventsInputContext ( ) : Context ( "github.event.inputs" )
307
+ {
308
+ public string Version => Expression ( $ "{ Name } .version") ;
309
+ }
310
+ }
0 commit comments