Added support (and outputs) for semver builds and prereleases.

This commit is contained in:
Corey Butler 2020-04-04 18:28:01 -05:00
parent 155e0c9674
commit 3c94e12b38
5 changed files with 34 additions and 14 deletions

View File

@ -123,6 +123,23 @@ _Using the **regex** strategy:_
The version will be extracted by scanning the content of `/path/to/subdirectory/my.file` for a string like `version=1.0.0`. See the `regex_pattern` option for more details.
### regex_pattern
An optional attribute containing the regular expression used to extract the version number.
```yaml
- uses: butlerlogic/action-autotag@1.0.0
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
regex_pattern: "version=([0-9\.]{5}([-\+][\w\.0-9]+)?)"
```
This attribute is used as the first argument of a [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) object. The first "group" (i.e. what's in the main set of parenthesis/the whole version number) will be used as the version number. For an example, see this [working example](regexr.com/51r8j).
The pattern described in this example is a simple one used. If you need a more complex one [complete pattern](https://regex101.com/r/vkijKf/1/) is:
`^((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$`
### tag_prefix
By default, [semantic versioning](https://semver.org/) is used, such as `1.0.0`. A prefix can be used to add text before the tag name. For example, if `tag_prefix` is set to `v`, then the tag would be labeled as `v1.0.0`.
@ -199,19 +216,6 @@ Useful for projects where the version number may be output by a previous action.
version: "${{ steps.previous_step.outputs.version }}"
```
### regex_pattern
An optional attribute containing the regular expression used to extract the version number.
```yaml
- uses: butlerlogic/action-autotag@1.0.0
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
regex_pattern: "version=([0-9\.]{3,}(-[\w\.0-9]+)?)"
```
This attribute is used as the first argument of a [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp) object. The first "group" (i.e. what's in the main set of parenthesis) will be used as the version number. For an example, see this [working example](regexr.com/51r8j).
## 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):
@ -223,6 +227,8 @@ If you are building an action that runs after this one, be aware this action pro
1. `tagmessage`: The message applied to the tag reference (this is what shows up on the tag screen on Github).
1. `tagcreated`: `yes` or `no`.
1. `version` will be the extracted/provided version.
1. `prerelease`: "yes" or "no", indicating the tag represents a semantic version pre-release.
1. `build`: "yes" or "no", indicating the tag represents a semantic version build.
---

View File

@ -49,6 +49,10 @@ outputs:
description: The name of the requested tag. This will be populated even if the tag is not created.
version:
description: The version, as defined in package.json or explicitly set in the input.
prerelease:
description: \"yes\" or \"no\", indicating the tag represents a semantic version pre-release.
build:
description: \"yes\" or \"no\", indicating the tag represents a semantic version build.
runs:
using: 'docker'
image: 'Dockerfile'

View File

@ -42,6 +42,14 @@ export default class Tag {
return this._ref || ''
}
get prerelease () {
return /([0-9\.]{5}(-[\w\.0-9]+)?)/i.test(this.version)
}
get build () {
return /([0-9\.]{5}(\+[\w\.0-9]+)?)/i.test(this.version)
}
async getMessage () {
if (this._message !== null) {
return this._message

View File

@ -54,6 +54,8 @@ async function run () {
core.warning(`Attempting to create ${tag.name} tag.`)
core.setOutput('tagrequested', tag.name)
core.setOutput('prerelease', tag.prerelease ? 'yes' : 'no')
core.setOutput('build', tag.build ? 'yes' : 'no')
// Check for existance of tag and abort (short circuit) if it already exists.
if (await tag.exists()) {

View File

@ -1,6 +1,6 @@
{
"name": "action-autotag-test",
"version": "1.1.0",
"version": "1.1.1",
"description": "This is a test file for the action.",
"main": "index.js",
"dependencies": {},