Skip to content

Commit 904f9d7

Browse files
committed
Skip and display warning if tag does not match
1 parent e87dd94 commit 904f9d7

File tree

5 files changed

+140
-25
lines changed

5 files changed

+140
-25
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ a custom value through `value` attribute.
437437
| `v2.0.8-beta.67` | `v(.*)` | `1` | `2.0.8-beta.67` |
438438
| `v2.0.8-beta.67` | `v(\d.\d)` | `1` | `2.0` |
439439
| `20200110-RC2` | `\d+` | `0` | `20200110` |
440+
| `p1/v1.2.3` | `p1-v(\d.\d.\d)` | `1` | `1.2.3` |
440441

441442
Extended attributes and default values:
442443

@@ -470,11 +471,11 @@ tags: |
470471

471472
```yaml
472473
tags: |
473-
# minimal branch event
474+
# branch event
474475
type=ref,event=branch
475-
# minimal tag event
476+
# tag event
476477
type=ref,event=tag
477-
# minimal pull request event
478+
# pull request event
478479
type=ref,event=pr
479480
```
480481

@@ -495,11 +496,11 @@ Extended attributes and default values:
495496

496497
```yaml
497498
tags: |
498-
# event branch
499+
# branch event
499500
type=ref,enable=true,priority=600,prefix=,suffix=,event=
500-
# event tag
501+
# tag event
501502
type=ref,enable=true,priority=600,prefix=,suffix=,event=
502-
# event pr
503+
# pull request event
503504
type=ref,enable=true,priority=600,prefix=pr-,suffix=,event=
504505
```
505506

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
GITHUB_ACTION=crazy-maxghaction-dump-context
2+
GITHUB_ACTIONS=true
3+
GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1
4+
GITHUB_ACTOR=crazy-max
5+
GITHUB_API_URL=https://api.github.com
6+
GITHUB_BASE_REF=
7+
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_6ee180c2-b331-434a-a867-89534cbefd83
8+
GITHUB_EVENT_NAME=push
9+
#GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
10+
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
11+
GITHUB_HEAD_REF=
12+
GITHUB_JOB=event
13+
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_6ee180c2-b331-434a-a867-89534cbefd83
14+
GITHUB_REF=refs/tags/p1/v1.0.0
15+
GITHUB_REPOSITORY=crazy-max/test-docker-action
16+
GITHUB_REPOSITORY_OWNER=crazy-max
17+
GITHUB_RETENTION_DAYS=90
18+
GITHUB_RUN_ID=325968230
19+
GITHUB_RUN_NUMBER=4
20+
GITHUB_SERVER_URL=https://github.com
21+
GITHUB_SHA=90dd6032fac8bda1b6c4436a2e65de27961ed071
22+
GITHUB_WORKFLOW=event
23+
GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action

__tests__/meta.test.ts

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -837,24 +837,29 @@ describe('tag', () => {
837837
{
838838
images: ['org/app', 'ghcr.io/user/app'],
839839
tags: [
840-
`type=match,"pattern=/^v(\\d.\\d.\\d)$/ig",group=1`,
840+
`type=match,"pattern=v(.*)-beta.(.*)",group=1`,
841+
`type=match,"pattern=v(.*)-beta.(.*)",group=2`,
841842
]
842843
} as Inputs,
843844
{
844-
main: 'v2.0.8-beta.67',
845-
partial: [],
846-
latest: false
845+
main: '2.0.8',
846+
partial: ['67'],
847+
latest: true
847848
} as Version,
848849
[
849-
'org/app:v2.0.8-beta.67',
850-
'ghcr.io/user/app:v2.0.8-beta.67'
850+
'org/app:2.0.8',
851+
'org/app:67',
852+
'org/app:latest',
853+
'ghcr.io/user/app:2.0.8',
854+
'ghcr.io/user/app:67',
855+
'ghcr.io/user/app:latest'
851856
],
852857
[
853858
"org.opencontainers.image.title=Hello-World",
854859
"org.opencontainers.image.description=This your first repo!",
855860
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
856861
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
857-
"org.opencontainers.image.version=v2.0.8-beta.67",
862+
"org.opencontainers.image.version=2.0.8",
858863
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
859864
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
860865
"org.opencontainers.image.licenses=MIT"
@@ -870,20 +875,17 @@ describe('tag', () => {
870875
]
871876
} as Inputs,
872877
{
873-
main: 'sometag',
878+
main: undefined,
874879
partial: [],
875880
latest: false
876881
} as Version,
877-
[
878-
'org/app:sometag',
879-
'ghcr.io/user/app:sometag'
880-
],
882+
[],
881883
[
882884
"org.opencontainers.image.title=Hello-World",
883885
"org.opencontainers.image.description=This your first repo!",
884886
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
885887
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
886-
"org.opencontainers.image.version=sometag",
888+
"org.opencontainers.image.version=",
887889
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
888890
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
889891
"org.opencontainers.image.licenses=MIT"
@@ -1089,6 +1091,82 @@ describe('tag', () => {
10891091
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
10901092
"org.opencontainers.image.licenses=MIT"
10911093
]
1094+
],
1095+
[
1096+
'tag17',
1097+
'event_tag_p1-v1.0.0.env',
1098+
{
1099+
images: ['org/app', 'ghcr.io/user/app'],
1100+
tags: [
1101+
`type=match,pattern=\\d.\\d.\\d`,
1102+
`type=match,pattern=\\d.\\d`,
1103+
`type=ref,event=pr`,
1104+
`type=sha`
1105+
]
1106+
} as Inputs,
1107+
{
1108+
main: '1.0.0',
1109+
partial: ['1.0', 'sha-90dd603'],
1110+
latest: true
1111+
} as Version,
1112+
[
1113+
'org/app:1.0.0',
1114+
'org/app:1.0',
1115+
'org/app:sha-90dd603',
1116+
'org/app:latest',
1117+
'ghcr.io/user/app:1.0.0',
1118+
'ghcr.io/user/app:1.0',
1119+
'ghcr.io/user/app:sha-90dd603',
1120+
'ghcr.io/user/app:latest'
1121+
],
1122+
[
1123+
"org.opencontainers.image.title=Hello-World",
1124+
"org.opencontainers.image.description=This your first repo!",
1125+
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
1126+
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
1127+
"org.opencontainers.image.version=1.0.0",
1128+
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
1129+
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
1130+
"org.opencontainers.image.licenses=MIT"
1131+
]
1132+
],
1133+
[
1134+
'tag18',
1135+
'event_tag_p1-v1.0.0.env',
1136+
{
1137+
images: ['org/app', 'ghcr.io/user/app'],
1138+
tags: [
1139+
`type=match,pattern=p1-v(\\d.\\d.\\d),group=1`,
1140+
`type=match,pattern=p1-v(\\d.\\d),group=1`,
1141+
`type=ref,event=pr`,
1142+
`type=sha`
1143+
]
1144+
} as Inputs,
1145+
{
1146+
main: '1.0.0',
1147+
partial: ['1.0', 'sha-90dd603'],
1148+
latest: true
1149+
} as Version,
1150+
[
1151+
'org/app:1.0.0',
1152+
'org/app:1.0',
1153+
'org/app:sha-90dd603',
1154+
'org/app:latest',
1155+
'ghcr.io/user/app:1.0.0',
1156+
'ghcr.io/user/app:1.0',
1157+
'ghcr.io/user/app:sha-90dd603',
1158+
'ghcr.io/user/app:latest'
1159+
],
1160+
[
1161+
"org.opencontainers.image.title=Hello-World",
1162+
"org.opencontainers.image.description=This your first repo!",
1163+
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
1164+
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
1165+
"org.opencontainers.image.version=1.0.0",
1166+
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
1167+
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
1168+
"org.opencontainers.image.licenses=MIT"
1169+
]
10921170
]
10931171
])('given %p with %p event', tagsLabelsTest);
10941172
});

dist/index.js

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/meta.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,17 @@ export class Meta {
180180
} else {
181181
tmatch = vraw.match(tag.attrs['pattern']);
182182
}
183-
if (tmatch) {
184-
vraw = tmatch[tag.attrs['group']];
185-
latest = true;
183+
if (!tmatch) {
184+
core.warning(`${tag.attrs['pattern']} does not match ${vraw}.`);
185+
return version;
186186
}
187+
if (typeof tmatch[tag.attrs['group']] === 'undefined') {
188+
core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
189+
return version;
190+
}
191+
192+
vraw = tmatch[tag.attrs['group']];
193+
latest = true;
187194

188195
if (version.main == undefined) {
189196
version.main = vraw;

0 commit comments

Comments
 (0)