Repository: crazy-max/ghaction-docker-meta (ts)

Issue:
Tag chaining with match and semver
### Behaviour

My context is kind of mono repository that each project has itself life-cycle.
Currently, I separate GitHub release tag as: `project/semver`

#### Steps to reproduce this issue

1. Input

```bash
# Ref context
refs/tags/project1/v1.0.0
# GH docker meta
tags: type=ref,event=branch
  type=ref,event=tag
  type=ref,event=pr
  type=sha
  type=match,pattern=project1\/v(.*),group=1
```
2. Output
```
project1-v1.0.0
```

It should be `1.0.0` ???

#### Expected behaviour

I'm wondering how to make tag chaining from `match` to `semver`. I have not yet understand prefix/suffix/value for what purpose.
In my case: I expect tag output is
- `1.0.0`
- `1.0`
- `latest`

Another thing, typo in https://github.com/crazy-max/ghaction-docker-meta#typematch
```
tags: |
  type=group,enable=true,priority=800,prefix=,suffix=,pattern=,group=0,value=
```
Should be `type=match`?

Pull request:
Skip and display warning if tag does not match
Closes #56

Patch:
diff --git a/README.md b/README.md
index ac24ab0..6395410 100644
--- a/README.md
+++ b/README.md
@@ -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=
 ```
 
diff --git a/dist/index.js b/dist/index.js
index e6f99e7..f6bc0ac 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -518,10 +518,16 @@ 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;
         }
diff --git a/src/meta.ts b/src/meta.ts
index d6e9268..8a2189e 100644
--- a/src/meta.ts
+++ b/src/meta.ts
@@ -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;


Test patch:
diff --git a/__tests__/fixtures/event_tag_p1-v1.0.0.env b/__tests__/fixtures/event_tag_p1-v1.0.0.env
new file mode 100644
index 0000000..a28dfa3
--- /dev/null
+++ b/__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
diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts
index 274613a..4428db2 100644
--- a/__tests__/meta.test.ts
+++ b/__tests__/meta.test.ts
@@ -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);
 });