Repository: crazy-max/ghaction-docker-meta
Pull request #5 (2020-10-28 17:19:29)

Generate latest tag by default on push tag event

codecov[bot]: # [Codecov](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=h1) Report
> Merging [#5](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=desc) into [master](https://codecov.io/gh/crazy-max/ghaction-docker-meta/commit/4a3b775794441fc7e170d0c1f35298f4a8f94423?el=desc) will **increase** coverage by `0.44%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5/graphs/tree.svg?width=650&height=150&src=pr&token=NgkCTCjmB1)](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master       #5      +/-   ##
==========================================
+ Coverage   70.76%   71.21%   +0.44%     
==========================================
  Files           3        3              
  Lines          65       66       +1     
  Branches       14       14              
==========================================
+ Hits           46       47       +1     
  Misses          6        6              
  Partials       13       13              
```


| [Impacted Files](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/meta.ts](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5/diff?src=pr&el=tree#diff-c3JjL21ldGEudHM=) | `72.72% <100.00%> (+0.63%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=footer). Last update [5ecce77...b647ca1](https://codecov.io/gh/crazy-max/ghaction-docker-meta/pull/5?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index f50abcf..4238e53 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,7 @@ ___
   * [inputs](#inputs)
   * [outputs](#outputs)
 * [Notes](#notes)
+  * [Latest tag](#latest-tag)
   * [`tag-match` examples](#tag-match-examples)
   * [Schedule tag](#schedule-tag)
   * [Overwrite labels](#overwrite-labels)
@@ -42,10 +43,9 @@ ___
 |-----------------|-------------------------------|------------|-------------------------------------|
 | `schedule`      | `refs/heads/master`           | `45f132a`  | `sha-45f132a`, `nightly`            |
 | `pull_request`  | `refs/pull/2/merge`           | `a123b57`  | `sha-a123b57`, `pr-2`               |
-| `push`          | `refs/heads/<default_branch>` | `676cae2`  | `sha-676cae2`, `edge`               |
-| `push`          | `refs/heads/dev`              | `cf20257`  | `sha-cf20257`, `dev`                |
+| `push`          | `refs/heads/master`           | `cf20257`  | `sha-cf20257`, `master`             |
 | `push`          | `refs/heads/my/branch`        | `a5df687`  | `sha-a5df687`, `my-branch`          |
-| `push tag`      | `refs/tags/v1.2.3`            | `bf4565b`  | `sha-bf4565b`, `1.2.3`, `latest`    |
+| `push tag`      | `refs/tags/v1.2.3`            | `bf4565b`  | `sha-bf4565b`, `v1.2.3`, `latest`   |
 | `push tag`      | `refs/tags/mytag`             | `afb7833`  | `sha-afb7833`, `mytag`              |
 
 ## Usage
@@ -76,10 +76,6 @@ jobs:
         uses: crazy-max/ghaction-docker-meta@v1
         with:
           images: name/app
-          tag-sha: true
-          tag-edge: true
-          tag-match: 'v(.*)'
-          tag-match-group: '1'
       -
         name: Set up QEMU
         uses: docker/setup-qemu-action@v1
@@ -138,6 +134,12 @@ Following outputs are available
 
 ## Notes
 
+### Latest tag
+
+Latest Docker tag will be generated by default on `push tag` event. So if for example you push the `v1.2.3` Git tag,
+you will have at the output of this action the Docker tags `v1.2.3` and `latest`. But you can allow the latest tag to be
+generated only if the Git tag matches a regular expression with the [`tag-match` input](#tag-match-examples).
+
 ### `tag-match` examples
 
 | Git tag                 | `tag-match`                        | `tag-match-group` | Docker tag
diff --git a/dist/index.js b/dist/index.js
index 116eabf..1706fc8 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -208,6 +208,9 @@ class Meta {
                     version.latest = this.inputs.tagMatchLatest;
                 }
             }
+            else {
+                version.latest = true;
+            }
         }
         else if (/^refs\/heads\//.test(this.context.ref)) {
             version.version = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
diff --git a/src/meta.ts b/src/meta.ts
index 8d85431..f580a61 100644
--- a/src/meta.ts
+++ b/src/meta.ts
@@ -52,6 +52,8 @@ export class Meta {
           version.version = tagMatch[this.inputs.tagMatchGroup];
           version.latest = this.inputs.tagMatchLatest;
         }
+      } else {
+        version.latest = true;
       }
     } else if (/^refs\/heads\//.test(this.context.ref)) {
       version.version = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');


Test patch:
diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts
index 3406388..27bb9db 100644
--- a/__tests__/meta.test.ts
+++ b/__tests__/meta.test.ts
@@ -377,10 +377,11 @@ describe('push tag', () => {
       } as Inputs,
       {
         version: 'release1',
-        latest: false
+        latest: true
       } as Version,
       [
-        'user/app:release1'
+        'user/app:release1',
+        'user/app:latest'
       ],
       [
         "org.opencontainers.image.title=Hello-World",
@@ -400,10 +401,11 @@ describe('push tag', () => {
       } as Inputs,
       {
         version: '20200110-RC2',
-        latest: false
+        latest: true
       } as Version,
       [
-        'user/app:20200110-RC2'
+        'user/app:20200110-RC2',
+        'user/app:latest'
       ],
       [
         "org.opencontainers.image.title=Hello-World",
@@ -686,11 +688,13 @@ describe('latest', () => {
       } as Inputs,
       {
         version: 'v1.1.1',
-        latest: false
+        latest: true
       } as Version,
       [
         'org/app:v1.1.1',
+        'org/app:latest',
         'ghcr.io/user/app:v1.1.1',
+        'ghcr.io/user/app:latest',
       ],
       [
         "org.opencontainers.image.title=Hello-World",
@@ -951,10 +955,11 @@ describe('release', () => {
       } as Inputs,
       {
         version: 'v1.1.1',
-        latest: false
+        latest: true
       } as Version,
       [
         'user/app:v1.1.1',
+        'user/app:latest',
       ],
       [
         "org.opencontainers.image.title=Hello-World",