Compare commits

...

6 Commits

Author SHA1 Message Date
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
9 changed files with 225 additions and 17 deletions

View File

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

View File

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

View File

@@ -1,5 +1,9 @@
# Changelog # Changelog
## 1.3.0 (2020/10/26)
* Set latest tag only if matches with a pattern
## 1.2.0 (2020/10/26) ## 1.2.0 (2020/10/26)
* Coerces Git tag to semver (#3) * Coerces Git tag to semver (#3)

View File

@@ -25,7 +25,7 @@ ___
* [Notes](#notes) * [Notes](#notes)
* [Latest tag](#latest-tag) * [Latest tag](#latest-tag)
* [Coerces Git tag](#coerces-git-tag) * [Coerces Git tag](#coerces-git-tag)
* [Templates available for schedule tag](#templates-available-for-schedule-tag) * [Schedule tag](#schedule-tag)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot) * [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [How can I help?](#how-can-i-help) * [How can I help?](#how-can-i-help)
* [License](#license) * [License](#license)
@@ -39,8 +39,8 @@ ___
## Overview ## Overview
| Event | Ref | Commit SHA | Docker Tags | | 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` | | `pull_request` | `refs/pull/2/merge` | `a123b57` | `sha-a123b57`, `pr-2` |
| `push` | `refs/heads/<default_branch>` | `676cae2` | `sha-676cae2`, `edge` | | `push` | `refs/heads/<default_branch>` | `676cae2` | `sha-676cae2`, `edge` |
| `push` | `refs/heads/dev` | `cf20257` | `sha-cf20257`, `dev` | | `push` | `refs/heads/dev` | `cf20257` | `sha-cf20257`, `dev` |
@@ -116,8 +116,9 @@ Following inputs can be used as `step.with` keys
| `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) | | `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) |
| `tag-edge` | Bool | Enable edge branch tagging (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-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-coerce-tag` | String | Coerces Git tag to semver if possible using [template](#coerces-git-tag) |
| `tag-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) | | `tag-latest-match` | String | Set `latest` tag only if [matches with a pattern](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) |
| `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-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) | | `sep-labels` | String | Separator to use for labels output (default `\n`) |
@@ -137,11 +138,13 @@ Following outputs are available
### Latest tag ### Latest tag
`latest` tag is created only on `push tag` event and resolves one of the following conditions: `latest` tag is created with the following conditions:
* Git tag is a valid [semver](https://semver.org/) * Git tag is a valid [semver](https://semver.org/)
* Provided `tag-coerce-tag` is valid * Provided `tag-coerce-tag` is valid
If `tag-latest-match` is filled, then it has priority over the creation of the tag.
### Coerces Git tag ### Coerces Git tag
Provides a very forgiving translation of a non-semver tag to semver. For more information see Provides a very forgiving translation of a non-semver tag to semver. For more information see
@@ -156,7 +159,7 @@ Provides a very forgiving translation of a non-semver tag to semver. For more in
| `{{minor}}` | `v1.2.3` | `2` | | `{{minor}}` | `v1.2.3` | `2` |
| `{{patch}}` | `v1.2.3` | `3` | | `{{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 `tag-schedule` is specially crafted input to support [Handlebars template](https://handlebarsjs.com/guide/) with
the following expressions: the following expressions:

View File

@@ -601,6 +601,191 @@ describe('push tag', () => {
])('given %p event ', tagsLabelsTest); ])('given %p event ', tagsLabelsTest);
}); });
describe('latest', () => {
// prettier-ignore
test.each([
[
'event_tag_release1.env',
{
images: ['user/app'],
tagLatestMatch: `^release`,
} 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'],
tagLatestMatch: `^\\d`,
} 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'],
tagCoerceTag: '{{major}}',
tagLatestMatch: `\\d`,
} 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'],
tagLatestMatch: `\\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: '1.1.1',
latest: true
} as Version,
[
'org/app:1.1.1',
'org/app:latest',
'ghcr.io/user/app:1.1.1',
'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=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'],
tagLatestMatch: `2.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '1.1.1',
latest: false
} as Version,
[
'org/app:1.1.1',
'ghcr.io/user/app:1.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.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'],
tagLatestMatch: `^\\d{1,3}.\\d{1,3}.\\d{1,3}`,
} as Inputs,
{
version: '2.0.8-beta.67',
latest: true
} as Version,
[
'org/app:2.0.8-beta.67',
'org/app:latest',
'ghcr.io/user/app:2.0.8-beta.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.git",
"org.opencontainers.image.version=2.0.8-beta.67",
"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', () => { describe('pull_request', () => {
// prettier-ignore // prettier-ignore
test.each([ test.each([

View File

@@ -22,10 +22,13 @@ inputs:
description: 'Branch that will be tagged as edge (default repo.default_branch)' description: 'Branch that will be tagged as edge (default repo.default_branch)'
required: false required: false
tag-coerce-tag: tag-coerce-tag:
description: 'Coerces Git tag to semver if possible using Handlebars template' description: 'Coerces Git tag to semver if possible using template'
required: false
tag-latest-match:
description: 'Set latest tag only if matches with a pattern'
required: false required: false
tag-schedule: tag-schedule:
description: 'Handlebars template to apply to schedule tag' description: 'Template to apply to schedule tag'
default: 'nightly' default: 'nightly'
required: false required: false
sep-tags: sep-tags:

6
dist/index.js generated vendored
View File

@@ -26,6 +26,7 @@ function getInputs() {
tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'), tagEdge: /true/i.test(core.getInput('tag-edge') || 'false'),
tagEdgeBranch: core.getInput('tag-edge-branch'), tagEdgeBranch: core.getInput('tag-edge-branch'),
tagCoerceTag: core.getInput('tag-coerce-tag'), tagCoerceTag: core.getInput('tag-coerce-tag'),
tagLatestMatch: core.getInput('tag-latest-match'),
tagSchedule: core.getInput('tag-schedule') || 'nightly', tagSchedule: core.getInput('tag-schedule') || 'nightly',
sepTags: core.getInput('sep-tags') || `\n`, sepTags: core.getInput('sep-tags') || `\n`,
sepLabels: core.getInput('sep-labels') || `\n`, sepLabels: core.getInput('sep-labels') || `\n`,
@@ -179,6 +180,7 @@ class Meta {
this.date = new Date(); this.date = new Date();
} }
version() { version() {
var _a;
const currentDate = this.date; const currentDate = this.date;
const version = { const version = {
version: undefined, version: undefined,
@@ -225,6 +227,10 @@ class Meta {
else if (/^refs\/pull\//.test(this.context.ref)) { else if (/^refs\/pull\//.test(this.context.ref)) {
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`; version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
} }
if (this.inputs.tagLatestMatch) {
const match = (_a = version.version) === null || _a === void 0 ? void 0 : _a.match(new RegExp(this.inputs.tagLatestMatch));
version.latest = match !== null;
}
return version; return version;
} }
tags() { tags() {

View File

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

View File

@@ -68,6 +68,11 @@ export class Meta {
version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`; version.version = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
} }
if (this.inputs.tagLatestMatch) {
const match = version.version?.match(new RegExp(this.inputs.tagLatestMatch));
version.latest = match !== null;
}
return version; return version;
} }