Skip to content

Commit d93d5fb

Browse files
committed
feat: add tagFilter option
1 parent 1c7c3f0 commit d93d5fb

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
| `noVersionBumpBehavior` | Whether to exit with an error *(default)*, a warning, silently, the current version or force bump using patch when none of the commits result in a version bump. (Possible values: `error`, `warn`, `current`, `patch` or `silent`) | :x: | `error` |
7171
| `prefix` | A prefix that will be striped when parsing tags (e.g. `foobar/`). Any other prefix will be ignored. Useful for monorepos. The prefix will be added back to the output values. | :x: | |
7272
| `skipInvalidTags` | If set to `true`, will skip tags that are not valid semver until it finds a proper one (up to `maxTagsFetch` from latest). | :x: | `false` |
73+
| `tagFilter` | If defined, only tags matching the regex pattern will be included (e.g. `^[a-f0-9.]+$`). Use a negative lookahead match to exclude tags (e.g. `^(?!abcd).*$`). When used in conjunction with the prefix option, the prefix is striped first, then the filter is applied. | :x: | |
7374

7475
## Outputs
7576

action.yml

+22-18
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,13 @@ inputs:
2525
description: If set to true, will ignore patchList and count any commit as a Patch
2626
required: false
2727
default: 'false'
28-
skipInvalidTags:
29-
description: If set to true, will skip tags that are not valid semver until it finds a proper one (up to maxTagsFetch from latest).
30-
required: false
31-
default: 'false'
32-
noVersionBumpBehavior:
33-
description: Whether to exit with an error, warning or silently when none of the commits result in a version bump. (error, warn, current, patch, silent)
34-
required: false
35-
default: error
36-
noNewCommitBehavior:
37-
description: Whether to exit with an error, warning or silently when there are no new commits since the latest tag. (error, warn, current, silent)
38-
required: false
39-
default: error
40-
prefix:
41-
description: A prefix that will be striped when parsing tags (e.g. `foobar/`). Any other prefix will be ignored. The prefix will be added back to the output values.
42-
required: false
43-
default: ''
4428
additionalCommits:
4529
description: A list of additional commit messages to parse in order to calculate semver.
4630
required: false
31+
fallbackTag:
32+
description: Fallback tag to use if no latest tag is found.
33+
required: false
34+
default: ''
4735
fromTag:
4836
description: Override the tag to use when comparing against the branch in order to fetch the list of commits.
4937
required: false
@@ -52,8 +40,24 @@ inputs:
5240
description: Maximum number of tags to fetch from latest.
5341
required: false
5442
default: '10'
55-
fallbackTag:
56-
description: Fallback tag to use if no latest tag is found.
43+
noNewCommitBehavior:
44+
description: Whether to exit with an error, warning or silently when there are no new commits since the latest tag. (error, warn, current, silent)
45+
required: false
46+
default: error
47+
noVersionBumpBehavior:
48+
description: Whether to exit with an error, warning or silently when none of the commits result in a version bump. (error, warn, current, patch, silent)
49+
required: false
50+
default: error
51+
prefix:
52+
description: A prefix that will be striped when parsing tags (e.g. `foobar/`). Any other prefix will be ignored. The prefix will be added back to the output values.
53+
required: false
54+
default: ''
55+
skipInvalidTags:
56+
description: If set to true, will skip tags that are not valid semver until it finds a proper one (up to maxTagsFetch from latest).
57+
required: false
58+
default: 'false'
59+
tagFilter:
60+
description: If defined, only tags matching the regex pattern will be included (e.g. `^[a-f0-9.]+$`). Use a negative lookahead match to exclude tags (e.g. `^(?!abcd).*$`). When used in conjunction with the prefix option, the prefix is striped first, then the filter is applied.
5761
required: false
5862
default: ''
5963
outputs:

dist/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -52963,6 +52963,7 @@ async function main () {
5296352963
const maxTagsToFetch = _.toSafeInteger(core.getInput('maxTagsToFetch') || 10)
5296452964
const fetchLimit = (maxTagsToFetch < 1 || maxTagsToFetch > 100) ? 10 : maxTagsToFetch
5296552965
const fallbackTag = core.getInput('fallbackTag')
52966+
const tagFilter = core.getInput('tagFilter')
5296652967

5296752968
const bumpTypes = {
5296852969
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
@@ -53027,6 +53028,12 @@ async function main () {
5302753028
}
5302853029
}
5302953030

53031+
let tagFilterRgx = null
53032+
if (tagFilter) {
53033+
core.info(`Will filter tags based on pattern: ${tagFilter}`)
53034+
tagFilterRgx = new RegExp(tagFilter)
53035+
}
53036+
5303053037
let idx = 0
5303153038
for (const tag of tagsList) {
5303253039
if (prefix) {
@@ -53036,6 +53043,11 @@ async function main () {
5303653043
continue
5303753044
}
5303853045
}
53046+
53047+
if (tagFilterRgx && !tagFilterRgx.test(tag.name)) {
53048+
continue
53049+
}
53050+
5303953051
if (semver.valid(tag.name)) {
5304053052
latestTag = tag
5304153053
break

index.js

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ async function main () {
1919
const maxTagsToFetch = _.toSafeInteger(core.getInput('maxTagsToFetch') || 10)
2020
const fetchLimit = (maxTagsToFetch < 1 || maxTagsToFetch > 100) ? 10 : maxTagsToFetch
2121
const fallbackTag = core.getInput('fallbackTag')
22+
const tagFilter = core.getInput('tagFilter')
2223

2324
const bumpTypes = {
2425
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
@@ -83,6 +84,12 @@ async function main () {
8384
}
8485
}
8586

87+
let tagFilterRgx = null
88+
if (tagFilter) {
89+
core.info(`Will filter tags based on pattern: ${tagFilter}`)
90+
tagFilterRgx = new RegExp(tagFilter)
91+
}
92+
8693
let idx = 0
8794
for (const tag of tagsList) {
8895
if (prefix) {
@@ -92,6 +99,11 @@ async function main () {
9299
continue
93100
}
94101
}
102+
103+
if (tagFilterRgx && !tagFilterRgx.test(tag.name)) {
104+
continue
105+
}
106+
95107
if (semver.valid(tag.name)) {
96108
latestTag = tag
97109
break

0 commit comments

Comments
 (0)