Skip to content

Commit

Permalink
Added support (and outputs) for semver builds and prereleases.
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed Apr 4, 2020
1 parent 155e0c9 commit 3c94e12
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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`.
Expand Down Expand Up @@ -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/[email protected]
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):
Expand All @@ -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.

---

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 8 additions & 0 deletions app/lib/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand Down

0 comments on commit 3c94e12

Please sign in to comment.