Skip to content

Commit

Permalink
Use personal access token
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletKuro committed May 27, 2024
1 parent 5385333 commit c8e2ab3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
FetchDepth = 0,
On = new[] { GitHubActionsTrigger.Push },
PublishArtifacts = true,
InvokedTargets = new[] { nameof(Compile), nameof(Pack) },
EnableGitHubToken = true)]
InvokedTargets = new[] { nameof(Compile), nameof(Pack) })]
[GitHubActions(
"release",
GitHubActionsImage.UbuntuLatest,
FetchDepth = 0,
OnPushTags = new[] { @"\d+\.\d+\.\d+" },
PublishArtifacts = true,
InvokedTargets = new[] { nameof(Push), nameof(PushGithubNuget) },
EnableGitHubToken = true,
ImportSecrets = new[] { nameof(NuGetApiKey) })]
ImportSecrets = new[] { nameof(NuGetApiKey), nameof(PersonalAccessToken) })]
class Build : NukeBuild
{
/// Support plugins are available for:
Expand All @@ -52,6 +50,7 @@ class Build : NukeBuild
bool IsTag => GitHubActions.Instance?.Ref?.StartsWith("refs/tags/") ?? false;

[Parameter] [Secret] readonly string NuGetApiKey;
[Parameter] [Secret] readonly string PersonalAccessToken;

[Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository;
Expand Down Expand Up @@ -130,6 +129,7 @@ class Build : NukeBuild
Target PushGithubNuget => _ => _
.DependsOn(Pack)
.OnlyWhenStatic(() => IsTag && IsServerBuild)
.Requires(() => PersonalAccessToken)
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() =>
{
Expand All @@ -140,10 +140,12 @@ class Build : NukeBuild
{
x.NotNull();

Assert.True(!string.IsNullOrEmpty(PersonalAccessToken));

DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource($"https://nuget.pkg.github.com/{GitHubActions.Instance.RepositoryOwner}/index.json")
.SetApiKey(GitHubActions.Instance.Token)
.SetApiKey(PersonalAccessToken)
.EnableSkipDuplicate()
);
});
Expand Down

0 comments on commit c8e2ab3

Please sign in to comment.