Skip to content

Commit

Permalink
Allow to disable latest tag (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
2 people authored and GitHub committed Dec 1, 2020
1 parent 4c2760b commit 9de4428
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ jobs:

tag-semver:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag-latest:
- 'true'
- 'false'
steps:
-
name: Checkout
Expand All @@ -97,6 +103,7 @@ jobs:
{{raw}}
{{version}}
{{major}}.{{minor}}.{{patch}}
tag-latest: ${{ matrix.tag-latest }}

docker-push:
runs-on: ubuntu-latest
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) |
Expand Down
14 changes: 7 additions & 7 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ describe('push tag', () => {
{
images: ['user/app'],
tagMatch: `\\d{8}`,
tagMatchLatest: false,
tagLatest: false,
} as Inputs,
{
main: '20200110',
Expand All @@ -464,7 +464,7 @@ describe('push tag', () => {
images: ['user/app'],
tagMatch: `(.*)-RC`,
tagMatchGroup: 1,
tagMatchLatest: false,
tagLatest: false,
} as Inputs,
{
main: '20200110',
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Inputs {
tagSemver: string[];
tagMatch: string;
tagMatchGroup: number;
tagMatchLatest: boolean;
tagLatest: boolean;
tagSchedule: string;
sepTags: string;
sepLabels: string;
Expand All @@ -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`,
Expand Down
6 changes: 3 additions & 3 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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, '-');
Expand Down

0 comments on commit 9de4428

Please sign in to comment.