Skip to content

Commit

Permalink
ci: fix lost release labels
Browse files Browse the repository at this point in the history
  • Loading branch information
moomiji committed Sep 23, 2024
1 parent 669dfe8 commit 7adf486
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tools/Builder/Build.csx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#r "nuget: NuGet.Versioning, 6.10.1"
#r "nuget: NuGet.Versioning, 6.11.0"

using System.Diagnostics;
using NuGet.Versioning;
Expand All @@ -10,23 +10,26 @@ var branch = StartProcess("git rev-parse --abbrev-ref HEAD", true);
var commit = StartProcess("git rev-parse HEAD", true);
var gitRef = Environment.GetEnvironmentVariable("GITHUB_REF") ?? string.Empty;
var isRelease = gitRef.StartsWith("refs/tags/v");
var tag = StartProcess($"git describe --tags --match v* {gitRef}", true); // tag=v1.8.9.2-3-ge878f0b
var tags = new Queue<string>(tag.Split('-'));
var version = NuGetVersion.Parse(tags.Dequeue().TrimStart('v'));

if (version.ReleaseLabels.Count() > 1)
var tag = StartProcess($"git describe --tags --match v* {gitRef}", true);
var tags = new Queue<string>(tag.TrimStart('v').Split('-'));
var version = tags.Count switch
{
throw new InvalidOperationException("The release labels count > 1.");
}
if (!isRelease)
1 or 3 => NuGetVersion.Parse(
tags.Dequeue()), // v2.0.1 v2.0.1-3-ge878f0b
2 or 4 => NuGetVersion.Parse(
tags.Dequeue() + '-' + tags.Dequeue()), // v2.0.1-rc.1 v2.0.1-rc.1-3-ge878f0b
_ => throw new InvalidOperationException("The release labels count > 4.")
};

if (tags.Count != 0) // 非最新版本号
{
var nightlyVersion = new NuGetVersion(version.Major, version.Minor, version.Patch,
version.IsPrerelease
? version.Revision // 预发布版本号已经提升了一位
: version.Revision + 1,
version.IsPrerelease
? version.ReleaseLabels.Concat(tags) // alpha1 -> alpha1.1
: tags.Prepend("alpha"), // -> alpha.1
: tags.Prepend("alpha"), // -> alpha.1
string.Empty
);
version = nightlyVersion;
Expand Down

0 comments on commit 7adf486

Please sign in to comment.