From 6cc07472c02282b001d84f98d2e9f08cc20a067b Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:25:31 +0100 Subject: [PATCH] Generate latest tag by default on push tag event (#5) Co-authored-by: CrazyMax --- README.md | 16 +++++++++------- __tests__/meta.test.ts | 17 +++++++++++------ dist/index.js | 3 +++ src/meta.ts | 2 ++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f50abcf..4238e53 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ ___ * [inputs](#inputs) * [outputs](#outputs) * [Notes](#notes) + * [Latest tag](#latest-tag) * [`tag-match` examples](#tag-match-examples) * [Schedule tag](#schedule-tag) * [Overwrite labels](#overwrite-labels) @@ -42,10 +43,9 @@ ___ |-----------------|-------------------------------|------------|-------------------------------------| | `schedule` | `refs/heads/master` | `45f132a` | `sha-45f132a`, `nightly` | | `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-a123b57`, `pr-2` | -| `push` | `refs/heads/` | `676cae2` | `sha-676cae2`, `edge` | -| `push` | `refs/heads/dev` | `cf20257` | `sha-cf20257`, `dev` | +| `push` | `refs/heads/master` | `cf20257` | `sha-cf20257`, `master` | | `push` | `refs/heads/my/branch` | `a5df687` | `sha-a5df687`, `my-branch` | -| `push tag` | `refs/tags/v1.2.3` | `bf4565b` | `sha-bf4565b`, `1.2.3`, `latest` | +| `push tag` | `refs/tags/v1.2.3` | `bf4565b` | `sha-bf4565b`, `v1.2.3`, `latest` | | `push tag` | `refs/tags/mytag` | `afb7833` | `sha-afb7833`, `mytag` | ## Usage @@ -76,10 +76,6 @@ jobs: uses: crazy-max/ghaction-docker-meta@v1 with: images: name/app - tag-sha: true - tag-edge: true - tag-match: 'v(.*)' - tag-match-group: '1' - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -138,6 +134,12 @@ Following outputs are available ## Notes +### Latest tag + +Latest Docker tag will be generated by default on `push tag` event. So 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). + ### `tag-match` examples | Git tag | `tag-match` | `tag-match-group` | Docker tag diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index 3406388..27bb9db 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -377,10 +377,11 @@ describe('push tag', () => { } as Inputs, { version: 'release1', - latest: false + latest: true } as Version, [ - 'user/app:release1' + 'user/app:release1', + 'user/app:latest' ], [ "org.opencontainers.image.title=Hello-World", @@ -400,10 +401,11 @@ describe('push tag', () => { } as Inputs, { version: '20200110-RC2', - latest: false + latest: true } as Version, [ - 'user/app:20200110-RC2' + 'user/app:20200110-RC2', + 'user/app:latest' ], [ "org.opencontainers.image.title=Hello-World", @@ -686,11 +688,13 @@ describe('latest', () => { } as Inputs, { version: 'v1.1.1', - latest: false + latest: true } as Version, [ 'org/app:v1.1.1', + 'org/app:latest', 'ghcr.io/user/app:v1.1.1', + 'ghcr.io/user/app:latest', ], [ "org.opencontainers.image.title=Hello-World", @@ -951,10 +955,11 @@ describe('release', () => { } as Inputs, { version: 'v1.1.1', - latest: false + latest: true } as Version, [ 'user/app:v1.1.1', + 'user/app:latest', ], [ "org.opencontainers.image.title=Hello-World", diff --git a/dist/index.js b/dist/index.js index 116eabf..1706fc8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -208,6 +208,9 @@ class Meta { version.latest = this.inputs.tagMatchLatest; } } + else { + version.latest = true; + } } else if (/^refs\/heads\//.test(this.context.ref)) { version.version = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-'); diff --git a/src/meta.ts b/src/meta.ts index 8d85431..f580a61 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -52,6 +52,8 @@ export class Meta { version.version = tagMatch[this.inputs.tagMatchGroup]; version.latest = this.inputs.tagMatchLatest; } + } else { + version.latest = true; } } else if (/^refs\/heads\//.test(this.context.ref)) { version.version = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');