Skip to content

Commit f3cbb7e

Browse files
authored
Merge pull request #15 from rafek1241/feature/update-build
Feature/update build
2 parents 2f0d5c4 + 6a82cc0 commit f3cbb7e

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

build/Build.cs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using Newtonsoft.Json;
45
using Nuke.Common;
56
using Nuke.Common.CI;
@@ -12,6 +13,7 @@
1213
using Nuke.Common.Tools.DotNet;
1314
using Nuke.Common.Tools.GitVersion;
1415
using Nuke.Common.Utilities.Collections;
16+
using Nuke.GitHub;
1517
using static Nuke.Common.EnvironmentInfo;
1618
using static Nuke.Common.IO.FileSystemTasks;
1719
using static Nuke.Common.IO.PathConstruction;
@@ -42,7 +44,8 @@ class Build : NukeBuild
4244

4345
[Parameter] string NugetApiUrl = "https://api.nuget.org/v3/index.json"; //default
4446
[Parameter] string NugetApiKey;
45-
47+
[Parameter] string GitHubAuthenticationToken;
48+
4649
[Solution] readonly Solution Solution;
4750
[GitRepository] readonly GitRepository GitRepository;
4851
[GitVersion(Framework = "netcoreapp3.1")] readonly GitVersion GitVersion;
@@ -120,17 +123,9 @@ class Build : NukeBuild
120123
}
121124
);
122125

123-
Target DeployToGithubPackage => _ => _
124-
.DependsOn(Pack)
125-
.Executes(() =>
126-
{
127-
128-
}
129-
);
130-
131126
Target Deploy => _ => _
132127
.DependsOn(Pack)
133-
.OnlyWhenStatic(() => GitRepository.Branch == "master")
128+
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch())
134129
.Requires(() => NugetApiUrl)
135130
.Requires(() => NugetApiKey)
136131
.Requires(() => Configuration.Equals(Configuration.Release))
@@ -152,6 +147,33 @@ class Build : NukeBuild
152147
}
153148
);
154149

150+
Target PublishGithubRelease => _ => _
151+
.DependsOn(Deploy)
152+
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch())
153+
.Requires(() => GitHubAuthenticationToken)
154+
.Requires(() => Configuration.Equals(Configuration.Release))
155+
.Executes(async () =>
156+
{
157+
var releaseTag = GitVersion.MajorMinorPatch;
158+
var nugets = GlobFiles(NugetDestinationDirectory, "*.nupkg")
159+
.NotEmpty()
160+
.Where(x => !x.EndsWith("symbols.nupkg"))
161+
.ToArray();
162+
163+
var repo = GitHubTasks.GetGitHubRepositoryInfo(GitRepository);
164+
165+
await GitHubTasks
166+
.PublishRelease(s => s
167+
.SetArtifactPaths(nugets)
168+
.SetCommitSha(GitVersion.Sha)
169+
.SetTag(releaseTag)
170+
.SetRepositoryName(repo.repositoryName)
171+
.SetRepositoryOwner(repo.gitHubOwner)
172+
.SetToken(GitHubAuthenticationToken)
173+
);
174+
}
175+
);
176+
155177
Target ContinousIntegration => _ => _
156-
.DependsOn(Deploy);
178+
.DependsOn(PublishGithubRelease);
157179
}

build/build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="Nuke.Common" Version="5.0.2" />
1414
<PackageDownload Include="GitVersion.Tool" Version="[5.5.1]" />
15+
<PackageReference Include="Nuke.GitHub" Version="2.0.0" />
1516
</ItemGroup>
1617

1718
</Project>

0 commit comments

Comments
 (0)