From 55e66262893d667ab8c785dcb81c98427d233646 Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Thu, 10 Sep 2020 18:27:44 -0500 Subject: [PATCH] Added support for named groups when using regex pattern --- README.md | 9 +++++++++ app/lib/regex.js | 2 ++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 1cb9fb5..f6ddafe 100644 --- a/README.md +++ b/README.md @@ -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=)(?[\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`. diff --git a/app/lib/regex.js b/app/lib/regex.js index a86d1df..95557fb 100644 --- a/app/lib/regex.js +++ b/app/lib/regex.js @@ -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] }