Skip to content

Commit 6a7f3e2

Browse files
committed
Add VersionTagPrefix property to customize recognition of version-like tags.
1 parent b6e5727 commit 6a7f3e2

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ Most lines should begin with one of these words:
55
*Add*, *Fix*, *Update*, *Change*, *Deprecate*, *Remove*.
66

77
<!--
8-
## [Unreleased](https://github.com/sharpjs/Subatomix.Build.Versioning.Semantic/compare/release/1.0.1..HEAD)
8+
## [Unreleased](https://github.com/sharpjs/Subatomix.Build.Versioning.Semantic/compare/release/1.1.0..HEAD)
99
-->
1010

11+
## [1.1.0](https://github.com/sharpjs/Subatomix.Build.Versioning.Semantic/compare/release/1.0.1..release/1.1.0)
12+
- Add `VersionTagPrefix` property to customize the prefix recognized for
13+
version-like tags.
14+
1115
## [1.0.1](https://github.com/sharpjs/Subatomix.Build.Versioning.Semantic/compare/release/1.0.0..release/1.0.1)
1216
- Fix use of [deprecated](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/)
1317
`set-output` workflow command in GitHub Actions.

src/Subatomix.Build.Versioning.Semantic.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<SetTeamCityBuildNumber Condition="'$(SetTeamCityBuildNumber)' == ''">false</SetTeamCityBuildNumber>
4646
<SetGitHubActionsVersion Condition="'$(SetGitHubActionsVersion)' == ''">false</SetGitHubActionsVersion>
4747
<RepositoryBranch Condition="'$(RepositoryBranch)' == ''">$(Branch)</RepositoryBranch>
48+
<VersionTagPrefix Condition="'$(VersionTagPrefix)' == ''">release/</VersionTagPrefix>
4849
</PropertyGroup>
4950

5051
<!-- Squash warning about using SemVer2 verions -->
@@ -77,11 +78,11 @@
7778
<AddCounterToVersionSuffix>true</AddCounterToVersionSuffix>
7879
</PropertyGroup>
7980
</When>
80-
<When Condition="$(Branch.StartsWith('refs/tags/release/'))">
81+
<When Condition="$(Branch.StartsWith('refs/tags/$(VersionTagPrefix)'))">
8182
<!-- Version suffix specified by source control -->
8283
<PropertyGroup>
83-
<BranchVersion >$([System.Text.RegularExpressions.Regex]::Match ($(Branch.Substring(18)), `^\d+\.\d+\.\d+` ))</BranchVersion>
84-
<NewVersionSuffix>$([System.Text.RegularExpressions.Regex]::Replace($(Branch.Substring(18)), `^\d+\.\d+\.\d+-?`, ``))</NewVersionSuffix>
84+
<BranchVersion >$([System.Text.RegularExpressions.Regex]::Match ($(Branch.Substring(10).Substring($(VersionTagPrefix.Length))), `^\d+\.\d+\.\d+` ))</BranchVersion>
85+
<NewVersionSuffix>$([System.Text.RegularExpressions.Regex]::Replace($(Branch.Substring(10).Substring($(VersionTagPrefix.Length))), `^\d+\.\d+\.\d+-?`, ``))</NewVersionSuffix>
8586
</PropertyGroup>
8687
</When>
8788
<Otherwise>

test/Test-Versioning.ps1

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,41 @@ Set-StrictMode -Version 3.0
1010
function Main {
1111
SetUp
1212

13-
Test SingleTarget "1T Default " <#none> <#none#> -Expect '^1\.2\.3-local$'
14-
Test SingleTarget "1T Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
15-
Test SingleTarget "1T Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
16-
Test SingleTarget "1T Branch + Counter " -Branch refs/heads/foo -Counter 42 -Expect '^1\.2\.3-foo\.b\.42$'
17-
Test SingleTarget "1T Pull Request " -Branch refs/pull/123/head <#none#> -Expect '^1\.2\.3-pr\.123\.\d{8}\.T\d{6}Z$'
18-
Test SingleTarget "1T Pull Request + Counter" -Branch refs/pull/123/head -Counter 42 -Expect '^1\.2\.3-pr\.123\.b\.42$'
19-
Test SingleTarget "1T Pre-Release " -Branch refs/tags/release/1.2.3-pre <#none#> -Expect '^1\.2\.3-pre$'
20-
Test SingleTarget "1T Pre-Release + Counter " -Branch refs/tags/release/1.2.3-pre -Counter 42 -Expect '^1\.2\.3-pre$'
21-
Test SingleTarget "1T Release " -Branch refs/tags/release/1.2.3 <#none#> -Expect '^1\.2\.3$'
22-
Test SingleTarget "1T Release + Counter " -Branch refs/tags/release/1.2.3 -Counter 42 -Expect '^1\.2\.3$'
23-
Test SingleTarget "1T Invalid " -Branch ?foo?bar? <#none#> -Expect '^1\.2\.3--foo-bar-\.\d{8}\.T\d{6}Z$'
24-
Test SingleTarget "1T Invalid + Counter " -Branch ?foo?bar? -Counter 42 -Expect '^1\.2\.3--foo-bar-\.b\.42$'
25-
Test SingleTarget "1T Explicit Suffix " -Branch refs/heads/foo -Suffix bar -Counter 42 -Expect '^1\.2\.3-bar$'
13+
Test SingleTarget "1T Default " <#none> <#none#> -Expect '^1\.2\.3-local$'
14+
Test SingleTarget "1T Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
15+
Test SingleTarget "1T Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
16+
Test SingleTarget "1T Branch + Counter " -Branch refs/heads/foo -Counter 42 -Expect '^1\.2\.3-foo\.b\.42$'
17+
Test SingleTarget "1T Pull Request " -Branch refs/pull/123/head <#none#> -Expect '^1\.2\.3-pr\.123\.\d{8}\.T\d{6}Z$'
18+
Test SingleTarget "1T Pull Request + Counter " -Branch refs/pull/123/head -Counter 42 -Expect '^1\.2\.3-pr\.123\.b\.42$'
19+
Test SingleTarget "1T Pre-Release " -Branch refs/tags/release/1.2.3-pre <#none#> -Expect '^1\.2\.3-pre$'
20+
Test SingleTarget "1T Pre-Release + Counter " -Branch refs/tags/release/1.2.3-pre -Counter 42 -Expect '^1\.2\.3-pre$'
21+
Test SingleTarget "1T Release " -Branch refs/tags/release/1.2.3 <#none#> -Expect '^1\.2\.3$'
22+
Test SingleTarget "1T Release + Counter " -Branch refs/tags/release/1.2.3 -Counter 42 -Expect '^1\.2\.3$'
23+
Test SingleTarget "1T VTag Pre-Release " -Branch refs/tags/v1.2.3-pre -VTag <#none#> -Expect '^1\.2\.3-pre$'
24+
Test SingleTarget "1T VTag Pre-Release + Counter" -Branch refs/tags/v1.2.3-pre -VTag -Counter 42 -Expect '^1\.2\.3-pre$'
25+
Test SingleTarget "1T VTag Release " -Branch refs/tags/v1.2.3 -VTag <#none#> -Expect '^1\.2\.3$'
26+
Test SingleTarget "1T VTag Release + Counter " -Branch refs/tags/v1.2.3 -VTag -Counter 42 -Expect '^1\.2\.3$'
27+
Test SingleTarget "1T Invalid " -Branch ?foo?bar? <#none#> -Expect '^1\.2\.3--foo-bar-\.\d{8}\.T\d{6}Z$'
28+
Test SingleTarget "1T Invalid + Counter " -Branch ?foo?bar? -Counter 42 -Expect '^1\.2\.3--foo-bar-\.b\.42$'
29+
Test SingleTarget "1T Explicit Suffix " -Branch refs/heads/foo -Suffix bar -Counter 42 -Expect '^1\.2\.3-bar$'
2630

27-
Test MultiTarget "MT Default " <#none> <#none#> -Expect '^1\.2\.3-local$'
28-
Test MultiTarget "MT Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
29-
Test MultiTarget "MT Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
30-
Test MultiTarget "MT Branch + Counter " -Branch refs/heads/foo -Counter 42 -Expect '^1\.2\.3-foo\.b\.42$'
31-
Test MultiTarget "MT Pull Request " -Branch refs/pull/123/head <#none#> -Expect '^1\.2\.3-pr\.123\.\d{8}\.T\d{6}Z$'
32-
Test MultiTarget "MT Pull Request + Counter" -Branch refs/pull/123/head -Counter 42 -Expect '^1\.2\.3-pr\.123\.b\.42$'
33-
Test MultiTarget "MT Pre-Release " -Branch refs/tags/release/1.2.3-pre <#none#> -Expect '^1\.2\.3-pre$'
34-
Test MultiTarget "MT Pre-Release + Counter " -Branch refs/tags/release/1.2.3-pre -Counter 42 -Expect '^1\.2\.3-pre$'
35-
Test MultiTarget "MT Release " -Branch refs/tags/release/1.2.3 <#none#> -Expect '^1\.2\.3$'
36-
Test MultiTarget "MT Release + Counter " -Branch refs/tags/release/1.2.3 -Counter 42 -Expect '^1\.2\.3$'
37-
Test MultiTarget "MT Invalid " -Branch ?foo?bar? <#none#> -Expect '^1\.2\.3--foo-bar-\.\d{8}\.T\d{6}Z$'
38-
Test MultiTarget "MT Invalid + Counter " -Branch ?foo?bar? -Counter 42 -Expect '^1\.2\.3--foo-bar-\.b\.42$'
39-
Test MultiTarget "MT Explicit Suffix " -Branch refs/heads/foo -Suffix bar -Counter 42 -Expect '^1\.2\.3-bar$'
31+
Test MultiTarget "MT Default " <#none> <#none#> -Expect '^1\.2\.3-local$'
32+
Test MultiTarget "MT Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
33+
Test MultiTarget "MT Branch " -Branch refs/heads/foo <#none#> -Expect '^1\.2\.3-foo\.\d{8}\.T\d{6}Z$'
34+
Test MultiTarget "MT Branch + Counter " -Branch refs/heads/foo -Counter 42 -Expect '^1\.2\.3-foo\.b\.42$'
35+
Test MultiTarget "MT Pull Request " -Branch refs/pull/123/head <#none#> -Expect '^1\.2\.3-pr\.123\.\d{8}\.T\d{6}Z$'
36+
Test MultiTarget "MT Pull Request + Counter " -Branch refs/pull/123/head -Counter 42 -Expect '^1\.2\.3-pr\.123\.b\.42$'
37+
Test MultiTarget "MT Pre-Release " -Branch refs/tags/release/1.2.3-pre <#none#> -Expect '^1\.2\.3-pre$'
38+
Test MultiTarget "MT Pre-Release + Counter " -Branch refs/tags/release/1.2.3-pre -Counter 42 -Expect '^1\.2\.3-pre$'
39+
Test MultiTarget "MT Release " -Branch refs/tags/release/1.2.3 <#none#> -Expect '^1\.2\.3$'
40+
Test MultiTarget "MT Release + Counter " -Branch refs/tags/release/1.2.3 -Counter 42 -Expect '^1\.2\.3$'
41+
Test MultiTarget "MT VTag Pre-Release " -Branch refs/tags/v1.2.3-pre -VTag <#none#> -Expect '^1\.2\.3-pre$'
42+
Test MultiTarget "MT VTag Pre-Release + Counter" -Branch refs/tags/v1.2.3-pre -VTag -Counter 42 -Expect '^1\.2\.3-pre$'
43+
Test MultiTarget "MT VTag Release " -Branch refs/tags/v1.2.3 -VTag <#none#> -Expect '^1\.2\.3$'
44+
Test MultiTarget "MT VTag Release + Counter " -Branch refs/tags/v1.2.3 -VTag -Counter 42 -Expect '^1\.2\.3$'
45+
Test MultiTarget "MT Invalid " -Branch ?foo?bar? <#none#> -Expect '^1\.2\.3--foo-bar-\.\d{8}\.T\d{6}Z$'
46+
Test MultiTarget "MT Invalid + Counter " -Branch ?foo?bar? -Counter 42 -Expect '^1\.2\.3--foo-bar-\.b\.42$'
47+
Test MultiTarget "MT Explicit Suffix " -Branch refs/heads/foo -Suffix bar -Counter 42 -Expect '^1\.2\.3-bar$'
4048
}
4149

4250
function SetUp {
@@ -50,6 +58,7 @@ function Test {
5058
[Parameter(Mandatory, Position=0)] [string] $Project,
5159
[Parameter(Mandatory, Position=1)] [string] $Name,
5260
[Parameter()] [string] $Branch,
61+
[Parameter()] [switch] $VTag,
5362
[Parameter()] [int] $Counter,
5463
[Parameter()] [string] $Suffix,
5564
[Parameter(Mandatory)] [regex] $Expect
@@ -64,6 +73,7 @@ function Test {
6473
"--no-restore"
6574
"--configuration:Release"
6675
if ($Suffix) { "--version-suffix:$Suffix" }
76+
if ($VTag) { "-p:VersionTagPrefix=v" }
6777
if ($Branch) { "-p:Branch=$Branch" }
6878
if ($Counter) { "-p:Counter=$Counter" }
6979
)

0 commit comments

Comments
 (0)