feat: restrict version to tag

This commit is contained in:
Tomasz Pluskiewicz 2021-01-30 16:09:56 +01:00 committed by GitHub
parent ade8d2e19b
commit 96636b210d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -225,6 +225,21 @@ Useful for projects where the version number may be output by a previous action.
version: "${{ steps.previous_step.outputs.version }}"
```
### minVersion
Set the minimum version which would be used to create a tag.
The default value (`0.0.1`) prevents a `0.0.0` from being created. This can also be used when introducing Autotag to a repository which has already tagged.
For example, if the version `0.1.0` would already have been published, set the `minVersion` to the next patch to preent a duplicate tag.
```yaml
- uses: butlerlogic/action-autotag@1.0.0
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
minVersion: "0.1.1"
```
## Developer Notes
If you are building an action that runs after this one, be aware this action produces several [outputs](https://help.github.com/en/articles/metadata-syntax-for-github-actions#outputs):

View File

@ -31,6 +31,10 @@ inputs:
version:
description: Explicitly set the version here instead of automatically detecting from `package.json`. Useful for non-JavaScript projects where version may be output by a previous action.
required: false
minVersion:
description: Minimum version required to create a tag. By default it will prevent a version `0.0.0` to be tagged. Also useful when introducing Autotag to an existing repo, to start auto-tagging from a specific version
required: false
default: '0.0.1'
regex_pattern:
description: An optional attribute containing the regular expression used to extract the version number.
required: false

View File

@ -48,6 +48,12 @@ async function run () {
if (!version) {
throw new Error(`No version identified${msg}`)
}
const minVersion = core.getInput('minVersion', { required: false })
if (version < minVersion) {
core.warning(`Version "${version}" is lower than minimum "${minVersion}"`)
return
}
core.warning(`Recognized "${version}"${msg}`)
core.setOutput('version', version)