Fix tag build

This commit is contained in:
Peter 2022-01-27 11:03:21 +01:00
parent 752bd9d8f5
commit c564229fb2
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
3 changed files with 31 additions and 27 deletions

View file

@ -56,7 +56,6 @@ nuget-publish:
only:
refs:
- tags
- main
script:
- dotnet tool restore
- dotnet nuke NuGetPush
- dotnet nuke NuGetPush --nuget-username "${NUGET_USERNAME}" --nuget-password "${NUGET_PASSWORD}"

View file

@ -1,5 +1,6 @@
using System;
using JetBrains.Annotations;
using NuGet.Versioning;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.GitLab;
@ -25,18 +26,17 @@ class Build : NukeBuild
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Parameter("Username to use for publishing NuGet packages", Name = "nuget-username")]
string NuGetUsername { get; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty;
string NuGetUsername { get; set; } = Environment.GetEnvironmentVariable("NUGET_USERNAME") ?? string.Empty;
[Parameter("Password to use for publishing NuGet packages", Name = "nuget-password")]
string NuGetPassword { get; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty;
string NuGetPassword { get; set; } = Environment.GetEnvironmentVariable("NUGET_PASSWORD") ?? string.Empty;
[Solution] readonly Solution Solution;
[GitRepository] readonly GitRepository GitRepository;
[GitVersion(NoFetch = true)] readonly GitVersion GitVersion;
[Solution] readonly Solution? Solution;
[GitRepository] readonly GitRepository? GitRepository;
[GitVersion(NoFetch = true, Framework = "net6.0")] readonly GitVersion? GitVersion;
[CanBeNull]
GitLab CI => GitLab.Instance;
GitLab? CI => GitLab.Instance;
AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "tests";
@ -62,12 +62,17 @@ class Build : NukeBuild
.DependsOn(Restore)
.Executes(() =>
{
var assemblyVersion = GitVersion?.AssemblySemVer ??
SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString();
var informationalVersion = GitVersion?.InformationalVersion ??
SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToFullString();
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetAssemblyVersion(assemblyVersion)
.SetFileVersion(assemblyVersion)
.SetInformationalVersion(informationalVersion)
.EnableNoRestore());
});
@ -84,28 +89,16 @@ class Build : NukeBuild
.EnableNoBuild()
.EnableProcessLogOutput()));
Target AddNugetSource => _ => _
.OnlyWhenStatic(() => GitRepository.IsOnMainBranch())
.OnlyWhenStatic(() => CI != null)
.OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword))
.ProceedAfterFailure()
.Executes(() => DotNetNuGetAddSource(s => s
.SetName(NuGetSourceName)
.SetSource($"https://gitlab.com/api/v4/projects/{CI.ProjectId}/packages/nuget/index.json")
.SetUsername(NuGetUsername)
.SetPassword(NuGetPassword)
.EnableStorePasswordInClearText()));
Target Pack => _ => _
.DependsOn(Compile)
.OnlyWhenStatic(() => GitRepository.IsOnMainBranch())
.OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag))
.Executes(() => SourceDirectory
.GlobFiles("**/*.csproj")
.ForEach(csproj => DotNetPack(s => s
.SetProject(csproj)
.SetConfiguration(Configuration)
.SetOutputDirectory(ArtifactsDirectory)
.SetVersion(GitVersion.FullSemVer)
.SetVersion(GitVersion?.FullSemVer ?? SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString())
.EnableIncludeSource()
.EnableIncludeSymbols()
.EnableNoRestore()
@ -113,9 +106,20 @@ class Build : NukeBuild
.EnableProcessLogOutput()
)));
Target AddNugetSource => _ => _
.OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag))
.OnlyWhenStatic(() => !string.IsNullOrEmpty(NuGetUsername) && !string.IsNullOrEmpty(NuGetPassword))
.ProceedAfterFailure()
.Executes(() => DotNetNuGetAddSource(s => s
.SetName(NuGetSourceName)
.SetSource($"https://gitlab.com/api/v4/projects/{CI?.ProjectId}/packages/nuget/index.json")
.SetUsername(NuGetUsername)
.SetPassword(NuGetPassword)
.EnableStorePasswordInClearText()));
Target NuGetPush => _ => _
.DependsOn(Pack, AddNugetSource)
.OnlyWhenStatic(() => GitRepository.IsOnMainBranch())
.OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag))
.Executes(() => ArtifactsDirectory
.GlobFiles("**/*.nupkg")
.ForEach(nupkg => DotNetNuGetPush(s => s

View file

@ -9,6 +9,7 @@
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>