Compare commits

..

14 Commits

Author SHA1 Message Date
CrazyMax
b747b8aaa7 Update CHANGELOG 2020-12-04 18:15:25 +01:00
CrazyMax
585ab8356c Allow to add custom tags (#24)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-04 17:12:39 +00:00
CrazyMax
9de4428611 Allow to disable latest tag (#23)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-01 05:29:34 +00:00
CrazyMax
4c2760ba7a Warn on invalid semver (#22)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-01 04:50:39 +00:00
CrazyMax
ef12c77b87 Avoid unnecessary calls to version (#21)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-12-01 04:38:08 +00:00
CrazyMax
c53f88523a Fix README 2020-11-24 14:12:22 +01:00
CrazyMax
6b4bf4724e Update CHANGELOG 2020-11-24 14:09:55 +01:00
Jeremy Gustie
d48c7d2917 Use sepLabels when joining labels for output (#17) 2020-11-24 13:08:49 +00:00
CrazyMax
7cb65aaacb Pre-release (rc, beta, alpha) will only extend {{version}} as tag for tag-semver 2020-11-20 23:12:14 +01:00
CrazyMax
0dca12c226 Update CHANGELOG 2020-11-20 20:26:04 +01:00
CrazyMax
6f270f37d4 Add test 2020-11-20 16:30:57 +01:00
CrazyMax
2860e42b1f Lowercase only on image name (#16) 2020-11-20 16:19:08 +01:00
CrazyMax
6a86fe1739 Tags to lowercase (#16) 2020-11-20 15:54:36 +01:00
CrazyMax
86dc87790d Update README 2020-11-18 17:56:39 +01:00
9 changed files with 412 additions and 71 deletions

View File

@@ -82,10 +82,18 @@ jobs:
tag-semver: tag-semver:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag-latest:
- 'true'
- 'false'
steps: steps:
- name: Checkout -
name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Docker meta -
name: Docker meta
uses: ./ uses: ./
with: with:
images: | images: |
@@ -95,6 +103,7 @@ jobs:
{{raw}} {{raw}}
{{version}} {{version}}
{{major}}.{{minor}}.{{patch}} {{major}}.{{minor}}.{{patch}}
tag-latest: ${{ matrix.tag-latest }}
docker-push: docker-push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -114,7 +123,10 @@ jobs:
with: with:
images: ${{ env.DOCKER_IMAGE }} images: ${{ env.DOCKER_IMAGE }}
tag-sha: true tag-sha: true
tag-match: '\d{1,3}.\d{1,3}.\d{1,3}' tag-semver: |
v{{version}}
v{{major}}.{{minor}}
v{{major}}
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1

View File

@@ -1,5 +1,24 @@
# Changelog # Changelog
## 1.9.0 (2020/12/04)
* Allow to add custom tags (#24)
* Allow to disable latest tag (#23)
* Warn on invalid semver (#22)
* Avoid unnecessary calls to version (#21)
## 1.8.5 (2020/11/24)
* Use sepLabels when joining labels for output (#17)
## 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) ## 1.8.2 (2020/11/18)
* Remove duplicated tags * Remove duplicated tags

View File

@@ -26,8 +26,8 @@ ___
* [outputs](#outputs) * [outputs](#outputs)
* [Notes](#notes) * [Notes](#notes)
* [Latest tag](#latest-tag) * [Latest tag](#latest-tag)
* [`tag-match` examples](#tag-match-examples)
* [Handle semver tag](#handle-semver-tag) * [Handle semver tag](#handle-semver-tag)
* [`tag-match` examples](#tag-match-examples)
* [Schedule tag](#schedule-tag) * [Schedule tag](#schedule-tag)
* [Overwrite labels](#overwrite-labels) * [Overwrite labels](#overwrite-labels)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot) * [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
@@ -168,11 +168,11 @@ jobs:
| Event | Ref | Commit SHA | Docker Tags | | Event | Ref | Commit SHA | Docker Tags |
|-----------------|-------------------------------|------------|-----------------------------------------| |-----------------|-------------------------------|------------|-----------------------------------------|
| `schedule` | `refs/heads/master` | `45f132a` | `sha-45f132a`, `nightly` | | `schedule` | `refs/heads/master` | `45f132a` | `sha-45f132a`, `nightly` |
| `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-45f132a`, `pr-2` | | `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-a123b57`, `pr-2` |
| `push` | `refs/heads/master` | `cf20257` | `sha-45f132a`, `master` | | `push` | `refs/heads/master` | `cf20257` | `sha-cf20257`, `master` |
| `push` | `refs/heads/my/branch` | `a5df687` | `sha-45f132a`, `my-branch` | | `push` | `refs/heads/my/branch` | `a5df687` | `sha-a5df687`, `my-branch` |
| `push tag` | `refs/tags/v1.2.3` | `ad132f5` | `sha-45f132a`, `1.2.3`, `1.2`, `latest` | | `push tag` | `refs/tags/v1.2.3` | `ad132f5` | `sha-ad132f5`, `1.2.3`, `1.2`, `latest` |
| `push tag` | `refs/tags/v2.0.8-beta.67` | `fc89efd` | `sha-45f132a`, `2.0.8-beta.67` | | `push tag` | `refs/tags/v2.0.8-beta.67` | `fc89efd` | `sha-fc89efd`, `2.0.8-beta.67` |
```yaml ```yaml
name: ci name: ci
@@ -200,6 +200,7 @@ jobs:
uses: crazy-max/ghaction-docker-meta@v1 uses: crazy-max/ghaction-docker-meta@v1
with: with:
images: name/app images: name/app
tag-sha: true
tag-semver: | tag-semver: |
{{version}} {{version}}
{{major}}.{{minor}} {{major}}.{{minor}}
@@ -240,16 +241,20 @@ Following inputs can be used as `step.with` keys
| `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) | | `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) |
| `tag-edge` | Bool | Enable edge branch tagging (default `false`) | | `tag-edge` | Bool | Enable edge branch tagging (default `false`) |
| `tag-edge-branch` | String | Branch that will be tagged as edge (default `repo.default_branch`) | | `tag-edge-branch` | String | Branch that will be tagged as edge (default `repo.default_branch`) |
| `tag-semver` | List | Handle Git tag as semver [template](#handle-semver-tag) if possible | | `tag-semver` | List/CSV | Handle Git tag as semver [template](#handle-semver-tag) if possible |
| `tag-match` | String | RegExp to match against a Git tag and use first match as Docker tag | | `tag-match` | String | RegExp to match against a Git tag and use first match as Docker tag |
| `tag-match-group` | Number | Group to get if `tag-match` matches (default `0`) | | `tag-match-group` | Number | Group to get if `tag-match` matches (default `0`) |
| `tag-match-latest` | Bool | Set `latest` Docker tag if `tag-match` matches or on Git tag event (default `true`) | | `tag-latest` | Bool | Set `latest` Docker tag if `tag-semver`, `tag-match` or Git tag event occurs (default `true`) |
| `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) | | `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) |
| `tag-custom` | List/CSV | List of custom tags |
| `tag-custom-only` | Bool | Only use `tag-custom` as Docker tags |
| `sep-tags` | String | Separator to use for tags output (default `\n`) | | `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) | | `sep-labels` | String | Separator to use for labels output (default `\n`) |
> List/CSV type can be a newline or comma delimited string > List/CSV type can be a newline or comma delimited string
> `tag-semver` and `tag-match` are mutually exclusive
### outputs ### outputs
Following outputs are available Following outputs are available
@@ -266,18 +271,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, 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 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 generated only if `tag-semver` is a valid [semver](https://semver.org/) or if Git tag matches a regular expression
`tag-semver` is valid [semver](https://semver.org/). with the [`tag-match` input](#tag-match-examples). Can be disabled if `tag-latest` is `false`.
### `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` |
### Handle semver tag ### Handle semver tag
@@ -292,12 +287,27 @@ If Git tag is a valid [semver](https://semver.org/) you can handle it to output
| `v1.2.3` | `v{{major}}` | :white_check_mark: | `v1`, `latest` | `v1` | | `v1.2.3` | `v{{major}}` | :white_check_mark: | `v1`, `latest` | `v1` |
| `v1.2.3` | `{{minor}}` | :white_check_mark: | `2`, `latest` | `2` | | `v1.2.3` | `{{minor}}` | :white_check_mark: | `2`, `latest` | `2` |
| `v1.2.3` | `{{patch}}` | :white_check_mark: | `3`, `latest` | `3` | | `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` | | `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: | `v2.0.8-beta.67` | `v2.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` | `{{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` | `2.0` | | `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` | | `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 ### Schedule tag
`tag-schedule` is specially crafted input to support [Handlebars template](https://handlebarsjs.com/guide/) with `tag-schedule` is specially crafted input to support [Handlebars template](https://handlebarsjs.com/guide/) with

View File

@@ -44,7 +44,7 @@ const tagsLabelsTest = async (envFile: string, inputs: Inputs, exVersion: Versio
const repo = await github.repo(process.env.GITHUB_TOKEN || ''); const repo = await github.repo(process.env.GITHUB_TOKEN || '');
const meta = new Meta({...getInputs(), ...inputs}, context, repo); const meta = new Meta({...getInputs(), ...inputs}, context, repo);
const version = meta.version(); const version = meta.version;
console.log('version', version); console.log('version', version);
expect(version).toEqual(exVersion); expect(version).toEqual(exVersion);
@@ -437,7 +437,7 @@ describe('push tag', () => {
{ {
images: ['user/app'], images: ['user/app'],
tagMatch: `\\d{8}`, tagMatch: `\\d{8}`,
tagMatchLatest: false, tagLatest: false,
} as Inputs, } as Inputs,
{ {
main: '20200110', main: '20200110',
@@ -464,7 +464,7 @@ describe('push tag', () => {
images: ['user/app'], images: ['user/app'],
tagMatch: `(.*)-RC`, tagMatch: `(.*)-RC`,
tagMatchGroup: 1, tagMatchGroup: 1,
tagMatchLatest: false, tagLatest: false,
} as Inputs, } as Inputs,
{ {
main: '20200110', main: '20200110',
@@ -715,7 +715,7 @@ describe('push tag', () => {
'event_tag_v2.0.8-beta.67.env', 'event_tag_v2.0.8-beta.67.env',
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'], tagSemver: ['{{major}}.{{minor}}', '{{major}}'],
} as Inputs, } as Inputs,
{ {
main: '2.0.8-beta.67', main: '2.0.8-beta.67',
@@ -737,6 +737,32 @@ describe('push tag', () => {
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
] ]
], ],
[
'event_tag_sometag.env',
{
images: ['ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
tagLatest: false,
} as Inputs,
{
main: 'sometag',
partial: [],
latest: false
} as Version,
[
'ghcr.io/user/app:sometag'
],
[
"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=sometag",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p event ', tagsLabelsTest); ])('given %p event ', tagsLabelsTest);
}); });
@@ -906,7 +932,7 @@ describe('latest', () => {
'event_tag_v1.1.1.env', 'event_tag_v1.1.1.env',
{ {
images: ['org/app', 'ghcr.io/user/app'], images: ['org/app', 'ghcr.io/user/app'],
tagMatchLatest: false, tagLatest: false,
} as Inputs, } as Inputs,
{ {
main: 'v1.1.1', main: 'v1.1.1',
@@ -928,6 +954,32 @@ describe('latest', () => {
"org.opencontainers.image.licenses=MIT" "org.opencontainers.image.licenses=MIT"
] ]
], ],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
tagLatest: 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); ])('given %p event ', tagsLabelsTest);
}); });
@@ -1177,3 +1229,193 @@ describe('release', () => {
], ],
])('given %p event ', tagsLabelsTest); ])('given %p event ', tagsLabelsTest);
}); });
describe('custom', () => {
// prettier-ignore
test.each([
[
'event_push.env',
{
images: ['user/app'],
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: 'dev',
partial: ['my', 'custom', 'tags'],
latest: false
} as Version,
[
'user/app:dev',
'user/app:my',
'user/app:custom',
'user/app:tags'
],
[
"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=dev",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_push.env',
{
images: ['user/app'],
tagCustom: ['my']
} as Inputs,
{
main: 'dev',
partial: ['my'],
latest: false
} as Version,
[
'user/app:dev',
'user/app:my'
],
[
"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=dev",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_release1.env',
{
images: ['user/app'],
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: 'release1',
partial: ['my', 'custom', 'tags'],
latest: true
} as Version,
[
'user/app:release1',
'user/app:my',
'user/app:custom',
'user/app:tags',
'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=release1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagMatch: `\\d{8}`,
tagLatest: false,
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: '20200110',
partial: ['my', 'custom', 'tags'],
latest: false
} as Version,
[
'user/app:20200110',
'user/app:my',
'user/app:custom',
'user/app:tags'
],
[
"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=20200110",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
tagCustom: ['my', 'custom', 'tags']
} as Inputs,
{
main: '1.1.1',
partial: ['1.1', '1', 'my', 'custom', 'tags'],
latest: true
} as Version,
[
'org/app:1.1.1',
'org/app:1.1',
'org/app:1',
'org/app:my',
'org/app:custom',
'org/app:tags',
'org/app:latest',
'ghcr.io/user/app:1.1.1',
'ghcr.io/user/app:1.1',
'ghcr.io/user/app:1',
'ghcr.io/user/app:my',
'ghcr.io/user/app:custom',
'ghcr.io/user/app:tags',
'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_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}.{{patch}}'],
tagCustom: ['my', 'custom', 'tags'],
tagCustomOnly: true,
} as Inputs,
{
main: 'my',
partial: ['custom', 'tags'],
latest: false
} as Version,
[
'org/app:my',
'org/app:custom',
'org/app:tags',
'ghcr.io/user/app:my',
'ghcr.io/user/app:custom',
'ghcr.io/user/app:tags'
],
[
"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=my",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
])('given %p event ', tagsLabelsTest);
});

View File

@@ -31,14 +31,25 @@ inputs:
description: 'Group to get if tag-match matches (default 0)' description: 'Group to get if tag-match matches (default 0)'
default: '0' default: '0'
required: false required: false
tag-latest:
description: 'Set latest Docker tag if tag-semver, tag-match or Git tag event occurs'
default: 'true'
required: false
tag-match-latest: tag-match-latest:
description: 'Set latest Docker tag if tag-match matches or on Git tag event' deprecationMessage: 'tag-match-latest is deprecated. Use tag-latest instead'
description: '(DEPRECATED) Set latest Docker tag if tag-match matches or on Git tag event'
default: 'true' default: 'true'
required: false required: false
tag-schedule: tag-schedule:
description: 'Template to apply to schedule tag' description: 'Template to apply to schedule tag'
default: 'nightly' default: 'nightly'
required: false required: false
tag-custom:
description: 'List of custom tags'
required: false
tag-custom-only:
description: 'Only use tag-custom as Docker tags'
required: false
sep-tags: sep-tags:
description: 'Separator to use for tags output (default \n)' description: 'Separator to use for tags output (default \n)'
required: false required: false

60
dist/index.js generated vendored
View File

@@ -28,8 +28,10 @@ function getInputs() {
tagSemver: getInputList('tag-semver'), tagSemver: getInputList('tag-semver'),
tagMatch: core.getInput('tag-match'), tagMatch: core.getInput('tag-match'),
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0, tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'), tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
tagSchedule: core.getInput('tag-schedule') || 'nightly', tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,
githubToken: core.getInput('github-token') githubToken: core.getInput('github-token')
@@ -131,7 +133,7 @@ function run() {
core.info(`runId: ${context.runId}`); core.info(`runId: ${context.runId}`);
core.endGroup(); core.endGroup();
const meta = new meta_1.Meta(inputs, context, repo); const meta = new meta_1.Meta(inputs, context, repo);
const version = meta.version(); const version = meta.version;
core.startGroup(`Docker image version`); core.startGroup(`Docker image version`);
core.info(version.main || ''); core.info(version.main || '');
core.endGroup(); core.endGroup();
@@ -149,7 +151,7 @@ function run() {
core.info(label); core.info(label);
} }
core.endGroup(); core.endGroup();
core.setOutput('labels', labels.join(inputs.sepTags)); core.setOutput('labels', labels.join(inputs.sepLabels));
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
@@ -171,6 +173,7 @@ exports.Meta = void 0;
const handlebars = __webpack_require__(7492); const handlebars = __webpack_require__(7492);
const moment = __webpack_require__(9623); const moment = __webpack_require__(9623);
const semver = __webpack_require__(1383); const semver = __webpack_require__(1383);
const core = __webpack_require__(2186);
class Meta { class Meta {
constructor(inputs, context, repo) { constructor(inputs, context, repo) {
this.inputs = inputs; this.inputs = inputs;
@@ -180,10 +183,11 @@ class Meta {
this.context = context; this.context = context;
this.repo = repo; this.repo = repo;
this.date = new Date(); this.date = new Date();
this.version = this.getVersion();
} }
version() { getVersion() {
const currentDate = this.date; const currentDate = this.date;
const version = { let version = {
main: undefined, main: undefined,
partial: [], partial: [],
latest: false latest: false
@@ -197,13 +201,19 @@ class Meta {
} }
else if (/^refs\/tags\//.test(this.context.ref)) { else if (/^refs\/tags\//.test(this.context.ref)) {
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'); version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
}
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) { if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
const sver = semver.parse(version.main, { const sver = semver.parse(version.main, {
includePrerelease: true includePrerelease: true
}); });
version.latest = !semver.prerelease(version.main); if (semver.prerelease(version.main)) {
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); version.main = handlebars.compile('{{version}}')(sver);
if (version.latest) { }
else {
version.latest = this.inputs.tagLatest;
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
for (const semverTpl of this.inputs.tagSemver) { for (const semverTpl of this.inputs.tagSemver) {
const partial = handlebars.compile(semverTpl)(sver); const partial = handlebars.compile(semverTpl)(sver);
if (partial == version.main) { if (partial == version.main) {
@@ -224,11 +234,11 @@ class Meta {
} }
if (tagMatch) { if (tagMatch) {
version.main = tagMatch[this.inputs.tagMatchGroup]; version.main = tagMatch[this.inputs.tagMatchGroup];
version.latest = this.inputs.tagMatchLatest; version.latest = this.inputs.tagLatest;
} }
} }
else { else {
version.latest = this.inputs.tagMatchLatest; version.latest = this.inputs.tagLatest;
} }
} }
else if (/^refs\/heads\//.test(this.context.ref)) { else if (/^refs\/heads\//.test(this.context.ref)) {
@@ -240,25 +250,37 @@ class Meta {
else if (/^refs\/pull\//.test(this.context.ref)) { else if (/^refs\/pull\//.test(this.context.ref)) {
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`; version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
} }
if (this.inputs.tagCustom.length > 0) {
if (this.inputs.tagCustomOnly) {
version = {
main: this.inputs.tagCustom.shift(),
partial: this.inputs.tagCustom,
latest: false
};
}
else {
version.partial.push(...this.inputs.tagCustom);
}
}
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index); version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
return version; return version;
} }
tags() { tags() {
const version = this.version(); if (!this.version.main) {
if (!version.main) {
return []; return [];
} }
let tags = []; let tags = [];
for (const image of this.inputs.images) { for (const image of this.inputs.images) {
tags.push(`${image}:${version.main}`); const imageLc = image.toLowerCase();
for (const partial of version.partial) { tags.push(`${imageLc}:${this.version.main}`);
tags.push(`${image}:${partial}`); for (const partial of this.version.partial) {
tags.push(`${imageLc}:${partial}`);
} }
if (version.latest) { if (this.version.latest) {
tags.push(`${image}:latest`); tags.push(`${imageLc}:latest`);
} }
if (this.context.sha && this.inputs.tagSha) { 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; return tags;
@@ -270,7 +292,7 @@ class Meta {
`org.opencontainers.image.description=${this.repo.description || ''}`, `org.opencontainers.image.description=${this.repo.description || ''}`,
`org.opencontainers.image.url=${this.repo.html_url || ''}`, `org.opencontainers.image.url=${this.repo.html_url || ''}`,
`org.opencontainers.image.source=${this.repo.html_url || ''}`, `org.opencontainers.image.source=${this.repo.html_url || ''}`,
`org.opencontainers.image.version=${this.version().main || ''}`, `org.opencontainers.image.version=${this.version.main || ''}`,
`org.opencontainers.image.created=${this.date.toISOString()}`, `org.opencontainers.image.created=${this.date.toISOString()}`,
`org.opencontainers.image.revision=${this.context.sha || ''}`, `org.opencontainers.image.revision=${this.context.sha || ''}`,
`org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}` `org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}`

View File

@@ -8,8 +8,10 @@ export interface Inputs {
tagSemver: string[]; tagSemver: string[];
tagMatch: string; tagMatch: string;
tagMatchGroup: number; tagMatchGroup: number;
tagMatchLatest: boolean; tagLatest: boolean;
tagSchedule: string; tagSchedule: string;
tagCustom: string[];
tagCustomOnly: boolean;
sepTags: string; sepTags: string;
sepLabels: string; sepLabels: string;
githubToken: string; githubToken: string;
@@ -24,8 +26,10 @@ export function getInputs(): Inputs {
tagSemver: getInputList('tag-semver'), tagSemver: getInputList('tag-semver'),
tagMatch: core.getInput('tag-match'), tagMatch: core.getInput('tag-match'),
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0, tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'), tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
tagSchedule: core.getInput('tag-schedule') || 'nightly', tagSchedule: core.getInput('tag-schedule') || 'nightly',
tagCustom: getInputList('tag-custom'),
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,
githubToken: core.getInput('github-token') githubToken: core.getInput('github-token')

View File

@@ -27,7 +27,7 @@ async function run() {
const meta: Meta = new Meta(inputs, context, repo); const meta: Meta = new Meta(inputs, context, repo);
const version: Version = meta.version(); const version: Version = meta.version;
core.startGroup(`Docker image version`); core.startGroup(`Docker image version`);
core.info(version.main || ''); core.info(version.main || '');
core.endGroup(); core.endGroup();
@@ -47,7 +47,7 @@ async function run() {
core.info(label); core.info(label);
} }
core.endGroup(); core.endGroup();
core.setOutput('labels', labels.join(inputs.sepTags)); core.setOutput('labels', labels.join(inputs.sepLabels));
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }

View File

@@ -2,6 +2,7 @@ import * as handlebars from 'handlebars';
import * as moment from 'moment'; import * as moment from 'moment';
import * as semver from 'semver'; import * as semver from 'semver';
import {Inputs} from './context'; import {Inputs} from './context';
import * as core from '@actions/core';
import {Context} from '@actions/github/lib/context'; import {Context} from '@actions/github/lib/context';
import {ReposGetResponseData} from '@octokit/types'; import {ReposGetResponseData} from '@octokit/types';
@@ -12,6 +13,8 @@ export interface Version {
} }
export class Meta { export class Meta {
public readonly version: Version;
private readonly inputs: Inputs; private readonly inputs: Inputs;
private readonly context: Context; private readonly context: Context;
private readonly repo: ReposGetResponseData; private readonly repo: ReposGetResponseData;
@@ -25,11 +28,12 @@ export class Meta {
this.context = context; this.context = context;
this.repo = repo; this.repo = repo;
this.date = new Date(); this.date = new Date();
this.version = this.getVersion();
} }
public version(): Version { private getVersion(): Version {
const currentDate = this.date; const currentDate = this.date;
const version: Version = { let version: Version = {
main: undefined, main: undefined,
partial: [], partial: [],
latest: false latest: false
@@ -43,13 +47,18 @@ export class Meta {
}); });
} else if (/^refs\/tags\//.test(this.context.ref)) { } else if (/^refs\/tags\//.test(this.context.ref)) {
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'); version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
}
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) { if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
const sver = semver.parse(version.main, { const sver = semver.parse(version.main, {
includePrerelease: true includePrerelease: true
}); });
version.latest = !semver.prerelease(version.main); if (semver.prerelease(version.main)) {
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); version.main = handlebars.compile('{{version}}')(sver);
if (version.latest) { } else {
version.latest = this.inputs.tagLatest;
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
for (const semverTpl of this.inputs.tagSemver) { for (const semverTpl of this.inputs.tagSemver) {
const partial = handlebars.compile(semverTpl)(sver); const partial = handlebars.compile(semverTpl)(sver);
if (partial == version.main) { if (partial == version.main) {
@@ -68,10 +77,10 @@ export class Meta {
} }
if (tagMatch) { if (tagMatch) {
version.main = tagMatch[this.inputs.tagMatchGroup]; version.main = tagMatch[this.inputs.tagMatchGroup];
version.latest = this.inputs.tagMatchLatest; version.latest = this.inputs.tagLatest;
} }
} else { } else {
version.latest = this.inputs.tagMatchLatest; version.latest = this.inputs.tagLatest;
} }
} else if (/^refs\/heads\//.test(this.context.ref)) { } else if (/^refs\/heads\//.test(this.context.ref)) {
version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-'); version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
@@ -82,27 +91,39 @@ export class Meta {
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`; version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
} }
if (this.inputs.tagCustom.length > 0) {
if (this.inputs.tagCustomOnly) {
version = {
main: this.inputs.tagCustom.shift(),
partial: this.inputs.tagCustom,
latest: false
};
} else {
version.partial.push(...this.inputs.tagCustom);
}
}
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index); version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
return version; return version;
} }
public tags(): Array<string> { public tags(): Array<string> {
const version: Version = this.version(); if (!this.version.main) {
if (!version.main) {
return []; return [];
} }
let tags: Array<string> = []; let tags: Array<string> = [];
for (const image of this.inputs.images) { for (const image of this.inputs.images) {
tags.push(`${image}:${version.main}`); const imageLc = image.toLowerCase();
for (const partial of version.partial) { tags.push(`${imageLc}:${this.version.main}`);
tags.push(`${image}:${partial}`); for (const partial of this.version.partial) {
tags.push(`${imageLc}:${partial}`);
} }
if (version.latest) { if (this.version.latest) {
tags.push(`${image}:latest`); tags.push(`${imageLc}:latest`);
} }
if (this.context.sha && this.inputs.tagSha) { 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; return tags;
@@ -114,7 +135,7 @@ export class Meta {
`org.opencontainers.image.description=${this.repo.description || ''}`, `org.opencontainers.image.description=${this.repo.description || ''}`,
`org.opencontainers.image.url=${this.repo.html_url || ''}`, `org.opencontainers.image.url=${this.repo.html_url || ''}`,
`org.opencontainers.image.source=${this.repo.html_url || ''}`, `org.opencontainers.image.source=${this.repo.html_url || ''}`,
`org.opencontainers.image.version=${this.version().main || ''}`, `org.opencontainers.image.version=${this.version.main || ''}`,
`org.opencontainers.image.created=${this.date.toISOString()}`, `org.opencontainers.image.created=${this.date.toISOString()}`,
`org.opencontainers.image.revision=${this.context.sha || ''}`, `org.opencontainers.image.revision=${this.context.sha || ''}`,
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}` `org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`