Skip to content

Commit e13a6c9

Browse files
committed
Implement deployment
1 parent e034d26 commit e13a6c9

File tree

5 files changed

+126
-12
lines changed

5 files changed

+126
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ------------------------------------------------------------------------------
2+
# <auto-generated>
3+
#
4+
# This code was generated.
5+
#
6+
# - To turn off auto-generation set:
7+
#
8+
# [GitHubActions (AutoGenerate = false)]
9+
#
10+
# - To trigger manual generation invoke:
11+
#
12+
# nuke --generate-configuration GitHubActions_deploy --host GitHubActions
13+
#
14+
# </auto-generated>
15+
# ------------------------------------------------------------------------------
16+
17+
name: deploy
18+
19+
on:
20+
push:
21+
tags:
22+
- 'v*'
23+
24+
permissions:
25+
packages: write
26+
contents: read
27+
28+
jobs:
29+
windows-latest:
30+
name: windows-latest
31+
runs-on: windows-latest
32+
steps:
33+
- uses: actions/checkout@v6
34+
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
35+
uses: actions/cache@v4
36+
with:
37+
path: |
38+
.nuke/temp
39+
~/.nuget/packages
40+
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
41+
- name: 'Run: Publish'
42+
run: ./build.cmd Publish
43+
- name: 'Publish: packages'
44+
uses: actions/upload-artifact@v5
45+
with:
46+
name: packages
47+
path: src/nuget/packages

.nuke/build.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"enum": [
2727
"Clean",
2828
"Pack",
29+
"Publish",
2930
"Test"
3031
]
3132
},
@@ -108,9 +109,17 @@
108109
"Release"
109110
]
110111
},
112+
"GithubNugetPAT": {
113+
"type": "string",
114+
"description": "Private Access Token for publishing Nuget packages to GitHub",
115+
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
116+
},
111117
"Solution": {
112118
"type": "string",
113119
"description": "Path to a solution file that is automatically loaded"
120+
},
121+
"Version": {
122+
"type": "string"
114123
}
115124
}
116125
},

.nuke/parameters.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"$schema": "build.schema.json",
3-
"Solution": "NukeBuild.slnx"
3+
"Solution": "NukeBuild.slnx",
4+
"GithubNugetPAT": "v1:wX7OoXgV5s5grQHFvkoTHZwOI+GH+LP/9GWoDbUL/YigBVQ0V5qFPG2mJvjZrF47"
45
}

src/build/Build.cs

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
using System.CodeDom;
2+
using System.Collections.Generic;
3+
using System.Linq;
14
using Nuke.Common.Git;
5+
using Nuke.Common.IO;
6+
using Nuke.Common.Tools.GitHub;
7+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
8+
using static Nuke.Common.Tools.NuGet.NuGetTasks;
29

3-
[GitHubActions("pack", GitHubActionsImage.WindowsLatest,
10+
[
11+
ShutdownDotNetAfterServerBuild,
12+
GitHubActions("pack", GitHubActionsImage.WindowsLatest,
413
InvokedTargets = [nameof(Pack)],
514
AutoGenerate = true,
615
PublishArtifacts = true,
716
On =
817
[
918
GitHubActionsTrigger.WorkflowDispatch,
1019
GitHubActionsTrigger.PullRequest
11-
])]
20+
]),
21+
GitHubActions("deploy", GitHubActionsImage.WindowsLatest,
22+
InvokedTargets = [nameof(Publish)],
23+
AutoGenerate = true,
24+
PublishArtifacts = true,
25+
ReadPermissions = [GitHubActionsPermissions.Contents],
26+
WritePermissions = [GitHubActionsPermissions.Packages],
27+
OnPushTags = ["v*"])
28+
]
1229
class Build : NukeBuild
1330
{
1431
[GitRepository]
@@ -25,30 +42,69 @@ class Build : NukeBuild
2542
Target Clean => _ => _
2643
.Executes(() =>
2744
{
28-
PackagesDirectory.DeleteDirectory();
45+
PackagesDirectory.CreateOrCleanDirectory();
2946
});
3047

48+
[Parameter]
49+
string Version;
50+
3151
Target Pack => _ => _
3252
.DependsOn(Test)
3353
.Produces(PackagesDirectory / "*.nupkg")
3454
.Executes(() =>
3555
{
36-
37-
NuGetTasks.NuGetPack(options => options
56+
var version = Version
57+
?? GitRepository.Tags?.FirstOrDefault(t => t != null && t.StartsWith('v'))?.TrimStart('v');
58+
59+
if (version == null)
60+
Assert.Fail("Could not find a version specified for this release");
61+
62+
return NuGetPack(options => options
63+
.SetVersion(version)
3864
.SetProcessWorkingDirectory(NugetDirectory)
3965
.SetOutputDirectory(PackagesDirectory));
4066
});
4167

4268
Target Test => _ => _
4369
.OnlyWhenStatic(()=> IsWin)
70+
.Executes(() =>
71+
DotNetPublish(options => options
72+
.SetProject(Solution.Tests.TestTarget)
73+
.SetRuntime(DotNetRuntimeIdentifier.win_x64)
74+
.SetConfiguration(Configuration)));
75+
76+
[Secret, Parameter("Private Access Token for publishing Nuget packages to GitHub")]
77+
string GithubNugetPAT;
78+
79+
Target Publish => _ => _
80+
.OnlyWhenStatic(() => GitRepository.IsOnMainBranch())
81+
.DependsOn(Pack)
4482
.Executes(() =>
4583
{
46-
DotNetTasks.DotNetPublish(options => options
47-
.SetProject(Solution.Tests.TestTarget)
48-
.SetRuntime(DotNetRuntimeIdentifier.win_x64)
49-
.SetConfiguration(Configuration));
50-
});
84+
if (string.IsNullOrWhiteSpace(GithubNugetPAT))
85+
GithubNugetPAT = GitHubActions.Instance.Token;
86+
var source = $"https://nuget.pkg.github.com/{GitRepository.GetGitHubOwner()}/index.json";
87+
88+
var preExisting = true;
89+
if (!NuGetSourcesList().Any(x => x.Text.Contains("github")))
90+
{
91+
preExisting = false;
92+
NuGetSourcesAdd(options => options
93+
.SetName("github")
94+
.SetUserName(GitRepository.GetGitHubOwner())
95+
.SetPassword(GithubNugetPAT)
96+
.SetSource(source));
97+
}
5198

99+
NuGetPush(options => options
100+
.SetApiKey(GithubNugetPAT)
101+
.SetSource(source)
102+
.SetTargetPath((PackagesDirectory / "*.nupkg").GlobFiles().First()));
103+
104+
if (!preExisting)
105+
NuGetSourcesRemove(options => options
106+
.SetName("github"));
107+
});
52108

53109

54110
// Paths

src/nuget/Dawn.AOT.DLLMain.nuspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<metadata>
44
<id>Dawn.AOT.DLLMain</id>
55
<title>Dawn AOT DLLMain</title>
6-
<version>1.0.0</version>
6+
<!-- Nuke will replace this -->
7+
<version>0.0.0</version>
78
<description>Removes the limitations placed on DllMain from .NET 10+</description>
89
<authors>arion</authors>
910
<owners>arion</owners>

0 commit comments

Comments
 (0)