88
99[ GitHubActions ( "deploy-to-nuget" ,
1010 GitHubActionsImage . UbuntuLatest ,
11- OnPushTags = new [ ] { "v*" } , // Runs when pushing a tag like "v1.0.0"
11+ OnPushTags = new [ ] { "v*" } ,
1212 InvokedTargets = new [ ] { nameof ( Pack ) , nameof ( Publish ) } ,
1313 ImportSecrets = new [ ] { "NUGET_API_KEY" } ) ]
1414class Build : NukeBuild
1515{
1616 public static int Main ( ) => Execute < Build > ( x => x . Pack ) ;
1717
1818 [ Parameter ] readonly string Configuration = "Release" ;
19+ [ Parameter ] readonly string NugetApiKey = Environment . GetEnvironmentVariable ( "NUGET_API_KEY" ) ;
1920
2021 AbsolutePath SourceDirectory => RootDirectory / "src" ;
2122 AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts" ;
@@ -60,12 +61,9 @@ class Build : NukeBuild
6061 }
6162 } ) ;
6263
63- bool IsRunningOnGitHubActions => Environment . GetEnvironmentVariable ( "GITHUB_ACTIONS" ) == "true" ;
64-
6564 Target Publish => _ => _
6665 . DependsOn ( Pack )
67- . OnlyWhenDynamic ( ( ) => IsRunningOnGitHubActions )
68- . Requires ( ( ) => Environment . GetEnvironmentVariable ( "NUGET_API_KEY" ) )
66+ . Requires ( ( ) => NugetApiKey )
6967 . Executes ( ( ) =>
7068 {
7169 SourceDirectory . GlobFiles ( ArtifactsDirectory , "*.nupkg" )
@@ -74,7 +72,7 @@ class Build : NukeBuild
7472 DotNetNuGetPush ( s => s
7573 . SetTargetPath ( package )
7674 . SetSource ( "https://api.nuget.org/v3/index.json" )
77- . SetApiKey ( Environment . GetEnvironmentVariable ( "NUGET_API_KEY" ) ) ) ;
75+ . SetApiKey ( NugetApiKey ) ) ;
7876 } ) ;
7977 } ) ;
8078}
0 commit comments