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:
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

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

View file

@ -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',

View file

@ -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:

8
dist/index.js generated vendored
View file

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

View file

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

View file

@ -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, '-');