Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7cb65aaacb | ||
|
0dca12c226 | ||
|
6f270f37d4 | ||
|
2860e42b1f | ||
|
6a86fe1739 | ||
|
86dc87790d | ||
|
b3281c85e6 | ||
|
9ba75ef142 | ||
|
a017e545d7 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,5 +1,17 @@
|
||||
# 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)
|
||||
|
||||
## 1.8.2 (2020/11/18)
|
||||
|
||||
* Remove duplicated tags
|
||||
|
||||
## 1.8.1 (2020/11/18)
|
||||
|
||||
* Missing input in `action.yml`
|
||||
|
59
README.md
59
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,37 +268,42 @@ 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 | Docker tags |
|
||||
|-------------------------|------------------------------------|-------------------|----------------------|---------------------------|
|
||||
| `v1.2.3` | `\d{1,3}.\d{1,3}.\d{1,3}` | `0` | :white_check_mark: | `1.2.3`, `latest` |
|
||||
| `v2.0.8-beta.67` | `v(.*)` | `1` | :white_check_mark: | `2.0.8-beta.67`, `latest` |
|
||||
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | :white_check_mark: | `2.0`, `latest` |
|
||||
| `release1` | `\d{1,3}.\d{1,3}` | `0` | :x: | `release1` |
|
||||
| `20200110-RC2` | `\d+` | `0` | :white_check_mark: | `20200110`, `latest` |
|
||||
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
|
||||
|
||||
If Git tag is a valid [semver](https://semver.org/) you can handle it to output multi Docker tags at once.
|
||||
`tag-semver` supports multi-line [Handlebars template](https://handlebarsjs.com/guide/) with the following inputs:
|
||||
|
||||
| Git tag | `tag-semver` | Valid | Docker tags |
|
||||
|--------------------|----------------------------------------------------------|--------------------|--------------------|
|
||||
| `v1.2.3` | `{{raw}}` | :white_check_mark: | `v1.2.3`, `latest` |
|
||||
| `v1.2.3` | `{{version}}` | :white_check_mark: | `1.2.3`, `latest` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}` | :white_check_mark: | `1.2`, `latest` |
|
||||
| `v1.2.3` | `v{{major}}` | :white_check_mark: | `v1`, `latest` |
|
||||
| `v1.2.3` | `{{minor}}` | :white_check_mark: | `2`, `latest` |
|
||||
| `v1.2.3` | `{{patch}}` | :white_check_mark: | `3`, `latest` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}`<br>`{{major}}.{{minor}}.{{patch}}` | :white_check_mark: | `1.2`, `1.2.3`, `latest` |
|
||||
| `v2.0.8-beta.67` | `{{raw}}` | :white_check_mark: | `v2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `{{version}}` | :white_check_mark: | `2.0.8-beta.67` |
|
||||
| `v2.0.8-beta.67` | `{{major}}.{{minor}}` | :white_check_mark: | `2.0` |
|
||||
| `release1` | `{{raw}}` | :x: | `release1` |
|
||||
| Git tag | `tag-semver` | Valid | Output tags | Output version |
|
||||
|--------------------|----------------------------------------------------------|--------------------|----------------------------|------------------------------|
|
||||
| `v1.2.3` | `{{raw}}` | :white_check_mark: | `v1.2.3`, `latest` | `v1.2.3` |
|
||||
| `v1.2.3` | `{{version}}` | :white_check_mark: | `1.2.3`, `latest` | `1.2.3` |
|
||||
| `v1.2.3` | `{{major}}.{{minor}}` | :white_check_mark: | `1.2`, `latest` | `1.2` |
|
||||
| `v1.2.3` | `v{{major}}` | :white_check_mark: | `v1`, `latest` | `v1` |
|
||||
| `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` | `{{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 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
|
||||
|
||||
|
@@ -683,11 +683,39 @@ describe('push tag', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}.{{patch}}'],
|
||||
} as Inputs,
|
||||
{
|
||||
main: '1.1.1',
|
||||
partial: [],
|
||||
latest: true
|
||||
} as Version,
|
||||
[
|
||||
'org/app:1.1.1',
|
||||
'org/app:latest',
|
||||
'ghcr.io/user/app:1.1.1',
|
||||
'ghcr.io/user/app:latest'
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.version=1.1.1",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'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',
|
||||
@@ -900,6 +928,32 @@ describe('latest', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
||||
tagMatchLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'v1.1.1',
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:v1.1.1',
|
||||
'ghcr.io/myuser/myapp:v1.1.1',
|
||||
],
|
||||
[
|
||||
"org.opencontainers.image.title=Hello-World",
|
||||
"org.opencontainers.image.description=This your first repo!",
|
||||
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
|
||||
"org.opencontainers.image.version=v1.1.1",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
||||
|
19
dist/index.js
generated
vendored
19
dist/index.js
generated
vendored
@@ -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) {
|
||||
@@ -240,6 +243,7 @@ class Meta {
|
||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||
}
|
||||
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||
return version;
|
||||
}
|
||||
tags() {
|
||||
@@ -249,15 +253,16 @@ class Meta {
|
||||
}
|
||||
let tags = [];
|
||||
for (const image of this.inputs.images) {
|
||||
tags.push(`${image}:${version.main}`);
|
||||
const imageLc = image.toLowerCase();
|
||||
tags.push(`${imageLc}:${version.main}`);
|
||||
for (const partial of version.partial) {
|
||||
tags.push(`${image}:${partial}`);
|
||||
tags.push(`${imageLc}:${partial}`);
|
||||
}
|
||||
if (version.latest) {
|
||||
tags.push(`${image}:latest`);
|
||||
tags.push(`${imageLc}:latest`);
|
||||
}
|
||||
if (this.context.sha && this.inputs.tagSha) {
|
||||
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
tags.push(`${imageLc}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
|
18
src/meta.ts
18
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) {
|
||||
@@ -82,6 +84,7 @@ export class Meta {
|
||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||
}
|
||||
|
||||
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -93,15 +96,16 @@ export class Meta {
|
||||
|
||||
let tags: Array<string> = [];
|
||||
for (const image of this.inputs.images) {
|
||||
tags.push(`${image}:${version.main}`);
|
||||
const imageLc = image.toLowerCase();
|
||||
tags.push(`${imageLc}:${version.main}`);
|
||||
for (const partial of version.partial) {
|
||||
tags.push(`${image}:${partial}`);
|
||||
tags.push(`${imageLc}:${partial}`);
|
||||
}
|
||||
if (version.latest) {
|
||||
tags.push(`${image}:latest`);
|
||||
tags.push(`${imageLc}:latest`);
|
||||
}
|
||||
if (this.context.sha && this.inputs.tagSha) {
|
||||
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
tags.push(`${imageLc}:sha-${this.context.sha.substr(0, 7)}`);
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
|
Reference in New Issue
Block a user