Skip to content

Commit

Permalink
feat: add noVersionBumpBehavior option
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Dec 23, 2022
1 parent f473c22 commit c675608
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 60 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
with:
token: ${{ github.token }}
branch: main

- name: Create Draft Release
uses: ncipollo/release-action@v1
uses: ncipollo/release-action@v1.12.0
if: ${{ !env.ACT }}
with:
prerelease: true
Expand All @@ -39,21 +39,22 @@ jobs:
with:
token: ${{ github.token }}
tag: ${{ steps.semver.outputs.next }}
writeToFile: false

- name: Create Release
if: ${{ !env.ACT }}
uses: ncipollo/release-action@v1
uses: ncipollo/release-action@v1.12.0
with:
allowUpdates: true
draft: false
tag: ${{ steps.semver.outputs.next }}
name: ${{ steps.semver.outputs.next }}
body: ${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}

- name: Create Release (Major-only)
if: ${{ !env.ACT }}
uses: ncipollo/release-action@v1
uses: ncipollo/release-action@v1.12.0
with:
allowUpdates: true
draft: false
Expand All @@ -63,14 +64,6 @@ jobs:
body: ${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}

- name: Commit CHANGELOG.md
if: ${{ !env.ACT }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }} [skip ci]'
file_pattern: CHANGELOG.md

# LOCAL TEST

- name: (local) Checkout Code
Expand Down
12 changes: 0 additions & 12 deletions CHANGELOG.md

This file was deleted.

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ This GitHub Action automatically determinate the next release version to use bas
- [Inputs](#inputs)
- [Outputs](#outputs)

> Works great alongside the [Changelog from Conventional Commits](https://github.com/marketplace/actions/changelog-from-conventional-commits) action!
## Example workflow
``` yaml
name: Deploy

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
workflow_dispatch:

jobs:
deploy:
Expand All @@ -42,10 +42,11 @@ jobs:
branch: main

- name: Create Release
uses: ncipollo/release-action@v1
uses: ncipollo/release-action@v1.12.0
with:
allowUpdates: true
draft: false
makeLatest: true
name: ${{ steps.semver.outputs.next }}
body: Changelog Contents
token: ${{ github.token }}
Expand All @@ -61,7 +62,8 @@ jobs:
| `minorList` | Comma separated commit prefixes, used to bump Minor version. | :x: | `feat, feature` |
| `patchList` | Comma separated commit prefixes, used to bump Patch version. | :x: | `fix, bugfix, perf, refactor, test, tests` |
| `patchAll` | If set to `true`, will ignore `patchList` and always count commits as a Patch. | :x: | `false` |
| `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` |
| `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` |
| `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` |

## Outputs

Expand Down
12 changes: 10 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ inputs:
description: If set to true, will skip tags that are not valid semver until it finds a proper one (up to 10 from latest).
required: false
default: 'false'
noVersionBumpBehavior:
description: Whether to exit with an error, warning or silently when none of the commits result in a version bump. (error, warn, silent)
required: false
default: error
outputs:
current:
description: Current version number
description: Current version number / latest tag.
next:
description: Next version number in format v0.0.0
nextStrict:
description: Next version number without the v prefix
description: Next version number without the v prefix.
nextMajor:
description: Next version major number in format v0
nextMajorStrict:
description: Next version major number only.
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
13 changes: 12 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31050,6 +31050,7 @@ async function main () {
const owner = github.context.repo.owner
const repo = github.context.repo.repo
const skipInvalidTags = core.getBooleanInput('skipInvalidTags')
const noVersionBumpBehavior = core.getInput('noVersionBumpBehavior')

const bumpTypes = {
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
Expand Down Expand Up @@ -31168,7 +31169,17 @@ async function main () {
} else if (patchChanges.length > 0) {
bump = 'patch'
} else {
return core.setFailed('No commit resulted in a version bump since last release!')
switch (noVersionBumpBehavior) {
case 'warn': {
return core.warning('No commit resulted in a version bump since last release!')
}
case 'silent': {
return core.info('No commit resulted in a version bump since last release! Exiting silently...')
}
default: {
return core.setFailed('No commit resulted in a version bump since last release!')
}
}
}
core.info(`\n>>> Will bump version ${latestTag.name} using ${bump.toUpperCase()}\n`)

Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function main () {
const owner = github.context.repo.owner
const repo = github.context.repo.repo
const skipInvalidTags = core.getBooleanInput('skipInvalidTags')
const noVersionBumpBehavior = core.getInput('noVersionBumpBehavior')

const bumpTypes = {
major: core.getInput('majorList').split(',').map(p => p.trim()).filter(p => p),
Expand Down Expand Up @@ -129,7 +130,17 @@ async function main () {
} else if (patchChanges.length > 0) {
bump = 'patch'
} else {
return core.setFailed('No commit resulted in a version bump since last release!')
switch (noVersionBumpBehavior) {
case 'warn': {
return core.warning('No commit resulted in a version bump since last release!')
}
case 'silent': {
return core.info('No commit resulted in a version bump since last release! Exiting silently...')
}
default: {
return core.setFailed('No commit resulted in a version bump since last release!')
}
}
}
core.info(`\n>>> Will bump version ${latestTag.name} using ${bump.toUpperCase()}\n`)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"semver": "7.3.8"
},
"devDependencies": {
"@vercel/ncc": "0.34.0",
"eslint": "8.27.0",
"@vercel/ncc": "0.36.0",
"eslint": "8.30.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-node": "11.1.0",
Expand Down
48 changes: 24 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@
unist-util-visit "^2.0.3"
unist-util-visit-parents "^3.1.1"

"@eslint/eslintrc@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.3.3.tgz#2b044ab39fdfa75b4688184f9e573ce3c5b0ff95"
integrity sha512-uj3pT6Mg+3t39fvLrj8iuCIJ38zKO9FpGtJ4BBJebJhEwjoT+KLVNCcHT5QC9NGRIEi7fZ0ZR8YRb884auB4Lg==
"@eslint/eslintrc@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.0.tgz#8ec64e0df3e7a1971ee1ff5158da87389f167a63"
integrity sha512-7yfvXy6MWLgWSFsLhz5yH3iQ52St8cdUY6FoGieKkRDVxuxmrNuUetIuu6cmjNWwniUHiWXjxCr5tTXDrbYS5A==
dependencies:
ajv "^6.12.4"
debug "^4.3.2"
espree "^9.4.0"
globals "^13.15.0"
globals "^13.19.0"
ignore "^5.2.0"
import-fresh "^3.2.1"
js-yaml "^4.1.0"
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@humanwhocodes/config-array@^0.11.6":
version "0.11.7"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.7.tgz#38aec044c6c828f6ed51d5d7ae3d9b9faf6dbb0f"
integrity sha512-kBbPWzN8oVMLb0hOUYXhmxggL/1cJE6ydvjDIGi9EnAGUyA7cLVKQg+d/Dsm+KZwx2czGHrCmMVLiyg8s5JPKw==
"@humanwhocodes/config-array@^0.11.8":
version "0.11.8"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.8.tgz#03595ac2075a4dc0f191cc2131de14fbd7d410b9"
integrity sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==
dependencies:
"@humanwhocodes/object-schema" "^1.2.1"
debug "^4.1.1"
Expand Down Expand Up @@ -229,10 +229,10 @@
resolved "https://registry.npmjs.org/@types/unist/-/unist-2.0.6.tgz"
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==

"@vercel/ncc@0.34.0":
version "0.34.0"
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.34.0.tgz#d0139528320e46670d949c82967044a8f66db054"
integrity sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==
"@vercel/ncc@0.36.0":
version "0.36.0"
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.36.0.tgz#1f262b86fc4f0770bbc0fc1d331d5aaa1bd47334"
integrity sha512-/ZTUJ/ZkRt694k7KJNimgmHjtQcRuVwsST2Z6XfYveQIuBbHR+EqkTc1jfgPkQmMyk/vtpxo3nVxe8CNuau86A==

JSONStream@^1.0.4:
version "1.3.5"
Expand Down Expand Up @@ -688,13 +688,13 @@ eslint-visitor-keys@^3.3.0:
resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz"
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==

eslint@8.27.0:
version "8.27.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.27.0.tgz#d547e2f7239994ad1faa4bb5d84e5d809db7cf64"
integrity sha512-0y1bfG2ho7mty+SiILVf9PfuRA49ek4Nc60Wmmu62QlobNR+CeXa4xXIJgcuwSQgZiWaPH+5BDsctpIW0PR/wQ==
eslint@8.30.0:
version "8.30.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.30.0.tgz#83a506125d089eef7c5b5910eeea824273a33f50"
integrity sha512-MGADB39QqYuzEGov+F/qb18r4i7DohCDOfatHaxI2iGlPuC65bwG2gxgO+7DkyL38dRFaRH7RaRAgU6JKL9rMQ==
dependencies:
"@eslint/eslintrc" "^1.3.3"
"@humanwhocodes/config-array" "^0.11.6"
"@eslint/eslintrc" "^1.4.0"
"@humanwhocodes/config-array" "^0.11.8"
"@humanwhocodes/module-importer" "^1.0.1"
"@nodelib/fs.walk" "^1.2.8"
ajv "^6.10.0"
Expand All @@ -713,7 +713,7 @@ [email protected]:
file-entry-cache "^6.0.1"
find-up "^5.0.0"
glob-parent "^6.0.2"
globals "^13.15.0"
globals "^13.19.0"
grapheme-splitter "^1.0.4"
ignore "^5.2.0"
import-fresh "^3.0.0"
Expand Down Expand Up @@ -889,10 +889,10 @@ glob@^7.1.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

globals@^13.15.0:
version "13.17.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-13.17.0.tgz#902eb1e680a41da93945adbdcb5a9f361ba69bd4"
integrity sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw==
globals@^13.19.0:
version "13.19.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-13.19.0.tgz#7a42de8e6ad4f7242fbcca27ea5b23aca367b5c8"
integrity sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==
dependencies:
type-fest "^0.20.2"

Expand Down

0 comments on commit c675608

Please sign in to comment.