Skip to content

Commit

Permalink
Workaround for GitVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
kthompson committed Nov 18, 2021
1 parent f88a0f5 commit b86b542
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
6 changes: 6 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
assembly-versioning-scheme: MajorMinorPatch
mode: ContinuousDelivery
branches: {}
ignore:
sha: []
merge-message-formats: {}
34 changes: 22 additions & 12 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
Expand Down Expand Up @@ -53,7 +54,7 @@ class Build : NukeBuild

[Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository;
[GitVersion] readonly GitVersion GitVersion;
[GitVersion(DisableOnUnix = true)] [CanBeNull] readonly GitVersion GitVersion;

AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "test";
Expand All @@ -64,7 +65,7 @@ class Build : NukeBuild
AbsolutePath CoverageReportDirectory => ArtifactsDirectory / "coverage-report";
AbsolutePath CoverageReportArchive => ArtifactsDirectory / "coverage-report.zip";

const string MasterBranch = "master";
const string MainBranch = "main";

Target Clean => _ => _
.Before(Restore)
Expand All @@ -86,12 +87,17 @@ class Build : NukeBuild
.DependsOn(Restore)
.Executes(() =>
{
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)

DotNetBuildSettings WithGitVersion(DotNetBuildSettings settings) => GitVersion == null
? settings
: settings
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion);

DotNetBuild(s => WithGitVersion(s
.SetProjectFile(Solution)
.SetConfiguration(Configuration))
.EnableNoRestore());
});

Expand Down Expand Up @@ -161,13 +167,17 @@ class Build : NukeBuild
.Produces(PackageDirectory / "*.nupkg")
.Executes(() =>
{
DotNetPack(_ => _
DotNetPackSettings WithGitVersion(DotNetPackSettings settings) => GitVersion == null
? settings
: settings
.SetVersion(GitVersion.NuGetVersionV2);

DotNetPack(_ => WithGitVersion(_
.SetProject(Solution)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetConfiguration(Configuration)
.SetOutputDirectory(PackageDirectory)
.SetVersion(GitVersion.NuGetVersionV2)
.SetPackageReleaseNotes(GetNuGetReleaseNotes(ChangelogFile, GitRepository)));
.SetPackageReleaseNotes(GetNuGetReleaseNotes(ChangelogFile, GitRepository))));
});


Expand All @@ -180,7 +190,7 @@ class Build : NukeBuild
.Requires(() => ApiKey)
.Requires(() => GitHasCleanWorkingCopy())
.Requires(() => Configuration.Equals(Configuration.Release))
.Requires(() => GitRepository.Branch.EqualsOrdinalIgnoreCase(MasterBranch))
.Requires(() => GitRepository.Branch.EqualsOrdinalIgnoreCase(MainBranch))
.Executes(() =>
{
var packages = PackageDirectory.GlobFiles("*.nupkg");
Expand Down
2 changes: 1 addition & 1 deletion src/Glob/Glob.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Description>A C# Glob library for .NET and .NET Core.</Description>
<PackageReleaseNotes>Fix issue preventing multiple enumeration</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/kthompson/glob/</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/kthompson/glob/master/LICENSE</PackageLicenseUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/kthompson/glob/main/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/kthompson/glob</RepositoryUrl>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
Expand Down

0 comments on commit b86b542

Please sign in to comment.