Skip to content

Commit f71b9ec

Browse files
committed
feat: support regex tag exclusions
1 parent 7bbf132 commit f71b9ec

20 files changed

Lines changed: 318 additions & 14 deletions

File tree

docs/input/docs/reference/configuration.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ commit-message-incrementing: Enabled
176176
ignore:
177177
paths: []
178178
sha: []
179+
tags: []
179180
increment: Inherit
180181
is-main-branch: false
181182
is-release-branch: false
@@ -210,7 +211,7 @@ update-build-number: true
210211
version-bump-reset-message: "=semver:"
211212
version-in-branch-pattern: "(?<version>[vV]?\\d+(\\.\\d+)?(\\.\\d+)?).*"
212213
```
213-
<sup><a href='/docs/workflows/GitFlow/v1.yml#L1-L168' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
214+
<sup><a href='/docs/workflows/GitFlow/v1.yml#L1-L169' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
214215
<!-- endSnippet -->
215216

216217
The supported built-in configuration for the `GitHubFlow` workflow (`workflow: GitHubFlow/v1`) looks like:
@@ -302,6 +303,7 @@ commit-message-incrementing: Enabled
302303
ignore:
303304
paths: []
304305
sha: []
306+
tags: []
305307
increment: Inherit
306308
is-main-branch: false
307309
is-release-branch: false
@@ -336,7 +338,7 @@ update-build-number: true
336338
version-bump-reset-message: "=semver:"
337339
version-in-branch-pattern: "(?<version>[vV]?\\d+(\\.\\d+)?(\\.\\d+)?).*"
338340
```
339-
<sup><a href='/docs/workflows/GitHubFlow/v1.yml#L1-L117' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitHubFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
341+
<sup><a href='/docs/workflows/GitHubFlow/v1.yml#L1-L118' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/GitHubFlow/v1.yml' title='Start of snippet'>anchor</a></sup>
340342
<!-- endSnippet -->
341343

342344
The preview built-in configuration (experimental usage only) for the `TrunkBased` workflow (`workflow: TrunkBased/preview1`) looks like:
@@ -417,6 +419,7 @@ commit-message-incrementing: Enabled
417419
ignore:
418420
paths: []
419421
sha: []
422+
tags: []
420423
increment: Inherit
421424
is-main-branch: false
422425
is-release-branch: false
@@ -447,7 +450,7 @@ update-build-number: true
447450
version-bump-reset-message: "=semver:"
448451
version-in-branch-pattern: "(?<version>[vV]?\\d+(\\.\\d+)?(\\.\\d+)?).*"
449452
```
450-
<sup><a href='/docs/workflows/TrunkBased/preview1.yml#L1-L102' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/TrunkBased/preview1.yml' title='Start of snippet'>anchor</a></sup>
453+
<sup><a href='/docs/workflows/TrunkBased/preview1.yml#L1-L103' title='Snippet source file'>snippet source</a> | <a href='#snippet-/docs/workflows/TrunkBased/preview1.yml' title='Start of snippet'>anchor</a></sup>
451454
<!-- endSnippet -->
452455

453456
The details of the available options are as follows:
@@ -719,6 +722,23 @@ ignore:
719722
- 764e16321318f2fdb9cdeaa56d1156a1cba307d7
720723
```
721724

725+
#### tags
726+
727+
A sequence of regular expressions matching tag names that should not be used as
728+
[version sources][version-sources]. Patterns are matched case-insensitively
729+
against the friendly tag name without the `refs/tags/` prefix. Multiple patterns
730+
use OR semantics, and `^` and `$` can be used to anchor a match.
731+
732+
```yaml
733+
ignore:
734+
tags:
735+
- ^experimental-
736+
- ^v0\.
737+
```
738+
739+
Ignoring a tag does not ignore the commit it points to. The commit remains part
740+
of version calculation and can still be reached through other references.
741+
722742
### increment
723743

724744
The part of the SemVer to increment when GitVersion detects it needs to be

docs/input/docs/reference/mdsource/configuration.source.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,23 @@ ignore:
317317
- 764e16321318f2fdb9cdeaa56d1156a1cba307d7
318318
```
319319

320+
#### tags
321+
322+
A sequence of regular expressions matching tag names that should not be used as
323+
[version sources][version-sources]. Patterns are matched case-insensitively
324+
against the friendly tag name without the `refs/tags/` prefix. Multiple patterns
325+
use OR semantics, and `^` and `$` can be used to anchor a match.
326+
327+
```yaml
328+
ignore:
329+
tags:
330+
- ^experimental-
331+
- ^v0\.
332+
```
333+
334+
Ignoring a tag does not ignore the commit it points to. The commit remains part
335+
of version calculation and can still be reached through other references.
336+
320337
### increment
321338

322339
The part of the SemVer to increment when GitVersion detects it needs to be

docs/input/docs/workflows/GitFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ commit-message-incrementing: Enabled
133133
ignore:
134134
paths: []
135135
sha: []
136+
tags: []
136137
increment: Inherit
137138
is-main-branch: false
138139
is-release-branch: false

docs/input/docs/workflows/GitHubFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ commit-message-incrementing: Enabled
8282
ignore:
8383
paths: []
8484
sha: []
85+
tags: []
8586
increment: Inherit
8687
is-main-branch: false
8788
is-release-branch: false

docs/input/docs/workflows/TrunkBased/preview1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ commit-message-incrementing: Enabled
7171
ignore:
7272
paths: []
7373
sha: []
74+
tags: []
7475
increment: Inherit
7576
is-main-branch: false
7677
is-release-branch: false

schemas/7.0/GitVersion.configuration.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@
201201
"sha": {
202202
"description": "A sequence of SHAs to be excluded from the version calculations.",
203203
"$ref": "#/$defs/hashSetOfString"
204+
},
205+
"tags": {
206+
"description": "A sequence of regular expressions matching friendly tag names to be excluded as version sources.",
207+
"$ref": "#/$defs/hashSetOfString"
204208
}
205209
}
206210
},

src/GitVersion.Configuration.Tests/Configuration/ConfigurationProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ commit-message-incrementing: Enabled
133133
ignore:
134134
paths: []
135135
sha: []
136+
tags: []
136137
increment: Inherit
137138
is-main-branch: false
138139
is-release-branch: false

src/GitVersion.Configuration.Tests/Configuration/IgnoreConfigurationTests.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,34 @@ public void ShouldSupportsOtherSequenceFormat()
4848
configuration.Ignore.Shas.ShouldBe(["b6c0c9fda88830ebcd563e500a5a7da5a1658e98", "6c19c7c219ecf8dbc468042baefa73a1b213e8b1"]);
4949
}
5050

51+
[Test]
52+
public void CanDeserializeCompactTagsSequence()
53+
{
54+
const string yaml = "ignore:\n tags: ['^preview-', '^v0\\.']";
55+
56+
var configuration = this.serializer.ReadConfiguration(yaml);
57+
58+
configuration.ShouldNotBeNull();
59+
configuration.Ignore.Tags.ShouldBe(["^preview-", "^v0\\."]);
60+
}
61+
62+
[Test]
63+
public void CanDeserializeMultilineTagsSequence()
64+
{
65+
const string yaml =
66+
"""
67+
ignore:
68+
tags:
69+
- ^preview-
70+
- ^v0\.
71+
""";
72+
73+
var configuration = this.serializer.ReadConfiguration(yaml);
74+
75+
configuration.ShouldNotBeNull();
76+
configuration.Ignore.Tags.ShouldBe(["^preview-", "^v0\\."]);
77+
}
78+
5179
[Test]
5280
public void WhenNotInConfigShouldHaveDefaults()
5381
{
@@ -60,6 +88,47 @@ public void WhenNotInConfigShouldHaveDefaults()
6088
configuration.Ignore.Before.ShouldBe(null);
6189
configuration.Ignore.Paths.ShouldBeEmpty();
6290
configuration.Ignore.Shas.ShouldBeEmpty();
91+
configuration.Ignore.Tags.ShouldBeEmpty();
92+
}
93+
94+
[Test]
95+
public void IsEmpty_WhenTagPatternIsConfigured_ReturnsFalse()
96+
{
97+
var ignoreConfig = new IgnoreConfiguration { Tags = ["^preview-"] };
98+
99+
ignoreConfig.IsEmpty.ShouldBeFalse();
100+
}
101+
102+
[Test]
103+
public void InvalidIgnoreTagExpression_ThrowsConfigurationExceptionWithPropertyAndPattern()
104+
{
105+
const string invalidExpression = "[invalid";
106+
107+
var exception = Should.Throw<ConfigurationException>(() => GitFlowConfigurationBuilder.New
108+
.WithIgnoreConfiguration(new IgnoreConfiguration { Tags = [invalidExpression] })
109+
.Build());
110+
111+
exception.Message.ShouldContain("ignore.tags");
112+
exception.Message.ShouldContain(invalidExpression);
113+
}
114+
115+
[Test]
116+
public void Serialize_IgnoreTagPatterns_UsesTagsPropertyName()
117+
{
118+
var ignoreConfig = new IgnoreConfiguration { Tags = ["^preview-"] };
119+
120+
var yaml = this.serializer.Serialize(ignoreConfig);
121+
122+
yaml.ShouldContain("tags:");
123+
yaml.ShouldContain("^preview-");
124+
}
125+
126+
[Test]
127+
public void IgnoreConfigurationBuilder_WithTags_PreservesCollection()
128+
{
129+
var ignoreConfig = IgnoreConfigurationBuilder.New.WithTags("^preview-", "^v0\\.").Build();
130+
131+
ignoreConfig.Tags.ShouldBe(["^preview-", "^v0\\."]);
63132
}
64133

65134
[Test]

src/GitVersion.Configuration.Tests/Workflows/approved/GitFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ commit-message-incrementing: Enabled
133133
ignore:
134134
paths: []
135135
sha: []
136+
tags: []
136137
increment: Inherit
137138
is-main-branch: false
138139
is-release-branch: false

src/GitVersion.Configuration.Tests/Workflows/approved/GitHubFlow/v1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ commit-message-incrementing: Enabled
8282
ignore:
8383
paths: []
8484
sha: []
85+
tags: []
8586
increment: Inherit
8687
is-main-branch: false
8788
is-release-branch: false

0 commit comments

Comments
 (0)