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+ }
0 commit comments