Skip to content

Commit

Permalink
Generate latest tag by default on push tag event (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max authored Oct 28, 2020
1 parent 5ecce77 commit 6cc0747
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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/<default_branch>` | `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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js

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

2 changes: 2 additions & 0 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '-');
Expand Down

0 comments on commit 6cc0747

Please sign in to comment.