Skip and display warning if tag does not match (#59)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-04-05 21:19:05 +02:00 committed by GitHub
parent e87dd9466c
commit 36ae18e02c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 142 additions and 25 deletions

View file

@ -437,6 +437,7 @@ a custom value through `value` attribute.
| `v2.0.8-beta.67` | `v(.*)` | `1` | `2.0.8-beta.67` |
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | `2.0` |
| `20200110-RC2` | `\d+` | `0` | `20200110` |
| `p1/v1.2.3` | `p1-v(\d.\d.\d)` | `1` | `1.2.3` |
Extended attributes and default values:
@ -470,11 +471,11 @@ tags: |
```yaml
tags: |
# minimal branch event
# branch event
type=ref,event=branch
# minimal tag event
# tag event
type=ref,event=tag
# minimal pull request event
# pull request event
type=ref,event=pr
```
@ -495,11 +496,11 @@ Extended attributes and default values:
```yaml
tags: |
# event branch
# branch event
type=ref,enable=true,priority=600,prefix=,suffix=,event=
# event tag
# tag event
type=ref,enable=true,priority=600,prefix=,suffix=,event=
# event pr
# pull request event
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=
```

View file

@ -0,0 +1,23 @@
GITHUB_ACTION=crazy-maxghaction-dump-context
GITHUB_ACTIONS=true
GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1
GITHUB_ACTOR=crazy-max
GITHUB_API_URL=https://api.github.com
GITHUB_BASE_REF=
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_6ee180c2-b331-434a-a867-89534cbefd83
GITHUB_EVENT_NAME=push
#GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
GITHUB_HEAD_REF=
GITHUB_JOB=event
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_6ee180c2-b331-434a-a867-89534cbefd83
GITHUB_REF=refs/tags/p1/v1.0.0
GITHUB_REPOSITORY=crazy-max/test-docker-action
GITHUB_REPOSITORY_OWNER=crazy-max
GITHUB_RETENTION_DAYS=90
GITHUB_RUN_ID=325968230
GITHUB_RUN_NUMBER=4
GITHUB_SERVER_URL=https://github.com
GITHUB_SHA=90dd6032fac8bda1b6c4436a2e65de27961ed071
GITHUB_WORKFLOW=event
GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action

View file

@ -837,24 +837,29 @@ describe('tag', () => {
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=/^v(\\d.\\d.\\d)$/ig",group=1`,
`type=match,"pattern=v(.*)-beta.(.*)",group=1`,
`type=match,"pattern=v(.*)-beta.(.*)",group=2`,
]
} as Inputs,
{
main: 'v2.0.8-beta.67',
partial: [],
latest: false
main: '2.0.8',
partial: ['67'],
latest: true
} as Version,
[
'org/app:v2.0.8-beta.67',
'ghcr.io/user/app:v2.0.8-beta.67'
'org/app:2.0.8',
'org/app:67',
'org/app:latest',
'ghcr.io/user/app:2.0.8',
'ghcr.io/user/app:67',
'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",
"org.opencontainers.image.version=v2.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"
@ -870,20 +875,17 @@ describe('tag', () => {
]
} as Inputs,
{
main: 'sometag',
main: undefined,
partial: [],
latest: false
} as Version,
[
'org/app:sometag',
'ghcr.io/user/app:sometag'
],
[],
[
"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",
"org.opencontainers.image.version=sometag",
"org.opencontainers.image.version=",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
@ -1089,6 +1091,84 @@ describe('tag', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag17',
'event_tag_p1-v1.0.0.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,"pattern=/^v(\\d.\\d.\\d)$/ig",group=1`,
`type=match,pattern=\\d.\\d.\\d`,
`type=match,pattern=\\d.\\d`,
`type=ref,event=pr`,
`type=sha`
]
} as Inputs,
{
main: '1.0.0',
partial: ['1.0', 'sha-90dd603'],
latest: true
} as Version,
[
'org/app:1.0.0',
'org/app:1.0',
'org/app:sha-90dd603',
'org/app:latest',
'ghcr.io/user/app:1.0.0',
'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-90dd603',
'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",
"org.opencontainers.image.version=1.0.0",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag18',
'event_tag_p1-v1.0.0.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=match,pattern=p1-v(\\d.\\d.\\d),group=1`,
`type=match,pattern=p1-v(\\d.\\d),group=1`,
`type=match,pattern=p1-v(\\d.\\d),group=3`,
`type=ref,event=pr`,
`type=sha`
]
} as Inputs,
{
main: '1.0.0',
partial: ['1.0', 'sha-90dd603'],
latest: true
} as Version,
[
'org/app:1.0.0',
'org/app:1.0',
'org/app:sha-90dd603',
'org/app:latest',
'ghcr.io/user/app:1.0.0',
'ghcr.io/user/app:1.0',
'ghcr.io/user/app:sha-90dd603',
'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",
"org.opencontainers.image.version=1.0.0",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest);
});

10
dist/index.js generated vendored
View file

@ -518,10 +518,16 @@ class Meta {
else {
tmatch = vraw.match(tag.attrs['pattern']);
}
if (tmatch) {
if (!tmatch) {
core.warning(`${tag.attrs['pattern']} does not match ${vraw}.`);
return version;
}
if (typeof tmatch[tag.attrs['group']] === 'undefined') {
core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
return version;
}
vraw = tmatch[tag.attrs['group']];
latest = true;
}
if (version.main == undefined) {
version.main = vraw;
}

View file

@ -180,10 +180,17 @@ export class Meta {
} else {
tmatch = vraw.match(tag.attrs['pattern']);
}
if (tmatch) {
if (!tmatch) {
core.warning(`${tag.attrs['pattern']} does not match ${vraw}.`);
return version;
}
if (typeof tmatch[tag.attrs['group']] === 'undefined') {
core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
return version;
}
vraw = tmatch[tag.attrs['group']];
latest = true;
}
if (version.main == undefined) {
version.main = vraw;