Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4a3aaf409c | ||
|
0c4748bf65 | ||
|
ffb794a3fd | ||
|
0dac4059e9 | ||
|
4d7603f754 | ||
|
06c67913f5 | ||
|
1c62cbada4 | ||
|
5bc3bf6dce |
25
.github/workflows/ci.yml
vendored
25
.github/workflows/ci.yml
vendored
@@ -2,7 +2,7 @@ name: ci
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 * * * *' # every hours
|
- cron: '0 */4 * * *' # every 4 hours
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- '**'
|
- '**'
|
||||||
@@ -53,6 +53,29 @@ jobs:
|
|||||||
tag-sha: true
|
tag-sha: true
|
||||||
tag-schedule: ${{ matrix.tag-schedule }}
|
tag-schedule: ${{ matrix.tag-schedule }}
|
||||||
|
|
||||||
|
coerce:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
tag-coerce-tag:
|
||||||
|
- "{{raw}}"
|
||||||
|
- "{{major}}.{{minor}}"
|
||||||
|
- "{{patch}}"
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2.3.3
|
||||||
|
-
|
||||||
|
name: Docker meta
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.DOCKER_IMAGE }}
|
||||||
|
ghcr.io/name/app
|
||||||
|
tag-coerce-tag: ${{ matrix.tag-coerce-tag }}
|
||||||
|
tag-sha: true
|
||||||
|
|
||||||
docker-push:
|
docker-push:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
services:
|
services:
|
||||||
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -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 }}
|
||||||
|
@@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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)
|
||||||
|
|
||||||
## 1.1.0 (2020/10/25)
|
## 1.1.0 (2020/10/25)
|
||||||
|
|
||||||
* Allow to templatize schedule tag (#1)
|
* Allow to templatize schedule tag (#1)
|
||||||
|
37
README.md
37
README.md
@@ -23,7 +23,9 @@ ___
|
|||||||
* [inputs](#inputs)
|
* [inputs](#inputs)
|
||||||
* [outputs](#outputs)
|
* [outputs](#outputs)
|
||||||
* [Notes](#notes)
|
* [Notes](#notes)
|
||||||
* [Templates available for schedule tag](#templates-available-for-schedule-tag)
|
* [Latest tag](#latest-tag)
|
||||||
|
* [Coerces Git tag](#coerces-git-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)
|
||||||
@@ -37,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` |
|
||||||
@@ -114,7 +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-schedule` | String | [Handlebars template](https://handlebarsjs.com/guide/) to apply to schedule tag (default `nightly`) |
|
| `tag-coerce-tag` | String | Coerces Git tag to semver if possible using [template](#coerces-git-tag) |
|
||||||
|
| `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`) |
|
||||||
|
|
||||||
@@ -132,7 +136,30 @@ Following outputs are available
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
### Templates available for schedule tag
|
### Latest tag
|
||||||
|
|
||||||
|
`latest` tag is created with the following conditions:
|
||||||
|
|
||||||
|
* Git tag is a valid [semver](https://semver.org/)
|
||||||
|
* 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
|
||||||
|
|
||||||
|
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` |
|
||||||
|
|
||||||
|
### 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:
|
||||||
|
23
__tests__/fixtures/event_tag_20200110-RC2.env
Normal file
23
__tests__/fixtures/event_tag_20200110-RC2.env
Normal file
@@ -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/20200110-RC2
|
||||||
|
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
|
23
__tests__/fixtures/event_tag_sometag.env
Normal file
23
__tests__/fixtures/event_tag_sometag.env
Normal file
@@ -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/sometag
|
||||||
|
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
|
23
__tests__/fixtures/event_tag_v2.0.8-beta.67.env
Normal file
23
__tests__/fixtures/event_tag_v2.0.8-beta.67.env
Normal file
@@ -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/v2.0.8-beta.67
|
||||||
|
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
|
File diff suppressed because it is too large
Load Diff
@@ -21,8 +21,14 @@ inputs:
|
|||||||
tag-edge-branch:
|
tag-edge-branch:
|
||||||
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:
|
||||||
|
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
|
||||||
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:
|
||||||
|
121
dist/index.js
generated
vendored
121
dist/index.js
generated
vendored
@@ -25,6 +25,8 @@ function getInputs() {
|
|||||||
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
||||||
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'),
|
||||||
|
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`,
|
||||||
@@ -129,9 +131,9 @@ function run() {
|
|||||||
const meta = new meta_1.Meta(inputs, context, repo);
|
const meta = new meta_1.Meta(inputs, context, repo);
|
||||||
const version = meta.version();
|
const version = meta.version();
|
||||||
core.startGroup(`Docker image version`);
|
core.startGroup(`Docker image version`);
|
||||||
core.info(`${version}`);
|
core.info(version.version || '');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
core.setOutput('version', version || '');
|
core.setOutput('version', version.version || '');
|
||||||
const tags = meta.tags();
|
const tags = meta.tags();
|
||||||
core.startGroup(`Docker tags`);
|
core.startGroup(`Docker tags`);
|
||||||
for (let tag of tags) {
|
for (let tag of tags) {
|
||||||
@@ -167,7 +169,6 @@ exports.Meta = void 0;
|
|||||||
const handlebars = __webpack_require__(7492);
|
const handlebars = __webpack_require__(7492);
|
||||||
const moment = __webpack_require__(9623);
|
const moment = __webpack_require__(9623);
|
||||||
const semver = __webpack_require__(1383);
|
const semver = __webpack_require__(1383);
|
||||||
const core = __webpack_require__(2186);
|
|
||||||
class Meta {
|
class Meta {
|
||||||
constructor(inputs, context, repo) {
|
constructor(inputs, context, repo) {
|
||||||
this.inputs = inputs;
|
this.inputs = inputs;
|
||||||
@@ -179,40 +180,69 @@ class Meta {
|
|||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
}
|
}
|
||||||
version() {
|
version() {
|
||||||
|
var _a;
|
||||||
|
const currentDate = this.date;
|
||||||
|
const version = {
|
||||||
|
version: undefined,
|
||||||
|
latest: false
|
||||||
|
};
|
||||||
if (/schedule/.test(this.context.eventName)) {
|
if (/schedule/.test(this.context.eventName)) {
|
||||||
return handlebars.compile(this.inputs.tagSchedule)(this.scheduleTplContext());
|
version.version = handlebars.compile(this.inputs.tagSchedule)({
|
||||||
|
date: function (format) {
|
||||||
|
return moment(currentDate).utc().format(format);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (/^refs\/tags\//.test(this.context.ref)) {
|
else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||||
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||||
const sver = semver.clean(tag);
|
const sver = semver.clean(tag);
|
||||||
return sver ? sver : 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 (/^refs\/heads\//.test(this.context.ref)) {
|
else if (sver) {
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
version.version = sver;
|
||||||
return this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch ? 'edge' : branch;
|
version.latest = true;
|
||||||
}
|
|
||||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
|
||||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
|
||||||
return `pr-${pr}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tags() {
|
|
||||||
let tags = [];
|
|
||||||
for (const image of this.inputs.images) {
|
|
||||||
if (/schedule/.test(this.context.eventName)) {
|
|
||||||
tags.push.apply(tags, this.eventSchedule(image));
|
|
||||||
}
|
|
||||||
else if (/^refs\/tags\//.test(this.context.ref)) {
|
|
||||||
tags.push.apply(tags, this.eventTag(image));
|
|
||||||
}
|
|
||||||
else if (/^refs\/heads\//.test(this.context.ref)) {
|
|
||||||
tags.push.apply(tags, this.eventBranch(image));
|
|
||||||
}
|
|
||||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
|
||||||
tags.push.apply(tags, this.eventPullRequest(image));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.warning(`Unknown event "${this.context.eventName}" with ref "${this.context.ref}"`);
|
version.version = tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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, '-');
|
||||||
|
if (this.inputs.tagEdge && this.inputs.tagEdgeBranch === version.version) {
|
||||||
|
version.version = 'edge';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
tags() {
|
||||||
|
const version = this.version();
|
||||||
|
if (!version.version) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
let tags = [];
|
||||||
|
for (const image of this.inputs.images) {
|
||||||
|
tags.push(`${image}:${version.version}`);
|
||||||
|
if (version.latest) {
|
||||||
|
tags.push(`${image}:latest`);
|
||||||
}
|
}
|
||||||
if (this.context.sha && this.inputs.tagSha) {
|
if (this.context.sha && this.inputs.tagSha) {
|
||||||
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
||||||
@@ -227,43 +257,12 @@ class Meta {
|
|||||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||||
`org.opencontainers.image.source=${this.repo.clone_url || ''}`,
|
`org.opencontainers.image.source=${this.repo.clone_url || ''}`,
|
||||||
`org.opencontainers.image.version=${this.version() || ''}`,
|
`org.opencontainers.image.version=${this.version().version || ''}`,
|
||||||
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
||||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||||
`org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}`
|
`org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}`
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
eventSchedule(image) {
|
|
||||||
const schedule = handlebars.compile(this.inputs.tagSchedule)(this.scheduleTplContext());
|
|
||||||
return [`${image}:${schedule}`];
|
|
||||||
}
|
|
||||||
eventTag(image) {
|
|
||||||
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
|
||||||
const version = semver.clean(tag);
|
|
||||||
if (version) {
|
|
||||||
return [`${image}:${version}`, `${image}:latest`];
|
|
||||||
}
|
|
||||||
return [`${image}:${tag}`];
|
|
||||||
}
|
|
||||||
eventBranch(image) {
|
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
|
||||||
if (this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch) {
|
|
||||||
return [`${image}:edge`];
|
|
||||||
}
|
|
||||||
return [`${image}:${branch}`];
|
|
||||||
}
|
|
||||||
eventPullRequest(image) {
|
|
||||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
|
||||||
return [`${image}:pr-${pr}`];
|
|
||||||
}
|
|
||||||
scheduleTplContext() {
|
|
||||||
const currentDate = this.date;
|
|
||||||
return {
|
|
||||||
date: function (format) {
|
|
||||||
return moment(currentDate).utc().format(format);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.Meta = Meta;
|
exports.Meta = Meta;
|
||||||
//# sourceMappingURL=meta.js.map
|
//# sourceMappingURL=meta.js.map
|
||||||
|
@@ -5,6 +5,8 @@ export interface Inputs {
|
|||||||
tagSha: boolean;
|
tagSha: boolean;
|
||||||
tagEdge: boolean;
|
tagEdge: boolean;
|
||||||
tagEdgeBranch: string;
|
tagEdgeBranch: string;
|
||||||
|
tagCoerceTag: string;
|
||||||
|
tagLatestMatch: string;
|
||||||
tagSchedule: string;
|
tagSchedule: string;
|
||||||
sepTags: string;
|
sepTags: string;
|
||||||
sepLabels: string;
|
sepLabels: string;
|
||||||
@@ -17,6 +19,8 @@ export function getInputs(): Inputs {
|
|||||||
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
tagSha: /true/i.test(core.getInput('tag-sha') || 'false'),
|
||||||
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'),
|
||||||
|
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`,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import {getInputs, Inputs} from './context';
|
import {getInputs, Inputs} from './context';
|
||||||
import * as github from './github';
|
import * as github from './github';
|
||||||
import {Meta} from './meta';
|
import {Meta, Version} from './meta';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {Context} from '@actions/github/lib/context';
|
import {Context} from '@actions/github/lib/context';
|
||||||
import {ReposGetResponseData} from '@octokit/types';
|
import {ReposGetResponseData} from '@octokit/types';
|
||||||
@@ -27,11 +27,11 @@ async function run() {
|
|||||||
|
|
||||||
const meta: Meta = new Meta(inputs, context, repo);
|
const meta: Meta = new Meta(inputs, context, repo);
|
||||||
|
|
||||||
const version: string | undefined = meta.version();
|
const version: Version = meta.version();
|
||||||
core.startGroup(`Docker image version`);
|
core.startGroup(`Docker image version`);
|
||||||
core.info(`${version}`);
|
core.info(version.version || '');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
core.setOutput('version', version || '');
|
core.setOutput('version', version.version || '');
|
||||||
|
|
||||||
const tags: Array<string> = meta.tags();
|
const tags: Array<string> = meta.tags();
|
||||||
core.startGroup(`Docker tags`);
|
core.startGroup(`Docker tags`);
|
||||||
|
114
src/meta.ts
114
src/meta.ts
@@ -2,10 +2,14 @@ import * as handlebars from 'handlebars';
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import {Inputs} from './context';
|
import {Inputs} from './context';
|
||||||
import * as core from '@actions/core';
|
|
||||||
import {Context} from '@actions/github/lib/context';
|
import {Context} from '@actions/github/lib/context';
|
||||||
import {ReposGetResponseData} from '@octokit/types';
|
import {ReposGetResponseData} from '@octokit/types';
|
||||||
|
|
||||||
|
export interface Version {
|
||||||
|
version: string | undefined;
|
||||||
|
latest: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class Meta {
|
export class Meta {
|
||||||
private readonly inputs: Inputs;
|
private readonly inputs: Inputs;
|
||||||
private readonly context: Context;
|
private readonly context: Context;
|
||||||
@@ -22,35 +26,67 @@ export class Meta {
|
|||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
public version(): string | undefined {
|
public version(): Version {
|
||||||
|
const currentDate = this.date;
|
||||||
|
const version: Version = {
|
||||||
|
version: undefined,
|
||||||
|
latest: false
|
||||||
|
};
|
||||||
|
|
||||||
if (/schedule/.test(this.context.eventName)) {
|
if (/schedule/.test(this.context.eventName)) {
|
||||||
return handlebars.compile(this.inputs.tagSchedule)(this.scheduleTplContext());
|
version.version = handlebars.compile(this.inputs.tagSchedule)({
|
||||||
|
date: function (format) {
|
||||||
|
return moment(currentDate).utc().format(format);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||||
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||||
const sver = semver.clean(tag);
|
const sver = semver.clean(tag);
|
||||||
return sver ? sver : tag;
|
if (this.inputs.tagCoerceTag) {
|
||||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
const coerce = semver.coerce(tag);
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
if (coerce) {
|
||||||
return this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch ? 'edge' : branch;
|
version.version = handlebars.compile(this.inputs.tagCoerceTag)(coerce);
|
||||||
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
version.latest = true;
|
||||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
} else if (sver) {
|
||||||
return `pr-${pr}`;
|
version.version = sver;
|
||||||
|
version.latest = true;
|
||||||
|
} else {
|
||||||
|
version.version = tag;
|
||||||
}
|
}
|
||||||
|
} 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, '-');
|
||||||
|
if (this.inputs.tagEdge && this.inputs.tagEdgeBranch === version.version) {
|
||||||
|
version.version = 'edge';
|
||||||
|
}
|
||||||
|
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public tags(): Array<string> {
|
public tags(): Array<string> {
|
||||||
|
const version: Version = this.version();
|
||||||
|
if (!version.version) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
let tags: Array<string> = [];
|
let tags: Array<string> = [];
|
||||||
for (const image of this.inputs.images) {
|
for (const image of this.inputs.images) {
|
||||||
if (/schedule/.test(this.context.eventName)) {
|
tags.push(`${image}:${version.version}`);
|
||||||
tags.push.apply(tags, this.eventSchedule(image));
|
if (version.latest) {
|
||||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
tags.push(`${image}:latest`);
|
||||||
tags.push.apply(tags, this.eventTag(image));
|
|
||||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
|
||||||
tags.push.apply(tags, this.eventBranch(image));
|
|
||||||
} else if (/^refs\/pull\//.test(this.context.ref)) {
|
|
||||||
tags.push.apply(tags, this.eventPullRequest(image));
|
|
||||||
} else {
|
|
||||||
core.warning(`Unknown event "${this.context.eventName}" with ref "${this.context.ref}"`);
|
|
||||||
}
|
}
|
||||||
if (this.context.sha && this.inputs.tagSha) {
|
if (this.context.sha && this.inputs.tagSha) {
|
||||||
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
tags.push(`${image}:sha-${this.context.sha.substr(0, 7)}`);
|
||||||
@@ -65,46 +101,10 @@ export class Meta {
|
|||||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||||
`org.opencontainers.image.source=${this.repo.clone_url || ''}`,
|
`org.opencontainers.image.source=${this.repo.clone_url || ''}`,
|
||||||
`org.opencontainers.image.version=${this.version() || ''}`,
|
`org.opencontainers.image.version=${this.version().version || ''}`,
|
||||||
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
||||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private eventSchedule(image: string): Array<string> {
|
|
||||||
const schedule = handlebars.compile(this.inputs.tagSchedule)(this.scheduleTplContext());
|
|
||||||
return [`${image}:${schedule}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
private eventTag(image: string): Array<string> {
|
|
||||||
const tag = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
|
||||||
const version = semver.clean(tag);
|
|
||||||
if (version) {
|
|
||||||
return [`${image}:${version}`, `${image}:latest`];
|
|
||||||
}
|
|
||||||
return [`${image}:${tag}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
private eventBranch(image: string): Array<string> {
|
|
||||||
const branch = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
|
||||||
if (this.inputs.tagEdge && this.inputs.tagEdgeBranch === branch) {
|
|
||||||
return [`${image}:edge`];
|
|
||||||
}
|
|
||||||
return [`${image}:${branch}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
private eventPullRequest(image: string): Array<string> {
|
|
||||||
const pr = this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '');
|
|
||||||
return [`${image}:pr-${pr}`];
|
|
||||||
}
|
|
||||||
|
|
||||||
private scheduleTplContext(): any {
|
|
||||||
const currentDate = this.date;
|
|
||||||
return {
|
|
||||||
date: function (format) {
|
|
||||||
return moment(currentDate).utc().format(format);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user