Skip to content

Commit 572e1a2

Browse files
committed
Added version bump script
1 parent 26e5a75 commit 572e1a2

6 files changed

Lines changed: 113 additions & 3 deletions

File tree

.idea/.idea.Forged/.idea/jsonCatalog.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Forged/.idea/jsonSchemas.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.scripts/Bump.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#:package Spectre.Console@0.57.0
2+
#:package NuGet.Versioning@7.6.0
3+
#:property PublishAot=false
4+
5+
using System.Text.RegularExpressions;
6+
using NuGet.Versioning;
7+
using Spectre.Console;
8+
9+
var path = args[0];
10+
11+
var file = File.ReadAllText(path);
12+
var versionStr = Regexes.VersionRegex.Match(file).Groups["version"].Value;
13+
14+
if (!SemanticVersion.TryParse(versionStr, out var version))
15+
{
16+
AnsiConsole.MarkupLine($"[red]Failed to parse version: {versionStr}[/]");
17+
return 1;
18+
}
19+
20+
AnsiConsole.MarkupLine($"[green]Current version: [bold]{versionStr}[/][/]");
21+
22+
var part = AnsiConsole.Prompt(
23+
new SelectionPrompt<string>()
24+
.Title("Select the part to bump:")
25+
.AddChoices("Major", "Minor", "Patch", "Build"));
26+
27+
var isBuild = part == "Build";
28+
29+
var buildKind = "";
30+
if (isBuild)
31+
{
32+
buildKind = AnsiConsole.Prompt(
33+
new SelectionPrompt<string>()
34+
.Title("Select the build kind:")
35+
.AddChoices("Alpha", "Beta", "RC", "Preview", "Other"));
36+
37+
if (buildKind == "Other")
38+
{
39+
buildKind = AnsiConsole.Ask<string>("What kind of build is it?");
40+
}
41+
}
42+
43+
string? tag = null;
44+
if (!string.IsNullOrEmpty(buildKind))
45+
{
46+
tag = buildKind;
47+
}
48+
else if (!string.IsNullOrEmpty(version.Release))
49+
{
50+
tag = AnsiConsole.Confirm("Clear the release tag?")
51+
? null
52+
: version.Release;
53+
}
54+
55+
var newVersion = new SemanticVersion(
56+
version.Major + (part == "Major" ? 1 : 0),
57+
version.Minor + (part == "Minor" ? 1 : 0),
58+
version.Patch + (part == "Patch" ? 1 : 0),
59+
tag,
60+
null
61+
);
62+
63+
AnsiConsole.MarkupLine($"[green]Bumping to: [bold]{newVersion}[/][/]");
64+
65+
if (AnsiConsole.Confirm("Proceed?"))
66+
{
67+
var newText = Regexes.VersionRegex.Replace(file, $$"""${open}{{newVersion}}${close}""");
68+
File.WriteAllText(path, newText);
69+
}
70+
71+
return 0;
72+
73+
internal static partial class Regexes
74+
{
75+
[GeneratedRegex(@"^(?<open>\s+<PackageVersion>)(?<version>.+)(?<close></PackageVersion>\s?)$", RegexOptions.Multiline)]
76+
public static partial Regex VersionRegex { get; }
77+
}

.scripts/New.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
var chosenModule = AnsiConsole.Prompt(
1313
new SelectionPrompt<string>()
1414
.Title("Select the module to add the generator to:")
15-
.AddChoices(modules.Add("Other")));
15+
.AddChoices([..modules, "Other"]));
1616

1717
var newModule = false;
1818
if (chosenModule == "Other")

Forged/Forged.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>

taskfile.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
version: 3
2+
silent: true
23

34
tasks:
4-
new: dotnet run ./.scripts/New.cs
5+
new: dotnet run ./.scripts/New.cs
6+
bump: dotnet run ./.scripts/Bump.cs ./Forged/Forged.csproj

0 commit comments

Comments
 (0)