Skip to content

Commit 35f2f92

Browse files
committed
feat: add prefix, additionalCommits and current noVersionBumpBehavior options
1 parent c675608 commit 35f2f92

File tree

7 files changed

+424
-105
lines changed

7 files changed

+424
-105
lines changed

.github/workflows/deploy.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
steps:
1111
- name: Checkout Code
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v3
1313
if: ${{ !env.ACT }}
1414

1515
- name: Get Next Version
@@ -47,6 +47,7 @@ jobs:
4747
with:
4848
allowUpdates: true
4949
draft: false
50+
makeLatest: true
5051
tag: ${{ steps.semver.outputs.next }}
5152
name: ${{ steps.semver.outputs.next }}
5253
body: ${{ steps.changelog.outputs.changes }}
@@ -67,7 +68,7 @@ jobs:
6768
# LOCAL TEST
6869

6970
- name: (local) Checkout Code
70-
uses: actions/checkout@v2
71+
uses: actions/checkout@v3
7172
if: ${{ env.ACT }}
7273
with:
7374
path: changelog-action

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ jobs:
6363
| `patchList` | Comma separated commit prefixes, used to bump Patch version. | :x: | `fix, bugfix, perf, refactor, test, tests` |
6464
| `patchAll` | If set to `true`, will ignore `patchList` and always count commits as a Patch. | :x: | `false` |
6565
| `skipInvalidTags` | If set to `true`, will skip tags that are not valid semver until it finds a proper one (up to 10 from latest). | :x: | `false` |
66-
| `noVersionBumpBehavior` | Whether to exit with an error *(default)*, a warning or silently when none of the commits result in a version bump. (Possible values: `error`, `warn` or `silent`) | :x: | `error` |
66+
| `noVersionBumpBehavior` | Whether to exit with an error *(default)*, a warning, the current version or silently when none of the commits result in a version bump. (Possible values: `error`, `warn`, `current` or `silent`) | :x: | `error` |
67+
| `prefix` | A prefix that will be ignored when parsing tags (e.g. `foobar/`). Useful for monorepos. The prefix will be added back to the output values. | :x: | |
68+
| `additionalCommits` | A list of additional commit messages to parse in order to calculate semver. | :x: | |
6769

6870
## Outputs
6971

action.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ inputs:
3030
required: false
3131
default: 'false'
3232
noVersionBumpBehavior:
33-
description: Whether to exit with an error, warning or silently when none of the commits result in a version bump. (error, warn, silent)
33+
description: Whether to exit with an error, warning or silently when none of the commits result in a version bump. (error, warn, current, silent)
3434
required: false
3535
default: error
36+
prefix:
37+
description: A prefix that will be ignored when parsing tags. Useful for monorepos. The prefix will be added back to the output values.
38+
required: false
39+
default: ''
40+
additionalCommits:
41+
description: A list of additional commit messages to parse in order to calculate semver.
42+
required: false
3643
outputs:
3744
current:
3845
description: Current version number / latest tag.

dist/index.js

+36-15
Original file line numberDiff line numberDiff line change
@@ -31051,6 +31051,8 @@ async function main () {
3105131051
const repo = github.context.repo.repo
3105231052
const skipInvalidTags = core.getBooleanInput('skipInvalidTags')
3105331053
const noVersionBumpBehavior = core.getInput('noVersionBumpBehavior')
31054+
const prefix = core.getInput('prefix') || ''
31055+
const additionalCommits = core.getInput('additionalCommits').split('\n').map(l => l.trim()).filter(l => l !== '')
3105431056

3105531057
const bumpTypes = {
3105631058
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
@@ -31059,6 +31061,16 @@ async function main () {
3105931061
patchAll: (core.getInput('patchAll') === true || core.getInput('patchAll') === 'true'),
3106031062
}
3106131063

31064+
function outputVersion (version) {
31065+
core.exportVariable('next', `${prefix}v${version}`)
31066+
core.exportVariable('nextStrict', `${prefix}${version}`)
31067+
31068+
core.setOutput('next', `${version}v${version}`)
31069+
core.setOutput('nextStrict', `${prefix}${version}`)
31070+
core.setOutput('nextMajor', `${prefix}v${semver.major(version)}`)
31071+
core.setOutput('nextMajorStrict', `${prefix}${semver.major(version)}`)
31072+
}
31073+
3106231074
// GET LATEST + PREVIOUS TAGS
3106331075

3106431076
const tagsRaw = await gh.graphql(`
@@ -31087,6 +31099,9 @@ async function main () {
3108731099
let latestTag = null
3108831100
let idx = 0
3108931101
for (const tag of tagsList) {
31102+
if (prefix && tag.name.indexOf(prefix) === 0) {
31103+
tag.name = tag.name.replace(prefix, '')
31104+
}
3109031105
if (semver.valid(tag.name)) {
3109131106
latestTag = tag
3109231107
break
@@ -31100,7 +31115,12 @@ async function main () {
3110031115
return core.setFailed(skipInvalidTags ? 'None of the 10 latest tags are valid semver!' : 'Latest tag is invalid (does not conform to semver)!')
3110131116
}
3110231117

31103-
core.info(`Comparing against latest tag: ${latestTag.name}`)
31118+
core.info(`Comparing against latest tag: ${prefix}${latestTag.name}`)
31119+
31120+
// OUTPUT CURRENT VARS
31121+
31122+
core.exportVariable('current', `${prefix}${latestTag.name}`)
31123+
core.setOutput('current', `${prefix}${latestTag.name}`)
3110431124

3110531125
// GET COMMITS
3110631126

@@ -31126,6 +31146,10 @@ async function main () {
3112631146
}
3112731147
} while (hasMoreCommits)
3112831148

31149+
if (additionalCommits && additionalCommits.length > 0) {
31150+
commits.push(...additionalCommits)
31151+
}
31152+
3112931153
if (!commits || commits.length < 1) {
3113031154
return core.setFailed('Couldn\'t find any commits between HEAD and latest tag.')
3113131155
}
@@ -31170,35 +31194,32 @@ async function main () {
3117031194
bump = 'patch'
3117131195
} else {
3117231196
switch (noVersionBumpBehavior) {
31173-
case 'warn': {
31174-
return core.warning('No commit resulted in a version bump since last release!')
31197+
case 'current': {
31198+
core.info('No commit resulted in a version bump since last release! Exiting with current as next version...')
31199+
outputVersion(semver.clean(latestTag.name))
31200+
return
3117531201
}
3117631202
case 'silent': {
3117731203
return core.info('No commit resulted in a version bump since last release! Exiting silently...')
3117831204
}
31205+
case 'warn': {
31206+
return core.warning('No commit resulted in a version bump since last release!')
31207+
}
3117931208
default: {
3118031209
return core.setFailed('No commit resulted in a version bump since last release!')
3118131210
}
3118231211
}
3118331212
}
31184-
core.info(`\n>>> Will bump version ${latestTag.name} using ${bump.toUpperCase()}\n`)
31213+
core.info(`\n>>> Will bump version ${prefix}${latestTag.name} using ${bump.toUpperCase()}\n`)
3118531214

3118631215
// BUMP VERSION
3118731216

3118831217
const next = semver.inc(latestTag.name, bump)
3118931218

31190-
core.info(`Current version is ${latestTag.name}`)
31191-
core.info(`Next version is v${next}`)
31192-
31193-
core.exportVariable('current', latestTag.name)
31194-
core.exportVariable('next', `v${next}`)
31195-
core.exportVariable('nextStrict', next)
31219+
core.info(`Current version is ${prefix}${latestTag.name}`)
31220+
core.info(`Next version is ${prefix}v${next}`)
3119631221

31197-
core.setOutput('current', latestTag.name)
31198-
core.setOutput('next', `v${next}`)
31199-
core.setOutput('nextStrict', next)
31200-
core.setOutput('nextMajor', `v${semver.major(next)}`)
31201-
core.setOutput('nextMajorStrict', semver.major(next))
31222+
outputVersion(next)
3120231223
}
3120331224

3120431225
main()

index.js

+36-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ async function main () {
1212
const repo = github.context.repo.repo
1313
const skipInvalidTags = core.getBooleanInput('skipInvalidTags')
1414
const noVersionBumpBehavior = core.getInput('noVersionBumpBehavior')
15+
const prefix = core.getInput('prefix') || ''
16+
const additionalCommits = core.getInput('additionalCommits').split('\n').map(l => l.trim()).filter(l => l !== '')
1517

1618
const bumpTypes = {
1719
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
@@ -20,6 +22,16 @@ async function main () {
2022
patchAll: (core.getInput('patchAll') === true || core.getInput('patchAll') === 'true'),
2123
}
2224

25+
function outputVersion (version) {
26+
core.exportVariable('next', `${prefix}v${version}`)
27+
core.exportVariable('nextStrict', `${prefix}${version}`)
28+
29+
core.setOutput('next', `${version}v${version}`)
30+
core.setOutput('nextStrict', `${prefix}${version}`)
31+
core.setOutput('nextMajor', `${prefix}v${semver.major(version)}`)
32+
core.setOutput('nextMajorStrict', `${prefix}${semver.major(version)}`)
33+
}
34+
2335
// GET LATEST + PREVIOUS TAGS
2436

2537
const tagsRaw = await gh.graphql(`
@@ -48,6 +60,9 @@ async function main () {
4860
let latestTag = null
4961
let idx = 0
5062
for (const tag of tagsList) {
63+
if (prefix && tag.name.indexOf(prefix) === 0) {
64+
tag.name = tag.name.replace(prefix, '')
65+
}
5166
if (semver.valid(tag.name)) {
5267
latestTag = tag
5368
break
@@ -61,7 +76,12 @@ async function main () {
6176
return core.setFailed(skipInvalidTags ? 'None of the 10 latest tags are valid semver!' : 'Latest tag is invalid (does not conform to semver)!')
6277
}
6378

64-
core.info(`Comparing against latest tag: ${latestTag.name}`)
79+
core.info(`Comparing against latest tag: ${prefix}${latestTag.name}`)
80+
81+
// OUTPUT CURRENT VARS
82+
83+
core.exportVariable('current', `${prefix}${latestTag.name}`)
84+
core.setOutput('current', `${prefix}${latestTag.name}`)
6585

6686
// GET COMMITS
6787

@@ -87,6 +107,10 @@ async function main () {
87107
}
88108
} while (hasMoreCommits)
89109

110+
if (additionalCommits && additionalCommits.length > 0) {
111+
commits.push(...additionalCommits)
112+
}
113+
90114
if (!commits || commits.length < 1) {
91115
return core.setFailed('Couldn\'t find any commits between HEAD and latest tag.')
92116
}
@@ -131,35 +155,32 @@ async function main () {
131155
bump = 'patch'
132156
} else {
133157
switch (noVersionBumpBehavior) {
134-
case 'warn': {
135-
return core.warning('No commit resulted in a version bump since last release!')
158+
case 'current': {
159+
core.info('No commit resulted in a version bump since last release! Exiting with current as next version...')
160+
outputVersion(semver.clean(latestTag.name))
161+
return
136162
}
137163
case 'silent': {
138164
return core.info('No commit resulted in a version bump since last release! Exiting silently...')
139165
}
166+
case 'warn': {
167+
return core.warning('No commit resulted in a version bump since last release!')
168+
}
140169
default: {
141170
return core.setFailed('No commit resulted in a version bump since last release!')
142171
}
143172
}
144173
}
145-
core.info(`\n>>> Will bump version ${latestTag.name} using ${bump.toUpperCase()}\n`)
174+
core.info(`\n>>> Will bump version ${prefix}${latestTag.name} using ${bump.toUpperCase()}\n`)
146175

147176
// BUMP VERSION
148177

149178
const next = semver.inc(latestTag.name, bump)
150179

151-
core.info(`Current version is ${latestTag.name}`)
152-
core.info(`Next version is v${next}`)
153-
154-
core.exportVariable('current', latestTag.name)
155-
core.exportVariable('next', `v${next}`)
156-
core.exportVariable('nextStrict', next)
180+
core.info(`Current version is ${prefix}${latestTag.name}`)
181+
core.info(`Next version is ${prefix}v${next}`)
157182

158-
core.setOutput('current', latestTag.name)
159-
core.setOutput('next', `v${next}`)
160-
core.setOutput('nextStrict', next)
161-
core.setOutput('nextMajor', `v${semver.major(next)}`)
162-
core.setOutput('nextMajorStrict', semver.major(next))
183+
outputVersion(next)
163184
}
164185

165186
main()

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"semver": "7.3.8"
2626
},
2727
"devDependencies": {
28-
"@vercel/ncc": "0.36.0",
29-
"eslint": "8.30.0",
28+
"@vercel/ncc": "0.36.1",
29+
"eslint": "8.34.0",
3030
"eslint-config-standard": "17.0.0",
31-
"eslint-plugin-import": "2.26.0",
31+
"eslint-plugin-import": "2.27.5",
3232
"eslint-plugin-node": "11.1.0",
3333
"eslint-plugin-promise": "6.1.1"
3434
}

0 commit comments

Comments
 (0)