Skip to content

Commit

Permalink
Skip and display warning if tag does not match (#59)
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 committed Apr 5, 2021
1 parent e87dd94 commit 36ae18e
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 25 deletions.
13 changes: 7 additions & 6 deletions README.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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
```
Expand All @@ -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=
```
Expand Down
23 changes: 23 additions & 0 deletions __tests__/fixtures/event_tag_p1-v1.0.0.env
@@ -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
106 changes: 93 additions & 13 deletions __tests__/meta.test.ts
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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);
});
Expand Down
12 changes: 9 additions & 3 deletions dist/index.js

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

13 changes: 10 additions & 3 deletions src/meta.ts
Expand Up @@ -180,10 +180,17 @@ export class Meta {
} else {
tmatch = vraw.match(tag.attrs['pattern']);
}
if (tmatch) {
vraw = tmatch[tag.attrs['group']];
latest = true;
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;
Expand Down

0 comments on commit 36ae18e

Please sign in to comment.