Skip to content

Commit

Permalink
Use RegExp to match against a Git tag instead of coerce
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Oct 26, 2020
1 parent 4a3aaf4 commit 983124b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2,339 deletions.
41 changes: 13 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ ___
* [inputs](#inputs)
* [outputs](#outputs)
* [Notes](#notes)
* [Latest tag](#latest-tag)
* [Coerces Git tag](#coerces-git-tag)
* [`tag-match` examples](#tag-match-examples)
* [Schedule tag](#schedule-tag)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [How can I help?](#how-can-i-help)
Expand Down Expand Up @@ -75,10 +74,9 @@ jobs:
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: |
name/app
ghcr.io/name/app
images: name/app
tag-sha: true
tag-match: \\d{1,3}.\\d{1,3}.\\d{1,3}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand Down Expand Up @@ -116,8 +114,8 @@ 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-coerce-tag` | String | Coerces Git tag to semver if possible using [template](#coerces-git-tag) |
| `tag-latest-match` | String | Set `latest` tag only if [matches with a pattern](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) |
| `tag-match` | String | RegExp to match against a Git tag and use match group as Docker tag |
| `tag-match-latest` | Bool | Set `latest` Docker tag if `tag-match` matches (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 All @@ -136,28 +134,15 @@ Following outputs are available

## Notes

### Latest tag
### `tag-match` examples

`latest` tag is created with the following conditions:

* Git tag is a valid [semver](https://semver.org/)
* Provided `tag-coerce-tag` is valid

If `tag-latest-match` is filled, then it has priority over the creation of the tag.

### Coerces Git tag

Provides a very forgiving translation of a non-semver tag to semver. For more information see
[Coercion section](https://www.npmjs.com/package/semver#coercion). `tag-coerce-tag` supports
[Handlebars template](https://handlebarsjs.com/guide/) with the following inputs:

| `tag-coerce-tag` | Git tag | Version |
|-------------------------|----------|---------|
| `{{raw}}` | `v1.2.3` | `1.2.3` |
| `{{major}}.{{minor}}` | `v1.2.3` | `1.2` |
| `{{major}}` | `v1.2.3` | `1` |
| `{{minor}}` | `v1.2.3` | `2` |
| `{{patch}}` | `v1.2.3` | `3` |
| Git tag | `tag-match` | Docker tag
|-------------------------|--------------------------------|-------------------|
| `v1.2.3` | `\\d{1,3}.\\d{1,3}.\\d{1,3}` | `1.2.3` |
| `v2.0.8-beta.67` | `\\d{1,3}.\\d{1,3}.\\d{1,3}.*` | `2.0.8-beta.67` |
| `v2.0.8-beta.67` | `\\d{1,3}.\\d{1,3}` | `2.0` |
| `release1` | `\\d{1,3}.\\d{1,3}` | `release1` |
| `20200110-RC2` | `\\d+` | `20200110` |

### Schedule tag

Expand Down
130 changes: 25 additions & 105 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,15 @@ describe('push tag', () => {
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagCoerceTag: '{{major}}',
tagMatch: `\\d{8}`,
tagMatchLatest: false,
} as Inputs,
{
version: '20200110',
latest: true
latest: false
} as Version,
[
'user/app:20200110',
'user/app:latest'
'user/app:20200110'
],
[
"org.opencontainers.image.title=Hello-World",
Expand All @@ -441,34 +441,11 @@ describe('push tag', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['user/app'],
} as Inputs,
{
version: '1.1.1',
latest: true
} as Version,
[
'user/app:1.1.1',
'user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '1.1.1',
Expand All @@ -491,39 +468,11 @@ describe('push tag', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagSha: true,
} as Inputs,
{
version: '1.1.1',
latest: true
} as Version,
[
'org/app:1.1.1',
'org/app:latest',
'org/app:sha-90dd603',
'ghcr.io/user/app:1.1.1',
'ghcr.io/user/app:latest',
'ghcr.io/user/app:sha-90dd603'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v2.0.8-beta.67.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}-(alpha|beta).\\d{1,3}`,
} as Inputs,
{
version: '2.0.8-beta.67',
Expand All @@ -550,7 +499,7 @@ describe('push tag', () => {
'event_tag_v2.0.8-beta.67.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagCoerceTag: '{{major}}.{{minor}}',
tagMatch: `\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '2.0',
Expand All @@ -577,7 +526,7 @@ describe('push tag', () => {
'event_tag_sometag.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagCoerceTag: '{{major}}.{{minor}}',
tagMatch: `\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: 'sometag',
Expand Down Expand Up @@ -608,7 +557,7 @@ describe('latest', () => {
'event_tag_release1.env',
{
images: ['user/app'],
tagLatestMatch: `^release`,
tagMatch: `^release\\d{1,2}`,
} as Inputs,
{
version: 'release1',
Expand All @@ -633,7 +582,7 @@ describe('latest', () => {
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagLatestMatch: `^\\d`,
tagMatch: `^\\d+-RC\\d{1,2}`,
} as Inputs,
{
version: '20200110-RC2',
Expand All @@ -658,8 +607,7 @@ describe('latest', () => {
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagCoerceTag: '{{major}}',
tagLatestMatch: `\\d`,
tagMatch: `\\d{8}`,
} as Inputs,
{
version: '20200110',
Expand All @@ -684,7 +632,7 @@ describe('latest', () => {
'event_tag_v1.1.1.env',
{
images: ['user/app'],
tagLatestMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '1.1.1',
Expand All @@ -711,46 +659,19 @@ describe('latest', () => {
images: ['org/app', 'ghcr.io/user/app'],
} as Inputs,
{
version: '1.1.1',
latest: true
} as Version,
[
'org/app:1.1.1',
'org/app:latest',
'ghcr.io/user/app:1.1.1',
'ghcr.io/user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagLatestMatch: `2.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '1.1.1',
version: 'v1.1.1',
latest: false
} as Version,
[
'org/app:1.1.1',
'ghcr.io/user/app:1.1.1',
'org/app:v1.1.1',
'ghcr.io/user/app:v1.1.1',
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.version=v1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
Expand All @@ -760,24 +681,24 @@ describe('latest', () => {
'event_tag_v2.0.8-beta.67.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagLatestMatch: `^\\d{1,3}.\\d{1,3}.\\d{1,3}`,
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '2.0.8-beta.67',
version: '2.0.8',
latest: true
} as Version,
[
'org/app:2.0.8-beta.67',
'org/app:2.0.8',
'org/app:latest',
'ghcr.io/user/app:2.0.8-beta.67',
'ghcr.io/user/app:2.0.8',
'ghcr.io/user/app:latest'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
"org.opencontainers.image.version=2.0.8-beta.67",
"org.opencontainers.image.version=2.0.8",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
Expand Down Expand Up @@ -1003,19 +924,18 @@ describe('release', () => {
images: ['user/app'],
} as Inputs,
{
version: '1.1.1',
latest: true
version: 'v1.1.1',
latest: false
} as Version,
[
'user/app:1.1.1',
'user/app:latest'
'user/app:v1.1.1',
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.version=v1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
Expand Down
9 changes: 5 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ inputs:
tag-edge-branch:
description: 'Branch that will be tagged as edge (default repo.default_branch)'
required: false
tag-coerce-tag:
description: 'Coerces Git tag to semver if possible using template'
tag-match:
description: 'RegExp to match against a Git tag and use match group as Docker tag'
required: false
tag-latest-match:
description: 'Set latest tag only if matches with a pattern'
tag-match-latest:
description: 'Set latest Docker tag if tag-match matches'
default: 'true'
required: false
tag-schedule:
description: 'Template to apply to schedule tag'
Expand Down
Loading

0 comments on commit 983124b

Please sign in to comment.