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

Issue:
prefix/suffix not working?
### Behaviour

I am unable to add a prefix or suffix in v2 of this action, regardless if specified in the flavor or in the tag attributes.

#### Steps to reproduce this issue

1. Specify `suffix=-dev` in flavor or individual tag
2. Run action
3. Suffix is not applied

#### Expected behaviour

The action should append the suffix to the tag

#### Actual behaviour

The suffix is not appended

### Configuration

* Repository URL (if public): https://github.com/strophy/js-drive
* Build URL (if public): https://github.com/strophy/js-drive/runs/2288637313

```yml
- name: Set -dev suffix
  id: release_type
  run: |
    if [[ ${{ contains(github.event.release.tag_name, '-dev') }} = true ]]
    then
      echo '::set-output name=dev-suffix::-dev'
    else
      echo '::set-output name=dev-suffix::'
    fi

- name: Docker meta
  id: docker_meta
  uses: crazy-max/ghaction-docker-meta@v2
  with:
    images: strophy/drive
    tags: |
      type=match,pattern=v(\d+),group=1
      type=match,pattern=v(\d+.\d+),group=1
      type=match,pattern=v(\d+.\d+.\d+),group=1
      type=match,pattern=v(.*),group=1,suffix=,enable=${{ contains(github.event.release.tag_name, '-dev') }}
    flavor: |
      latest=${{ !contains(github.event.release.tag_name, '-dev') }}
      suffix=${{ steps.release_type.outputs.dev-suffix }}
```

### Logs
[logs_396.zip](https://github.com/crazy-max/ghaction-docker-meta/files/6272603/logs_396.zip)



Pull request:
Prefix/suffix not taken into account
Fixes #61 

cc. @strophy

Patch:
diff --git a/dist/index.js b/dist/index.js
index f6bc0ac..da2f1b0 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -439,11 +439,11 @@ class Meta {
             return version;
         }
         const currentDate = this.date;
-        const vraw = handlebars.compile(tag.attrs['pattern'])({
+        const vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])({
             date: function (format) {
                 return moment_1.default(currentDate).utc().format(format);
             }
-        });
+        }), tag);
         if (version.main == undefined) {
             version.main = vraw;
         }
@@ -475,24 +475,18 @@ class Meta {
             includePrerelease: true
         });
         if (semver.prerelease(vraw)) {
-            vraw = handlebars.compile('{{version}}')(sver);
-            if (version.main == undefined) {
-                version.main = vraw;
-            }
-            else if (vraw !== version.main) {
-                version.partial.push(vraw);
-            }
+            vraw = this.setFlavor(handlebars.compile('{{version}}')(sver), tag);
         }
         else {
-            vraw = handlebars.compile(tag.attrs['pattern'])(sver);
-            if (version.main == undefined) {
-                version.main = vraw;
-            }
-            else if (vraw !== version.main) {
-                version.partial.push(vraw);
-            }
+            vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])(sver), tag);
             latest = true;
         }
+        if (version.main == undefined) {
+            version.main = vraw;
+        }
+        else if (vraw !== version.main) {
+            version.partial.push(vraw);
+        }
         if (version.latest == undefined) {
             version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
         }
@@ -526,7 +520,7 @@ class Meta {
             core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
             return version;
         }
-        vraw = tmatch[tag.attrs['group']];
+        vraw = this.setFlavor(tmatch[tag.attrs['group']], tag);
         latest = true;
         if (version.main == undefined) {
             version.main = vraw;
diff --git a/src/meta.ts b/src/meta.ts
index 8a2189e..ca6b633 100644
--- a/src/meta.ts
+++ b/src/meta.ts
@@ -99,11 +99,14 @@ export class Meta {
     }
 
     const currentDate = this.date;
-    const vraw = handlebars.compile(tag.attrs['pattern'])({
-      date: function (format) {
-        return moment(currentDate).utc().format(format);
-      }
-    });
+    const vraw = this.setFlavor(
+      handlebars.compile(tag.attrs['pattern'])({
+        date: function (format) {
+          return moment(currentDate).utc().format(format);
+        }
+      }),
+      tag
+    );
 
     if (version.main == undefined) {
       version.main = vraw;
@@ -138,21 +141,16 @@ export class Meta {
       includePrerelease: true
     });
     if (semver.prerelease(vraw)) {
-      vraw = handlebars.compile('{{version}}')(sver);
-      if (version.main == undefined) {
-        version.main = vraw;
-      } else if (vraw !== version.main) {
-        version.partial.push(vraw);
-      }
+      vraw = this.setFlavor(handlebars.compile('{{version}}')(sver), tag);
     } else {
-      vraw = handlebars.compile(tag.attrs['pattern'])(sver);
-      if (version.main == undefined) {
-        version.main = vraw;
-      } else if (vraw !== version.main) {
-        version.partial.push(vraw);
-      }
+      vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])(sver), tag);
       latest = true;
     }
+    if (version.main == undefined) {
+      version.main = vraw;
+    } else if (vraw !== version.main) {
+      version.partial.push(vraw);
+    }
     if (version.latest == undefined) {
       version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
     }
@@ -189,7 +187,7 @@ export class Meta {
       return version;
     }
 
-    vraw = tmatch[tag.attrs['group']];
+    vraw = this.setFlavor(tmatch[tag.attrs['group']], tag);
     latest = true;
 
     if (version.main == undefined) {


Test patch:
diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts
index 4428db2..2439173 100644
--- a/__tests__/meta.test.ts
+++ b/__tests__/meta.test.ts
@@ -1578,6 +1578,72 @@ describe('pr', () => {
         "org.opencontainers.image.licenses=MIT"
       ]
     ],
+    [
+      'pr05',
+      'event_pull_request.env',
+      {
+        images: ['org/app', 'ghcr.io/user/app'],
+        tags: [
+          `type=ref,event=pr`
+        ],
+        flavor: [
+          `prefix=glo-`,
+          `suffix=-bal`
+        ]
+      } as Inputs,
+      {
+        main: 'pr-2-bal',
+        partial: [],
+        latest: false
+      } as Version,
+      [
+        'org/app:pr-2-bal',
+        'ghcr.io/user/app:pr-2-bal'
+      ],
+      [
+        "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=pr-2-bal",
+        "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
+        "org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
+        "org.opencontainers.image.licenses=MIT"
+      ]
+    ],
+    [
+      'pr06',
+      'event_pull_request.env',
+      {
+        images: ['org/app', 'ghcr.io/user/app'],
+        tags: [
+          `type=ref,event=pr,prefix=`
+        ],
+        flavor: [
+          `prefix=glo-`,
+          `suffix=-bal`
+        ]
+      } as Inputs,
+      {
+        main: 'glo-2-bal',
+        partial: [],
+        latest: false
+      } as Version,
+      [
+        'org/app:glo-2-bal',
+        'ghcr.io/user/app:glo-2-bal'
+      ],
+      [
+        "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=glo-2-bal",
+        "org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
+        "org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504",
+        "org.opencontainers.image.licenses=MIT"
+      ]
+    ]
   ])('given %p with %p event', tagsLabelsTest);
 });
 
@@ -1758,6 +1824,39 @@ describe('schedule', () => {
         "org.opencontainers.image.licenses=MIT"
       ]
     ],
+    [
+      'schedule07',
+      'event_schedule.env',
+      {
+        images: ['org/app', 'ghcr.io/user/app'],
+        tags: [
+          `type=schedule`,
+        ],
+        flavor: [
+          `prefix=glo-`,
+          `suffix=-bal`
+        ]
+      } as Inputs,
+      {
+        main: 'glo-nightly-bal',
+        partial: [],
+        latest: false
+      } as Version,
+      [
+        'org/app:glo-nightly-bal',
+        'ghcr.io/user/app:glo-nightly-bal'
+      ],
+      [
+        "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=glo-nightly-bal",
+        "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);
 });