From 7cb65aaacb170c4921eb6b87920a05db5d3f65c7 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 20 Nov 2020 23:12:14 +0100 Subject: [PATCH] Pre-release (rc, beta, alpha) will only extend {{version}} as tag for tag-semver --- CHANGELOG.md | 4 ++++ README.md | 33 ++++++++++++++++++--------------- __tests__/meta.test.ts | 2 +- dist/index.js | 9 ++++++--- src/meta.ts | 8 +++++--- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbe2396..01b3a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.8.4 (2020/11/20) + +* Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag for `tag-semver` + ## 1.8.3 (2020/11/20) * Lowercase image name (#16) diff --git a/README.md b/README.md index b8992ee..4a1713d 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ ___ * [outputs](#outputs) * [Notes](#notes) * [Latest tag](#latest-tag) - * [`tag-match` examples](#tag-match-examples) * [Handle semver tag](#handle-semver-tag) + * [`tag-match` examples](#tag-match-examples) * [Schedule tag](#schedule-tag) * [Overwrite labels](#overwrite-labels) * [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot) @@ -250,6 +250,8 @@ Following inputs can be used as `step.with` keys > List/CSV type can be a newline or comma delimited string +> `tag-semver` and `tag-match` are mutually exclusive + ### outputs Following outputs are available @@ -266,18 +268,8 @@ Following outputs are available Latest Docker tag will be generated by default on `push tag` event. If for example you push the `v1.2.3` Git tag, you will have at the output of this action the Docker tags `v1.2.3` and `latest`. But you can allow the latest tag to be -generated only if the Git tag matches a regular expression with the [`tag-match` input](#tag-match-examples) or if -`tag-semver` is valid [semver](https://semver.org/). - -### `tag-match` examples - -| Git tag | `tag-match` | `tag-match-group` | Match | Output tags | Output version | -|-------------------------|------------------------------------|-------------------|----------------------|---------------------------|------------------------------| -| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | :white_check_mark: | `1.2.3`, `latest` | `1.2.3` | -| `v2.0.8-beta.67` | `v(.*)` | `1` | :white_check_mark: | `2.0.8-beta.67`, `latest` | `2.0.8-beta.67` | -| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | :white_check_mark: | `2.0`, `latest` | `2.0` | -| `release1` | `\d{1,3}.\d{1,3}` | `0` | :x: | `release1` | `release1` | -| `20200110-RC2` | `\d+` | `0` | :white_check_mark: | `20200110`, `latest` | `20200110` | +generated only if `tag-semver` is a valid [semver](https://semver.org/) or if Git tag matches a regular expression +with the [`tag-match` input](#tag-match-examples). ### Handle semver tag @@ -293,14 +285,25 @@ If Git tag is a valid [semver](https://semver.org/) you can handle it to output | `v1.2.3` | `{{minor}}` | :white_check_mark: | `2`, `latest` | `2` | | `v1.2.3` | `{{patch}}` | :white_check_mark: | `3`, `latest` | `3` | | `v1.2.3` | `{{major}}.{{minor}}`
`{{major}}.{{minor}}.{{patch}}` | :white_check_mark: | `1.2`, `1.2.3`, `latest` | `1.2`* | -| `v2.0.8-beta.67` | `{{raw}}` | :white_check_mark: | `2.0.8-beta.67` | `2.0.8-beta.67` | +| `v2.0.8-beta.67` | `{{raw}}` | :white_check_mark: | `2.0.8-beta.67`** | `2.0.8-beta.67` | | `v2.0.8-beta.67` | `{{version}}` | :white_check_mark: | `2.0.8-beta.67` | `2.0.8-beta.67` | | `v2.0.8-beta.67` | `{{major}}.{{minor}}` | :white_check_mark: | `2.0.8-beta.67`** | `2.0.8-beta.67` | | `release1` | `{{raw}}` | :x: | `release1` | `release1` | > *First occurrence of `tag-semver` will be taken as `output.version` -> **Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag +> **Pre-release (rc, beta, alpha) will only extend `{{version}}` as tag because they are updated frequently, +> and contain many breaking changes that are (by the author's design) not yet fit for public consumption. + +### `tag-match` examples + +| Git tag | `tag-match` | `tag-match-group` | Match | Output tags | Output version | +|-------------------------|------------------------------------|-------------------|----------------------|---------------------------|------------------------------| +| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | :white_check_mark: | `1.2.3`, `latest` | `1.2.3` | +| `v2.0.8-beta.67` | `v(.*)` | `1` | :white_check_mark: | `2.0.8-beta.67`, `latest` | `2.0.8-beta.67` | +| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | :white_check_mark: | `2.0`, `latest` | `2.0` | +| `release1` | `\d{1,3}.\d{1,3}` | `0` | :x: | `release1` | `release1` | +| `20200110-RC2` | `\d+` | `0` | :white_check_mark: | `20200110`, `latest` | `20200110` | ### Schedule tag diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index f5eccb8..3d58406 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -715,7 +715,7 @@ describe('push tag', () => { 'event_tag_v2.0.8-beta.67.env', { images: ['org/app', 'ghcr.io/user/app'], - tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'], + tagSemver: ['{{major}}.{{minor}}', '{{major}}'], } as Inputs, { main: '2.0.8-beta.67', diff --git a/dist/index.js b/dist/index.js index 1f65984..2c90a31 100644 --- a/dist/index.js +++ b/dist/index.js @@ -201,9 +201,12 @@ class Meta { const sver = semver.parse(version.main, { includePrerelease: true }); - version.latest = !semver.prerelease(version.main); - version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); - if (version.latest) { + if (semver.prerelease(version.main)) { + version.main = handlebars.compile('{{version}}')(sver); + } + else { + version.latest = true; + version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); for (const semverTpl of this.inputs.tagSemver) { const partial = handlebars.compile(semverTpl)(sver); if (partial == version.main) { diff --git a/src/meta.ts b/src/meta.ts index 68bee2a..9683439 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -47,9 +47,11 @@ export class Meta { const sver = semver.parse(version.main, { includePrerelease: true }); - version.latest = !semver.prerelease(version.main); - version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); - if (version.latest) { + if (semver.prerelease(version.main)) { + version.main = handlebars.compile('{{version}}')(sver); + } else { + version.latest = true; + version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); for (const semverTpl of this.inputs.tagSemver) { const partial = handlebars.compile(semverTpl)(sver); if (partial == version.main) {