Skip to content

Commit

Permalink
CI/DI
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletKuro committed May 27, 2024
1 parent 9227080 commit 00792bc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
run: ./build.cmd Push
env:
NuGetApiKey: ${{ secrets.NUGET_API_KEY }}
GithubToken: ${{ secrets.GITHUB_TOKEN }}
- name: 'Publish: packages'
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 6 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"GithubToken": {
"type": "string",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
Expand Down Expand Up @@ -83,6 +87,7 @@
"Compile",
"Pack",
"Push",
"PushGithubNuget",
"Restore"
]
}
Expand All @@ -101,6 +106,7 @@
"Compile",
"Pack",
"Push",
"PushGithubNuget",
"Restore"
]
}
Expand Down
27 changes: 26 additions & 1 deletion build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
OnPushTags = new[] { @"\d+\.\d+\.\d+" },
PublishArtifacts = true,
InvokedTargets = new[] { nameof(Push) },
ImportSecrets = new[] { nameof(NuGetApiKey) })]
ImportSecrets = new[] { nameof(NuGetApiKey), nameof(GithubToken) })]
class Build : NukeBuild
{
/// Support plugins are available for:
Expand All @@ -47,6 +47,7 @@ class Build : NukeBuild

[Parameter] string NugetApiUrl = "https://api.nuget.org/v3/index.json"; //default
[Parameter][Secret] readonly string NuGetApiKey;
[Parameter][Secret] readonly string GithubToken;

bool IsTag => GitHubActions.Instance?.Ref?.StartsWith("refs/tags/") ?? false;

Expand Down Expand Up @@ -121,6 +122,30 @@ class Build : NukeBuild
});
});

Target PushGithubNuget => _ => _
.DependsOn(Pack)
.OnlyWhenStatic(() => IsTag && IsServerBuild)
.Requires(() => GithubToken)
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() =>
{
Log.Information("Running push to packages directory.");

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

PackagesDirectory.GlobFiles("*.nupkg")
.ForEach(x =>
{
x.NotNull();
DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource($"https://nuget.pkg.github.com/{GitHubActions.Instance.RepositoryOwner}/index.json")
.SetApiKey(GithubToken)
.EnableSkipDuplicate()
);
});
});

Configure<DotNetPackSettings> PackSettings => _ => _
.SetProject(Solution)
.SetConfiguration(Configuration)
Expand Down

0 comments on commit 00792bc

Please sign in to comment.