Added support for named groups when using regex pattern

This commit is contained in:
Corey Butler 2020-09-10 18:27:44 -05:00
parent 99d46556b4
commit 55e6626289
2 changed files with 11 additions and 0 deletions

View File

@ -140,6 +140,15 @@ The pattern described in this example is a simple one used. If you need a more c
`^((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-]+)*))?)$`
As of `1.0.3`, JavaScript named patterns are supported, where the group named `version` will be used to populate the tag. For example:
```yaml
- uses: butlerlogic/action-autotag@1.0.0
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
regex_pattern: "(version=)(?<version>[\d+\.]{3}([-\+][\w\.0-9]+)?)"
```
### 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`.

View File

@ -19,6 +19,8 @@ export default class Regex {
if (!content) {
this._version = null
// throw new Error(`Could not find pattern matching "${pattern.toString()}" in "${root}".`)
} else if (content.groups && content.groups.version) {
this._version = content.groups.version
} else {
this._version = content[1]
}