Skip to content

Commit 732e2b1

Browse files
committed
Add NuGet API key parameter to build configuration for GitHub Actions
1 parent 97edcf3 commit 732e2b1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

.nuke/build.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
"properties": {
105105
"Configuration": {
106106
"type": "string"
107+
},
108+
"NugetApiKey": {
109+
"type": "string"
107110
}
108111
}
109112
},

build/Build.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
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" })]
1414
class 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

Comments
 (0)