mirror of
https://github.com/docker/metadata-action.git
synced 2024-11-22 20:15:41 +01:00
Add tag-match-group input to choose group to get if tag-match matches
Check tag-match is a valid regex
This commit is contained in:
parent
ad83daa929
commit
6fe5b3f6bb
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -58,9 +58,13 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
tag-match:
|
include:
|
||||||
- \\d{1,3}.\\d{1,3}.\\d{1,3}
|
- tag-match: '\d{1,3}.\d{1,3}.\d{1,3}'
|
||||||
- \\d{1,3}.\\d{1,3}
|
tag-match-group: '0'
|
||||||
|
- tag-match: '\d{1,3}.\d{1,3}'
|
||||||
|
tag-match-group: '0'
|
||||||
|
- tag-match: 'v(.*)'
|
||||||
|
tag-match-group: '1'
|
||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
@ -74,6 +78,7 @@ jobs:
|
|||||||
ghcr.io/name/app
|
ghcr.io/name/app
|
||||||
tag-sha: true
|
tag-sha: true
|
||||||
tag-match: ${{ matrix.tag-match }}
|
tag-match: ${{ matrix.tag-match }}
|
||||||
|
tag-match-group: ${{ matrix.tag-match-group }}
|
||||||
|
|
||||||
docker-push:
|
docker-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 1.5.0 (2020/10/27)
|
||||||
|
|
||||||
|
* Add `tag-match-group` input to choose group to get if `tag-match` matches
|
||||||
|
* Check `tag-match` is a valid regex
|
||||||
|
|
||||||
## 1.4.0 (2020/10/27)
|
## 1.4.0 (2020/10/27)
|
||||||
|
|
||||||
* Use RegExp to match against a Git tag instead of coerce
|
* Use RegExp to match against a Git tag instead of coerce
|
||||||
|
20
README.md
20
README.md
@ -76,7 +76,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
images: name/app
|
images: name/app
|
||||||
tag-sha: true
|
tag-sha: true
|
||||||
tag-match: \\d{1,3}.\\d{1,3}.\\d{1,3}
|
tag-match: v(.*)
|
||||||
|
tag-match-group: 1
|
||||||
-
|
-
|
||||||
name: Set up QEMU
|
name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v1
|
||||||
@ -114,7 +115,8 @@ 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-match` | String | RegExp to match against a Git tag and use match group 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-latest` | Bool | Set `latest` Docker tag if `tag-match` matches (default `true`) |
|
| `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`) |
|
| `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`) |
|
||||||
@ -136,13 +138,13 @@ Following outputs are available
|
|||||||
|
|
||||||
### `tag-match` examples
|
### `tag-match` examples
|
||||||
|
|
||||||
| Git tag | `tag-match` | Docker tag
|
| Git tag | `tag-match` | `tag-match-group` | Docker tag
|
||||||
|-------------------------|--------------------------------|-------------------|
|
|-------------------------|------------------------------------|-------------------|------------------|
|
||||||
| `v1.2.3` | `\\d{1,3}.\\d{1,3}.\\d{1,3}` | `1.2.3` |
|
| `v1.2.3` | `\\d{1,3}.\\d{1,3}.\\d{1,3}` | `0` | `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` | `v(.*)` | `1` | `2.0.8-beta.67` |
|
||||||
| `v2.0.8-beta.67` | `\\d{1,3}.\\d{1,3}` | `2.0` |
|
| `v2.0.8-beta.67` | `v(\\d.\\d)` | `1` | `2.0` |
|
||||||
| `release1` | `\\d{1,3}.\\d{1,3}` | `release1` |
|
| `release1` | `\\d{1,3}.\\d{1,3}` | `0` | `release1` |
|
||||||
| `20200110-RC2` | `\\d+` | `20200110` |
|
| `20200110-RC2` | `\\d+` | `0` | `20200110` |
|
||||||
|
|
||||||
### Schedule tag
|
### Schedule tag
|
||||||
|
|
||||||
|
@ -441,6 +441,32 @@ describe('push tag', () => {
|
|||||||
"org.opencontainers.image.licenses=MIT"
|
"org.opencontainers.image.licenses=MIT"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'event_tag_20200110-RC2.env',
|
||||||
|
{
|
||||||
|
images: ['user/app'],
|
||||||
|
tagMatch: `(.*)-RC`,
|
||||||
|
tagMatchGroup: 1,
|
||||||
|
tagMatchLatest: false,
|
||||||
|
} as Inputs,
|
||||||
|
{
|
||||||
|
version: '20200110',
|
||||||
|
latest: false
|
||||||
|
} as Version,
|
||||||
|
[
|
||||||
|
'user/app:20200110'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"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=20200110",
|
||||||
|
"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',
|
'event_tag_v1.1.1.env',
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,10 @@ inputs:
|
|||||||
tag-match:
|
tag-match:
|
||||||
description: 'RegExp to match against a Git tag and use match group as Docker tag'
|
description: 'RegExp to match against a Git tag and use match group as Docker tag'
|
||||||
required: false
|
required: false
|
||||||
|
tag-match-group:
|
||||||
|
description: 'Group to get if tag-match matches (default 0)'
|
||||||
|
default: '0'
|
||||||
|
required: false
|
||||||
tag-match-latest:
|
tag-match-latest:
|
||||||
description: 'Set latest Docker tag if tag-match matches'
|
description: 'Set latest Docker tag if tag-match matches'
|
||||||
default: 'true'
|
default: 'true'
|
||||||
|
12
dist/index.js
generated
vendored
12
dist/index.js
generated
vendored
@ -26,6 +26,7 @@ function getInputs() {
|
|||||||
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
||||||
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
||||||
tagMatch: core.getInput('tag-match'),
|
tagMatch: core.getInput('tag-match'),
|
||||||
|
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
||||||
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
|
tagMatchLatest: /true/i.test(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`,
|
||||||
@ -194,9 +195,16 @@ class Meta {
|
|||||||
else if (/^refs\/tags\//.test(this.context.ref)) {
|
else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||||
version.version = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
version.version = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||||
if (this.inputs.tagMatch) {
|
if (this.inputs.tagMatch) {
|
||||||
const tagMatch = version.version.match(this.inputs.tagMatch);
|
let tagMatch;
|
||||||
|
const isRegEx = this.inputs.tagMatch.match(/^\/(.+)\/(.*)$/);
|
||||||
|
if (isRegEx) {
|
||||||
|
tagMatch = version.version.match(new RegExp(isRegEx[1], isRegEx[2]));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tagMatch = version.version.match(this.inputs.tagMatch);
|
||||||
|
}
|
||||||
if (tagMatch) {
|
if (tagMatch) {
|
||||||
version.version = tagMatch[0];
|
version.version = tagMatch[this.inputs.tagMatchGroup];
|
||||||
version.latest = this.inputs.tagMatchLatest;
|
version.latest = this.inputs.tagMatchLatest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ export interface Inputs {
|
|||||||
tagEdge: boolean;
|
tagEdge: boolean;
|
||||||
tagEdgeBranch: string;
|
tagEdgeBranch: string;
|
||||||
tagMatch: string;
|
tagMatch: string;
|
||||||
|
tagMatchGroup: number;
|
||||||
tagMatchLatest: boolean;
|
tagMatchLatest: boolean;
|
||||||
tagSchedule: string;
|
tagSchedule: string;
|
||||||
sepTags: string;
|
sepTags: string;
|
||||||
@ -20,6 +21,7 @@ export function getInputs(): Inputs {
|
|||||||
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
|
||||||
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
tagEdgeBranch: core.getInput('tag-edge-branch'),
|
||||||
tagMatch: core.getInput('tag-match'),
|
tagMatch: core.getInput('tag-match'),
|
||||||
|
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
||||||
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
|
tagMatchLatest: /true/i.test(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`,
|
||||||
|
10
src/meta.ts
10
src/meta.ts
@ -41,9 +41,15 @@ export class Meta {
|
|||||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||||
version.version = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
version.version = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||||
if (this.inputs.tagMatch) {
|
if (this.inputs.tagMatch) {
|
||||||
const tagMatch = version.version.match(this.inputs.tagMatch);
|
let tagMatch;
|
||||||
|
const isRegEx = this.inputs.tagMatch.match(/^\/(.+)\/(.*)$/);
|
||||||
|
if (isRegEx) {
|
||||||
|
tagMatch = version.version.match(new RegExp(isRegEx[1], isRegEx[2]));
|
||||||
|
} else {
|
||||||
|
tagMatch = version.version.match(this.inputs.tagMatch);
|
||||||
|
}
|
||||||
if (tagMatch) {
|
if (tagMatch) {
|
||||||
version.version = tagMatch[0];
|
version.version = tagMatch[this.inputs.tagMatchGroup];
|
||||||
version.latest = this.inputs.tagMatchLatest;
|
version.latest = this.inputs.tagMatchLatest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user