1- // Copyright (c) Duende Software. All rights reserved.
1+ // Copyright (c) Duende Software. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33
44using Logicality . GitHub . Actions . Workflow ;
@@ -110,8 +110,9 @@ void GenerateReleaseWorkflow(Component component)
110110 workflow . On
111111 . WorkflowDispatch ( )
112112 . Inputs (
113- new StringInput ( "version" , "Version in format X.Y.Z or X.Y.Z-preview." , true , "0.0.0" )
114- , new StringInput ( "target-branch" , "(Optional) the name of the branch to release from" , false , "main" ) ) ;
113+ new StringInput ( "version" , "Version in format X.Y.Z or X.Y.Z-preview." , true , "0.0.0" ) ,
114+ new StringInput ( "branch" , "(Optional) the name of the branch to release from" , false , "main" ) ,
115+ new BooleanInput ( "remove-tag-if-exists" , "If set, will remove the existing tag. Use this if you have issues with the previous release action" , false , false ) ) ;
115116
116117 workflow . EnvDefaults ( ) ;
117118
@@ -132,11 +133,26 @@ void GenerateReleaseWorkflow(Component component)
132133
133134 tagJob . StepSetupDotNet ( ) ;
134135
136+
137+ tagJob . Step ( )
138+ . Name ( "Git Config" )
139+ . Run ( @"git config --global user.email ""github-bot@duendesoftware.com""
140+ git config --global user.name ""Duende Software GitHub Bot""" ) ;
141+
142+ tagJob . Step ( )
143+ . Name ( "Remove previous git tag" )
144+ . If ( "github.event.inputs['remove-tag-if-exists'] == 'true'" )
145+ . Run ( $@ "if git rev-parse { component . TagPrefix } -{ contexts . Event . Input . Version } >/dev/null 2>&1; then
146+ git tag -d { component . TagPrefix } -{ contexts . Event . Input . Version }
147+ git push --delete origin { component . TagPrefix } -{ contexts . Event . Input . Version }
148+ else
149+ echo 'Tag { component . TagPrefix } -{ contexts . Event . Input . Version } does not exist.'
150+ fi" ) ;
151+
152+
135153 tagJob . Step ( )
136154 . Name ( "Git tag" )
137- . Run ( $@ "git config --global user.email ""github-bot@duendesoftware.com""
138- git config --global user.name ""Duende Software GitHub Bot""
139- git tag -a { component . TagPrefix } -{ contexts . Event . Input . Version } -m ""Release v{ contexts . Event . Input . Version } ""
155+ . Run ( $@ "git tag -a { component . TagPrefix } -{ contexts . Event . Input . Version } -m ""Release v{ contexts . Event . Input . Version } ""
140156git push origin { component . TagPrefix } -{ contexts . Event . Input . Version } " ) ;
141157
142158 foreach ( var project in component . Projects )
@@ -146,20 +162,20 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
146162
147163 tagJob . StepToolRestore ( ) ;
148164
149- tagJob . StepSign ( true ) ;
150-
151- tagJob . StepPush ( "MyGet" , "https://www.myget.org/F/duende_identityserver/api/v2/package" , "MYGET" ) ;
165+ tagJob . StepSign ( always : true ) ;
152166
153- tagJob . StepPush ( "GitHub" , "https://nuget.pkg.github.com/DuendeSoftware/index.json" , "GITHUB_TOKEN" )
167+ tagJob . StepPush ( "GitHub" , "https://nuget.pkg.github.com/DuendeSoftware/index.json" , "GITHUB_TOKEN" , pushAlways : true )
154168 . Env ( ( "GITHUB_TOKEN" , contexts . Secrets . GitHubToken ) ,
155169 ( "NUGET_AUTH_TOKEN" , contexts . Secrets . GitHubToken ) ) ;
156170
157- tagJob . StepUploadArtifacts ( component . Name ) ;
171+ tagJob . StepUploadArtifacts ( component . Name , uploadAlways : true ) ;
158172
159173 var publishJob = workflow . Job ( "publish" )
160174 . Name ( "Publish to nuget.org" )
161175 . RunsOn ( GitHubHostedRunners . UbuntuLatest )
162- . Needs ( "tag" ) ;
176+ . Needs ( "tag" )
177+ . Environment ( "nuget.org" , "" ) ;
178+ ;
163179
164180 publishJob . Step ( )
165181 . Uses ( "actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16" ) // 4.1.8
@@ -172,7 +188,9 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c
172188 . Shell ( "bash" )
173189 . Run ( "tree" ) ;
174190
175- publishJob . StepPush ( "nuget.org" , "https://api.nuget.org/v3/index.json" , "NUGET_ORG_API_KEY" ) ;
191+ tagJob . StepPush ( "MyGet" , "https://www.myget.org/F/duende_identityserver/api/v2/package" , "MYGET" , pushAlways : true ) ;
192+
193+ publishJob . StepPush ( "nuget.org" , "https://api.nuget.org/v3/index.json" , "NUGET_ORG_API_KEY" , pushAlways : true ) ;
176194
177195 var fileName = $ "{ component . Name } -release";
178196 WriteWorkflow ( workflow , fileName ) ;
@@ -320,22 +338,31 @@ dotnet NuGetKeyVaultSignTool sign "$file" {flags}
320338 public static Step IfGithubEventIsPush ( this Step step )
321339 => step . If ( "github.event_name == 'push'" ) ;
322340
323- public static Step StepPush ( this Job job , string destination , string sourceUrl , string secretName )
341+ public static Step StepPush ( this Job job , string destination , string sourceUrl , string secretName , bool pushAlways = false )
324342 {
325343 var apiKey = $ "${{{{ secrets.{ secretName } }}}}";
326- return job . Step ( )
327- . Name ( $ "Push packages to { destination } ")
328- . IfRefMain ( )
329- . Run ( $ "dotnet nuget push artifacts/*.nupkg --source { sourceUrl } --api-key { apiKey } --skip-duplicate") ;
344+ var step = job . Step ( )
345+ . Name ( $ "Push packages to { destination } ") ;
346+
347+ if ( ! pushAlways )
348+ {
349+ step . IfRefMain ( ) ;
350+ }
351+ return step . Run ( $ "dotnet nuget push artifacts/*.nupkg --source { sourceUrl } --api-key { apiKey } --skip-duplicate") ;
330352 }
331353
332- public static void StepUploadArtifacts ( this Job job , string componentName )
354+ public static void StepUploadArtifacts ( this Job job , string componentName , bool uploadAlways = false )
333355 {
334356 var path = $ "{ componentName } /artifacts/*.nupkg";
335- job . Step ( )
336- . Name ( "Upload Artifacts" )
337- . IfGithubEventIsPush ( )
338- . Uses ( "actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882" ) // 4.4.3
357+ var step = job . Step ( )
358+ . Name ( "Upload Artifacts" ) ;
359+
360+ if ( ! uploadAlways )
361+ {
362+ step . IfGithubEventIsPush ( ) ;
363+ }
364+
365+ step . Uses ( "actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882" ) // 4.4.3
339366 . With (
340367 ( "name" , "artifacts" ) ,
341368 ( "path" , path ) ,
0 commit comments