Allow to disable latest tag (#23)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-12-01 06:29:34 +01:00 committed by GitHub
parent 4c2760ba7a
commit 9de4428611
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 20 deletions

View file

@ -82,6 +82,12 @@ 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
@ -97,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
@ -116,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

@ -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-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`) |
| `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`) |

View file

@ -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',
@ -742,15 +742,15 @@ describe('push tag', () => {
{ {
images: ['ghcr.io/user/app'], images: ['ghcr.io/user/app'],
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'], tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
tagLatest: false,
} as Inputs, } as Inputs,
{ {
main: 'sometag', main: 'sometag',
partial: [], partial: [],
latest: true latest: false
} as Version, } as Version,
[ [
'ghcr.io/user/app:sometag', 'ghcr.io/user/app:sometag'
'ghcr.io/user/app:latest',
], ],
[ [
"org.opencontainers.image.title=Hello-World", "org.opencontainers.image.title=Hello-World",
@ -932,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',
@ -958,7 +958,7 @@ describe('latest', () => {
'event_tag_v1.1.1.env', 'event_tag_v1.1.1.env',
{ {
images: ['org/app', 'ghcr.io/MyUSER/MyApp'], images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
tagMatchLatest: false, tagLatest: false,
} as Inputs, } as Inputs,
{ {
main: 'v1.1.1', main: 'v1.1.1',

View file

@ -31,8 +31,13 @@ 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:

8
dist/index.js generated vendored
View file

@ -28,7 +28,7 @@ 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',
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,
@ -210,7 +210,7 @@ class Meta {
version.main = handlebars.compile('{{version}}')(sver); version.main = handlebars.compile('{{version}}')(sver);
} }
else { else {
version.latest = true; version.latest = this.inputs.tagLatest;
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); 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);
@ -232,11 +232,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)) {

View file

@ -8,7 +8,7 @@ export interface Inputs {
tagSemver: string[]; tagSemver: string[];
tagMatch: string; tagMatch: string;
tagMatchGroup: number; tagMatchGroup: number;
tagMatchLatest: boolean; tagLatest: boolean;
tagSchedule: string; tagSchedule: string;
sepTags: string; sepTags: string;
sepLabels: string; sepLabels: string;
@ -24,7 +24,7 @@ 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',
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,

View file

@ -57,7 +57,7 @@ export class Meta {
if (semver.prerelease(version.main)) { if (semver.prerelease(version.main)) {
version.main = handlebars.compile('{{version}}')(sver); version.main = handlebars.compile('{{version}}')(sver);
} else { } else {
version.latest = true; version.latest = this.inputs.tagLatest;
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver); 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);
@ -77,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, '-');