From 9de4428611f28258bcd28a8be4940033d2068172 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 1 Dec 2020 06:29:34 +0100 Subject: [PATCH] Allow to disable latest tag (#23) Co-authored-by: CrazyMax --- .github/workflows/ci.yml | 12 +++++++++++- README.md | 4 ++-- __tests__/meta.test.ts | 14 +++++++------- action.yml | 7 ++++++- dist/index.js | 8 ++++---- src/context.ts | 4 ++-- src/meta.ts | 6 +++--- 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e886b69..e2937c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,6 +82,12 @@ jobs: tag-semver: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + tag-latest: + - 'true' + - 'false' steps: - name: Checkout @@ -97,6 +103,7 @@ jobs: {{raw}} {{version}} {{major}}.{{minor}}.{{patch}} + tag-latest: ${{ matrix.tag-latest }} docker-push: runs-on: ubuntu-latest @@ -116,7 +123,10 @@ jobs: with: images: ${{ env.DOCKER_IMAGE }} 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 uses: docker/setup-qemu-action@v1 diff --git a/README.md b/README.md index 8eb5ed0..623df68 100644 --- a/README.md +++ b/README.md @@ -241,10 +241,10 @@ Following inputs can be used as `step.with` keys | `tag-sha` | Bool | Add git short SHA as Docker tag (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-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-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`) | | `sep-tags` | String | Separator to use for tags output (default `\n`) | | `sep-labels` | String | Separator to use for labels output (default `\n`) | diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index dfe08ad..ad63e7f 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -437,7 +437,7 @@ describe('push tag', () => { { images: ['user/app'], tagMatch: `\\d{8}`, - tagMatchLatest: false, + tagLatest: false, } as Inputs, { main: '20200110', @@ -464,7 +464,7 @@ describe('push tag', () => { images: ['user/app'], tagMatch: `(.*)-RC`, tagMatchGroup: 1, - tagMatchLatest: false, + tagLatest: false, } as Inputs, { main: '20200110', @@ -742,15 +742,15 @@ describe('push tag', () => { { images: ['ghcr.io/user/app'], tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'], + tagLatest: false, } as Inputs, { main: 'sometag', partial: [], - latest: true + latest: false } as Version, [ - 'ghcr.io/user/app:sometag', - 'ghcr.io/user/app:latest', + 'ghcr.io/user/app:sometag' ], [ "org.opencontainers.image.title=Hello-World", @@ -932,7 +932,7 @@ describe('latest', () => { 'event_tag_v1.1.1.env', { images: ['org/app', 'ghcr.io/user/app'], - tagMatchLatest: false, + tagLatest: false, } as Inputs, { main: 'v1.1.1', @@ -958,7 +958,7 @@ describe('latest', () => { 'event_tag_v1.1.1.env', { images: ['org/app', 'ghcr.io/MyUSER/MyApp'], - tagMatchLatest: false, + tagLatest: false, } as Inputs, { main: 'v1.1.1', diff --git a/action.yml b/action.yml index c899d46..8eadd19 100644 --- a/action.yml +++ b/action.yml @@ -31,8 +31,13 @@ inputs: description: 'Group to get if tag-match matches (default 0)' default: '0' 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: - 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' required: false tag-schedule: diff --git a/dist/index.js b/dist/index.js index 85e11d3..72fb643 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28,7 +28,7 @@ function getInputs() { tagSemver: getInputList('tag-semver'), tagMatch: core.getInput('tag-match'), 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', sepTags: core.getInput('sep-tags') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`, @@ -210,7 +210,7 @@ class Meta { version.main = handlebars.compile('{{version}}')(sver); } else { - version.latest = true; + version.latest = this.inputs.tagLatest; version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); for (const semverTpl of this.inputs.tagSemver) { const partial = handlebars.compile(semverTpl)(sver); @@ -232,11 +232,11 @@ class Meta { } if (tagMatch) { version.main = tagMatch[this.inputs.tagMatchGroup]; - version.latest = this.inputs.tagMatchLatest; + version.latest = this.inputs.tagLatest; } } else { - version.latest = this.inputs.tagMatchLatest; + version.latest = this.inputs.tagLatest; } } else if (/^refs\/heads\//.test(this.context.ref)) { diff --git a/src/context.ts b/src/context.ts index 8227241..e50221d 100644 --- a/src/context.ts +++ b/src/context.ts @@ -8,7 +8,7 @@ export interface Inputs { tagSemver: string[]; tagMatch: string; tagMatchGroup: number; - tagMatchLatest: boolean; + tagLatest: boolean; tagSchedule: string; sepTags: string; sepLabels: string; @@ -24,7 +24,7 @@ export function getInputs(): Inputs { tagSemver: getInputList('tag-semver'), tagMatch: core.getInput('tag-match'), 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', sepTags: core.getInput('sep-tags') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`, diff --git a/src/meta.ts b/src/meta.ts index f8ee02a..8fae9b9 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -57,7 +57,7 @@ export class Meta { if (semver.prerelease(version.main)) { version.main = handlebars.compile('{{version}}')(sver); } else { - version.latest = true; + version.latest = this.inputs.tagLatest; version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); for (const semverTpl of this.inputs.tagSemver) { const partial = handlebars.compile(semverTpl)(sver); @@ -77,10 +77,10 @@ export class Meta { } if (tagMatch) { version.main = tagMatch[this.inputs.tagMatchGroup]; - version.latest = this.inputs.tagMatchLatest; + version.latest = this.inputs.tagLatest; } } else { - version.latest = this.inputs.tagMatchLatest; + version.latest = this.inputs.tagLatest; } } else if (/^refs\/heads\//.test(this.context.ref)) { version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');