Skip to content

Commit

Permalink
Pre-release (rc, beta, alpha) will only extend {{version}} as tag for…
Browse files Browse the repository at this point in the history
… tag-semver
  • Loading branch information
crazy-max committed Nov 20, 2020
1 parent 0dca12c commit 7cb65aa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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}}`<br>`{{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

Expand Down
2 changes: 1 addition & 1 deletion __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7cb65aa

Please sign in to comment.