Compare commits

..

8 Commits

Author SHA1 Message Date
CrazyMax
a207508e20 Update CHANGELOG 2020-10-27 00:59:19 +01:00
CrazyMax
983124bca8 Use RegExp to match against a Git tag instead of coerce 2020-10-27 00:57:32 +01:00
CrazyMax
4a3aaf409c Update README 2020-10-26 17:58:13 +01:00
CrazyMax
0c4748bf65 Update cron 2020-10-26 17:54:22 +01:00
CrazyMax
ffb794a3fd Update CHANGELOG 2020-10-26 17:53:34 +01:00
CrazyMax
0dac4059e9 Set latest tag only if matches with a pattern 2020-10-26 17:51:00 +01:00
dependabot[bot]
4d7603f754 Bump codecov/codecov-action from v1.0.13 to v1.0.14 (#4)
Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from v1.0.13 to v1.0.14.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Commits](https://github.com/codecov/codecov-action/compare/v1.0.13...7d5dfa54903bd909319c580a00535b483d1efcf3)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-26 11:37:33 +00:00
CrazyMax
06c67913f5 Update README 2020-10-26 01:51:56 +01:00
10 changed files with 229 additions and 2294 deletions

View File

@@ -2,7 +2,7 @@ name: ci
on:
schedule:
- cron: '0 * * * *' # every hours
- cron: '0 */4 * * *' # every 4 hours
push:
branches:
- '**'

View File

@@ -39,7 +39,7 @@ jobs:
run: yarn run test
-
name: Upload coverage
uses: codecov/codecov-action@v1.0.13
uses: codecov/codecov-action@v1.0.14
if: success()
with:
token: ${{ secrets.CODECOV_TOKEN }}

View File

@@ -1,5 +1,13 @@
# Changelog
## 1.4.0 (2020/10/27)
* Use RegExp to match against a Git tag instead of coerce
## 1.3.0 (2020/10/26)
* Set latest tag only if matches with a pattern
## 1.2.0 (2020/10/26)
* Coerces Git tag to semver (#3)

View File

@@ -23,9 +23,8 @@ ___
* [inputs](#inputs)
* [outputs](#outputs)
* [Notes](#notes)
* [Latest tag](#latest-tag)
* [Coerces Git tag](#coerces-git-tag)
* [Templates available for schedule tag](#templates-available-for-schedule-tag)
* [`tag-match` examples](#tag-match-examples)
* [Schedule tag](#schedule-tag)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [How can I help?](#how-can-i-help)
* [License](#license)
@@ -39,8 +38,8 @@ ___
## Overview
| Event | Ref | Commit SHA | Docker Tags |
|-----------------|-------------------------------|------------|------------------------------------|
| `schedule` | | `45f132a` | `sha-45f132a`, `nightly` |
|-----------------|-------------------------------|------------|-------------------------------------|
| `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` |
@@ -75,10 +74,9 @@ jobs:
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: |
name/app
ghcr.io/name/app
images: name/app
tag-sha: true
tag-match: \\d{1,3}.\\d{1,3}.\\d{1,3}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
@@ -116,8 +114,9 @@ Following inputs can be used as `step.with` keys
| `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) |
| `tag-edge` | Bool | Enable edge branch tagging (default `false`) |
| `tag-edge-branch` | String | Branch that will be tagged as edge (default `repo.default_branch`) |
| `tag-coerce-tag` | String | Coerces Git tag to semver if possible using [Handlebars template](https://handlebarsjs.com/guide/) |
| `tag-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) |
| `tag-match` | String | RegExp to match against a Git tag and use match group as Docker tag |
| `tag-match-latest` | Bool | Set `latest` Docker tag if `tag-match` matches (default `true`) |
| `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) |
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
@@ -135,28 +134,17 @@ Following outputs are available
## Notes
### Latest tag
### `tag-match` examples
`latest` tag is created only on `push tag` event and resolves one of the following conditions:
| Git tag | `tag-match` | Docker tag
|-------------------------|--------------------------------|-------------------|
| `v1.2.3` | `\\d{1,3}.\\d{1,3}.\\d{1,3}` | `1.2.3` |
| `v2.0.8-beta.67` | `\\d{1,3}.\\d{1,3}.\\d{1,3}.*` | `2.0.8-beta.67` |
| `v2.0.8-beta.67` | `\\d{1,3}.\\d{1,3}` | `2.0` |
| `release1` | `\\d{1,3}.\\d{1,3}` | `release1` |
| `20200110-RC2` | `\\d+` | `20200110` |
* Git tag is a valid [semver](https://semver.org/)
* Provided `tag-coerce-tag` is valid
### Coerces Git tag
Provides a very forgiving translation of a non-semver tag to semver. For more information see
[Coercion section](https://www.npmjs.com/package/semver#coercion). `tag-coerce-tag` supports
[Handlebars template](https://handlebarsjs.com/guide/) with the following inputs:
| `tag-coerce-tag` | Git tag | Version |
|-------------------------|----------|---------|
| `{{raw}}` | `v1.2.3` | `1.2.3` |
| `{{major}}.{{minor}}` | `v1.2.3` | `1.2` |
| `{{major}}` | `v1.2.3` | `1` |
| `{{minor}}` | `v1.2.3` | `2` |
| `{{patch}}` | `v1.2.3` | `3` |
### Templates available for schedule tag
### Schedule tag
`tag-schedule` is specially crafted input to support [Handlebars template](https://handlebarsjs.com/guide/) with
the following expressions:

View File

@@ -420,15 +420,15 @@ describe('push tag', () => {
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagCoerceTag: '{{major}}',
tagMatch: `\\d{8}`,
tagMatchLatest: false,
} as Inputs,
{
version: '20200110',
latest: true
latest: false
} as Version,
[
'user/app:20200110',
'user/app:latest'
'user/app:20200110'
],
[
"org.opencontainers.image.title=Hello-World",
@@ -441,34 +441,11 @@ describe('push tag', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['user/app'],
} as Inputs,
{
version: '1.1.1',
latest: true
} as Version,
[
'user/app:1.1.1',
'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.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '1.1.1',
@@ -491,39 +468,11 @@ describe('push tag', () => {
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagSha: true,
} as Inputs,
{
version: '1.1.1',
latest: true
} as Version,
[
'org/app:1.1.1',
'org/app:latest',
'org/app:sha-90dd603',
'ghcr.io/user/app:1.1.1',
'ghcr.io/user/app:latest',
'ghcr.io/user/app:sha-90dd603'
],
[
"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.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v2.0.8-beta.67.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}-(alpha|beta).\\d{1,3}`,
} as Inputs,
{
version: '2.0.8-beta.67',
@@ -550,7 +499,7 @@ describe('push tag', () => {
'event_tag_v2.0.8-beta.67.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagCoerceTag: '{{major}}.{{minor}}',
tagMatch: `\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '2.0',
@@ -577,7 +526,7 @@ describe('push tag', () => {
'event_tag_sometag.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagCoerceTag: '{{major}}.{{minor}}',
tagMatch: `\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: 'sometag',
@@ -601,6 +550,163 @@ describe('push tag', () => {
])('given %p event ', tagsLabelsTest);
});
describe('latest', () => {
// prettier-ignore
test.each([
[
'event_tag_release1.env',
{
images: ['user/app'],
tagMatch: `^release\\d{1,2}`,
} as Inputs,
{
version: 'release1',
latest: true,
} as Version,
[
'user/app:release1',
'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.git",
"org.opencontainers.image.version=release1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagMatch: `^\\d+-RC\\d{1,2}`,
} as Inputs,
{
version: '20200110-RC2',
latest: true
} as Version,
[
'user/app:20200110-RC2',
'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.git",
"org.opencontainers.image.version=20200110-RC2",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_20200110-RC2.env',
{
images: ['user/app'],
tagMatch: `\\d{8}`,
} as Inputs,
{
version: '20200110',
latest: true
} as Version,
[
'user/app:20200110',
'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.git",
"org.opencontainers.image.version=20200110",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['user/app'],
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '1.1.1',
latest: true
} as Version,
[
'user/app:1.1.1',
'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.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
} as Inputs,
{
version: 'v1.1.1',
latest: false
} as Version,
[
'org/app:v1.1.1',
'ghcr.io/user/app:v1.1.1',
],
[
"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.git",
"org.opencontainers.image.version=v1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'event_tag_v2.0.8-beta.67.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tagMatch: `\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '2.0.8',
latest: true
} as Version,
[
'org/app:2.0.8',
'org/app:latest',
'ghcr.io/user/app:2.0.8',
'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.git",
"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"
]
],
])('given %p event ', tagsLabelsTest);
});
describe('pull_request', () => {
// prettier-ignore
test.each([
@@ -818,19 +924,18 @@ describe('release', () => {
images: ['user/app'],
} as Inputs,
{
version: '1.1.1',
latest: true
version: 'v1.1.1',
latest: false
} as Version,
[
'user/app:1.1.1',
'user/app:latest'
'user/app:v1.1.1',
],
[
"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.git",
"org.opencontainers.image.version=1.1.1",
"org.opencontainers.image.version=v1.1.1",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"

View File

@@ -21,11 +21,15 @@ inputs:
tag-edge-branch:
description: 'Branch that will be tagged as edge (default repo.default_branch)'
required: false
tag-coerce-tag:
description: 'Coerces Git tag to semver if possible using Handlebars template'
tag-match:
description: 'RegExp to match against a Git tag and use match group as Docker tag'
required: false
tag-match-latest:
description: 'Set latest Docker tag if tag-match matches'
default: 'true'
required: false
tag-schedule:
description: 'Handlebars template to apply to schedule tag'
description: 'Template to apply to schedule tag'
default: 'nightly'
required: false
sep-tags:

2175
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@@ -26,8 +26,7 @@
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"handlebars": "^4.7.6",
"moment": "^2.29.1",
"semver": "^7.3.2"
"moment": "^2.29.1"
},
"devDependencies": {
"@types/jest": "^26.0.0",

View File

@@ -5,7 +5,8 @@ export interface Inputs {
tagSha: boolean;
tagEdge: boolean;
tagEdgeBranch: string;
tagCoerceTag: string;
tagMatch: string;
tagMatchLatest: boolean;
tagSchedule: string;
sepTags: string;
sepLabels: string;
@@ -18,7 +19,8 @@ export function getInputs(): Inputs {
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
tagEdgeBranch: core.getInput('tag-edge-branch'),
tagCoerceTag: core.getInput('tag-coerce-tag'),
tagMatch: core.getInput('tag-match'),
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
tagSchedule: core.getInput('tag-schedule') || 'nightly',
sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`,

View File

@@ -1,6 +1,5 @@
import * as handlebars from 'handlebars';
import * as moment from 'moment';
import * as semver from 'semver';
import {Inputs} from './context';
import {Context} from '@actions/github/lib/context';
import {ReposGetResponseData} from '@octokit/types';
@@ -40,24 +39,13 @@ export class Meta {
}
});
} else if (/^refs\/tags\//.test(this.context.ref)) {
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
const sver = semver.clean(tag);
if (this.inputs.tagCoerceTag) {
const coerce = semver.coerce(tag);
if (coerce) {
version.version = handlebars.compile(this.inputs.tagCoerceTag)(coerce);
version.latest = true;
} else if (sver) {
version.version = sver;
version.latest = true;
} else {
version.version = tag;
version.version = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
if (this.inputs.tagMatch) {
const tagMatch = version.version.match(this.inputs.tagMatch);
if (tagMatch) {
version.version = tagMatch[0];
version.latest = this.inputs.tagMatchLatest;
}
} else if (sver) {
version.version = sver;
version.latest = true;
} else {
version.version = tag;
}
} else if (/^refs\/heads\//.test(this.context.ref)) {
version.version = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');