Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b747b8aaa7 | ||
|
585ab8356c | ||
|
9de4428611 | ||
|
4c2760ba7a | ||
|
ef12c77b87 |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -82,10 +82,18 @@ jobs:
|
||||
|
||||
tag-semver:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
tag-latest:
|
||||
- 'true'
|
||||
- 'false'
|
||||
steps:
|
||||
- name: Checkout
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Docker meta
|
||||
-
|
||||
name: Docker meta
|
||||
uses: ./
|
||||
with:
|
||||
images: |
|
||||
@@ -95,6 +103,7 @@ jobs:
|
||||
{{raw}}
|
||||
{{version}}
|
||||
{{major}}.{{minor}}.{{patch}}
|
||||
tag-latest: ${{ matrix.tag-latest }}
|
||||
|
||||
docker-push:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -114,7 +123,10 @@ jobs:
|
||||
with:
|
||||
images: ${{ env.DOCKER_IMAGE }}
|
||||
tag-sha: true
|
||||
tag-match: '\d{1,3}.\d{1,3}.\d{1,3}'
|
||||
tag-semver: |
|
||||
v{{version}}
|
||||
v{{major}}.{{minor}}
|
||||
v{{major}}
|
||||
-
|
||||
name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
|
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 1.9.0 (2020/12/04)
|
||||
|
||||
* Allow to add custom tags (#24)
|
||||
* Allow to disable latest tag (#23)
|
||||
* Warn on invalid semver (#22)
|
||||
* Avoid unnecessary calls to version (#21)
|
||||
|
||||
## 1.8.5 (2020/11/24)
|
||||
|
||||
* Use sepLabels when joining labels for output (#17)
|
||||
|
@@ -241,11 +241,13 @@ 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-semver` | List | Handle Git tag as semver [template](#handle-semver-tag) if possible |
|
||||
| `tag-semver` | List/CSV | Handle Git tag as semver [template](#handle-semver-tag) if possible |
|
||||
| `tag-match` | String | RegExp to match against a Git tag and use first match as Docker tag |
|
||||
| `tag-match-group` | Number | Group to get if `tag-match` matches (default `0`) |
|
||||
| `tag-match-latest` | Bool | Set `latest` Docker tag if `tag-match` matches or on Git tag event (default `true`) |
|
||||
| `tag-latest` | Bool | Set `latest` Docker tag if `tag-semver`, `tag-match` or Git tag event occurs (default `true`) |
|
||||
| `tag-schedule` | String | [Template](#schedule-tag) to apply to schedule tag (default `nightly`) |
|
||||
| `tag-custom` | List/CSV | List of custom tags |
|
||||
| `tag-custom-only` | Bool | Only use `tag-custom` as Docker tags |
|
||||
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
|
||||
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
|
||||
|
||||
@@ -270,7 +272,7 @@ Following outputs are available
|
||||
Latest Docker tag will be generated by default on `push tag` event. 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 `tag-semver` is a valid [semver](https://semver.org/) or if Git tag matches a regular expression
|
||||
with the [`tag-match` input](#tag-match-examples).
|
||||
with the [`tag-match` input](#tag-match-examples). Can be disabled if `tag-latest` is `false`.
|
||||
|
||||
### Handle semver tag
|
||||
|
||||
|
@@ -44,7 +44,7 @@ const tagsLabelsTest = async (envFile: string, inputs: Inputs, exVersion: Versio
|
||||
const repo = await github.repo(process.env.GITHUB_TOKEN || '');
|
||||
const meta = new Meta({...getInputs(), ...inputs}, context, repo);
|
||||
|
||||
const version = meta.version();
|
||||
const version = meta.version;
|
||||
console.log('version', version);
|
||||
expect(version).toEqual(exVersion);
|
||||
|
||||
@@ -437,7 +437,7 @@ describe('push tag', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagMatch: `\\d{8}`,
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
@@ -464,7 +464,7 @@ describe('push tag', () => {
|
||||
images: ['user/app'],
|
||||
tagMatch: `(.*)-RC`,
|
||||
tagMatchGroup: 1,
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
@@ -737,6 +737,32 @@ describe('push tag', () => {
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_sometag.env',
|
||||
{
|
||||
images: ['ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'sometag',
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'ghcr.io/user/app:sometag'
|
||||
],
|
||||
[
|
||||
"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=sometag",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
||||
@@ -906,7 +932,7 @@ describe('latest', () => {
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'v1.1.1',
|
||||
@@ -932,7 +958,7 @@ describe('latest', () => {
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/MyUSER/MyApp'],
|
||||
tagMatchLatest: false,
|
||||
tagLatest: false,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'v1.1.1',
|
||||
@@ -1203,3 +1229,193 @@ describe('release', () => {
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
||||
describe('custom', () => {
|
||||
// prettier-ignore
|
||||
test.each([
|
||||
[
|
||||
'event_push.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'dev',
|
||||
partial: ['my', 'custom', 'tags'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:dev',
|
||||
'user/app:my',
|
||||
'user/app:custom',
|
||||
'user/app:tags'
|
||||
],
|
||||
[
|
||||
"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=dev",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_push.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagCustom: ['my']
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'dev',
|
||||
partial: ['my'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:dev',
|
||||
'user/app:my'
|
||||
],
|
||||
[
|
||||
"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=dev",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'event_tag_release1.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'release1',
|
||||
partial: ['my', 'custom', 'tags'],
|
||||
latest: true
|
||||
} as Version,
|
||||
[
|
||||
'user/app:release1',
|
||||
'user/app:my',
|
||||
'user/app:custom',
|
||||
'user/app:tags',
|
||||
'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",
|
||||
"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{8}`,
|
||||
tagLatest: false,
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: '20200110',
|
||||
partial: ['my', 'custom', 'tags'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:20200110',
|
||||
'user/app:my',
|
||||
'user/app:custom',
|
||||
'user/app:tags'
|
||||
],
|
||||
[
|
||||
"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=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: ['org/app', 'ghcr.io/user/app'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}', '{{major}}'],
|
||||
tagCustom: ['my', 'custom', 'tags']
|
||||
} as Inputs,
|
||||
{
|
||||
main: '1.1.1',
|
||||
partial: ['1.1', '1', 'my', 'custom', 'tags'],
|
||||
latest: true
|
||||
} as Version,
|
||||
[
|
||||
'org/app:1.1.1',
|
||||
'org/app:1.1',
|
||||
'org/app:1',
|
||||
'org/app:my',
|
||||
'org/app:custom',
|
||||
'org/app:tags',
|
||||
'org/app:latest',
|
||||
'ghcr.io/user/app:1.1.1',
|
||||
'ghcr.io/user/app:1.1',
|
||||
'ghcr.io/user/app:1',
|
||||
'ghcr.io/user/app:my',
|
||||
'ghcr.io/user/app:custom',
|
||||
'ghcr.io/user/app:tags',
|
||||
'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",
|
||||
"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'],
|
||||
tagSemver: ['{{version}}', '{{major}}.{{minor}}.{{patch}}'],
|
||||
tagCustom: ['my', 'custom', 'tags'],
|
||||
tagCustomOnly: true,
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'my',
|
||||
partial: ['custom', 'tags'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:my',
|
||||
'org/app:custom',
|
||||
'org/app:tags',
|
||||
'ghcr.io/user/app:my',
|
||||
'ghcr.io/user/app:custom',
|
||||
'ghcr.io/user/app:tags'
|
||||
],
|
||||
[
|
||||
"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=my",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
])('given %p event ', tagsLabelsTest);
|
||||
});
|
||||
|
13
action.yml
13
action.yml
@@ -31,14 +31,25 @@ inputs:
|
||||
description: 'Group to get if tag-match matches (default 0)'
|
||||
default: '0'
|
||||
required: false
|
||||
tag-latest:
|
||||
description: 'Set latest Docker tag if tag-semver, tag-match or Git tag event occurs'
|
||||
default: 'true'
|
||||
required: false
|
||||
tag-match-latest:
|
||||
description: 'Set latest Docker tag if tag-match matches or on Git tag event'
|
||||
deprecationMessage: 'tag-match-latest is deprecated. Use tag-latest instead'
|
||||
description: '(DEPRECATED) Set latest Docker tag if tag-match matches or on Git tag event'
|
||||
default: 'true'
|
||||
required: false
|
||||
tag-schedule:
|
||||
description: 'Template to apply to schedule tag'
|
||||
default: 'nightly'
|
||||
required: false
|
||||
tag-custom:
|
||||
description: 'List of custom tags'
|
||||
required: false
|
||||
tag-custom-only:
|
||||
description: 'Only use tag-custom as Docker tags'
|
||||
required: false
|
||||
sep-tags:
|
||||
description: 'Separator to use for tags output (default \n)'
|
||||
required: false
|
||||
|
44
dist/index.js
generated
vendored
44
dist/index.js
generated
vendored
@@ -28,8 +28,10 @@ function getInputs() {
|
||||
tagSemver: getInputList('tag-semver'),
|
||||
tagMatch: core.getInput('tag-match'),
|
||||
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
||||
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
|
||||
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
|
||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||
tagCustom: getInputList('tag-custom'),
|
||||
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
|
||||
sepTags: core.getInput('sep-tags') || `\n`,
|
||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||
githubToken: core.getInput('github-token')
|
||||
@@ -131,7 +133,7 @@ function run() {
|
||||
core.info(`runId: ${context.runId}`);
|
||||
core.endGroup();
|
||||
const meta = new meta_1.Meta(inputs, context, repo);
|
||||
const version = meta.version();
|
||||
const version = meta.version;
|
||||
core.startGroup(`Docker image version`);
|
||||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
@@ -171,6 +173,7 @@ exports.Meta = void 0;
|
||||
const handlebars = __webpack_require__(7492);
|
||||
const moment = __webpack_require__(9623);
|
||||
const semver = __webpack_require__(1383);
|
||||
const core = __webpack_require__(2186);
|
||||
class Meta {
|
||||
constructor(inputs, context, repo) {
|
||||
this.inputs = inputs;
|
||||
@@ -180,10 +183,11 @@ class Meta {
|
||||
this.context = context;
|
||||
this.repo = repo;
|
||||
this.date = new Date();
|
||||
this.version = this.getVersion();
|
||||
}
|
||||
version() {
|
||||
getVersion() {
|
||||
const currentDate = this.date;
|
||||
const version = {
|
||||
let version = {
|
||||
main: undefined,
|
||||
partial: [],
|
||||
latest: false
|
||||
@@ -197,6 +201,9 @@ class Meta {
|
||||
}
|
||||
else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
|
||||
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
|
||||
}
|
||||
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
|
||||
const sver = semver.parse(version.main, {
|
||||
includePrerelease: true
|
||||
@@ -205,7 +212,7 @@ class Meta {
|
||||
version.main = handlebars.compile('{{version}}')(sver);
|
||||
}
|
||||
else {
|
||||
version.latest = true;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||
for (const semverTpl of this.inputs.tagSemver) {
|
||||
const partial = handlebars.compile(semverTpl)(sver);
|
||||
@@ -227,11 +234,11 @@ class Meta {
|
||||
}
|
||||
if (tagMatch) {
|
||||
version.main = tagMatch[this.inputs.tagMatchGroup];
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
}
|
||||
else {
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
}
|
||||
else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||
@@ -243,22 +250,33 @@ class Meta {
|
||||
else if (/^refs\/pull\//.test(this.context.ref)) {
|
||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||
}
|
||||
if (this.inputs.tagCustom.length > 0) {
|
||||
if (this.inputs.tagCustomOnly) {
|
||||
version = {
|
||||
main: this.inputs.tagCustom.shift(),
|
||||
partial: this.inputs.tagCustom,
|
||||
latest: false
|
||||
};
|
||||
}
|
||||
else {
|
||||
version.partial.push(...this.inputs.tagCustom);
|
||||
}
|
||||
}
|
||||
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||
return version;
|
||||
}
|
||||
tags() {
|
||||
const version = this.version();
|
||||
if (!version.main) {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
}
|
||||
let tags = [];
|
||||
for (const image of this.inputs.images) {
|
||||
const imageLc = image.toLowerCase();
|
||||
tags.push(`${imageLc}:${version.main}`);
|
||||
for (const partial of version.partial) {
|
||||
tags.push(`${imageLc}:${this.version.main}`);
|
||||
for (const partial of this.version.partial) {
|
||||
tags.push(`${imageLc}:${partial}`);
|
||||
}
|
||||
if (version.latest) {
|
||||
if (this.version.latest) {
|
||||
tags.push(`${imageLc}:latest`);
|
||||
}
|
||||
if (this.context.sha && this.inputs.tagSha) {
|
||||
@@ -274,7 +292,7 @@ class Meta {
|
||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.source=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.version=${this.version().main || ''}`,
|
||||
`org.opencontainers.image.version=${this.version.main || ''}`,
|
||||
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||
`org.opencontainers.image.licenses=${((_a = this.repo.license) === null || _a === void 0 ? void 0 : _a.spdx_id) || ''}`
|
||||
|
@@ -8,8 +8,10 @@ export interface Inputs {
|
||||
tagSemver: string[];
|
||||
tagMatch: string;
|
||||
tagMatchGroup: number;
|
||||
tagMatchLatest: boolean;
|
||||
tagLatest: boolean;
|
||||
tagSchedule: string;
|
||||
tagCustom: string[];
|
||||
tagCustomOnly: boolean;
|
||||
sepTags: string;
|
||||
sepLabels: string;
|
||||
githubToken: string;
|
||||
@@ -24,8 +26,10 @@ export function getInputs(): Inputs {
|
||||
tagSemver: getInputList('tag-semver'),
|
||||
tagMatch: core.getInput('tag-match'),
|
||||
tagMatchGroup: Number(core.getInput('tag-match-group')) || 0,
|
||||
tagMatchLatest: /true/i.test(core.getInput('tag-match-latest') || 'true'),
|
||||
tagLatest: /true/i.test(core.getInput('tag-latest') || core.getInput('tag-match-latest') || 'true'),
|
||||
tagSchedule: core.getInput('tag-schedule') || 'nightly',
|
||||
tagCustom: getInputList('tag-custom'),
|
||||
tagCustomOnly: /true/i.test(core.getInput('tag-custom-only') || 'false'),
|
||||
sepTags: core.getInput('sep-tags') || `\n`,
|
||||
sepLabels: core.getInput('sep-labels') || `\n`,
|
||||
githubToken: core.getInput('github-token')
|
||||
|
@@ -27,7 +27,7 @@ async function run() {
|
||||
|
||||
const meta: Meta = new Meta(inputs, context, repo);
|
||||
|
||||
const version: Version = meta.version();
|
||||
const version: Version = meta.version;
|
||||
core.startGroup(`Docker image version`);
|
||||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
|
40
src/meta.ts
40
src/meta.ts
@@ -2,6 +2,7 @@ import * as handlebars from 'handlebars';
|
||||
import * as moment from 'moment';
|
||||
import * as semver from 'semver';
|
||||
import {Inputs} from './context';
|
||||
import * as core from '@actions/core';
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
import {ReposGetResponseData} from '@octokit/types';
|
||||
|
||||
@@ -12,6 +13,8 @@ export interface Version {
|
||||
}
|
||||
|
||||
export class Meta {
|
||||
public readonly version: Version;
|
||||
|
||||
private readonly inputs: Inputs;
|
||||
private readonly context: Context;
|
||||
private readonly repo: ReposGetResponseData;
|
||||
@@ -25,11 +28,12 @@ export class Meta {
|
||||
this.context = context;
|
||||
this.repo = repo;
|
||||
this.date = new Date();
|
||||
this.version = this.getVersion();
|
||||
}
|
||||
|
||||
public version(): Version {
|
||||
private getVersion(): Version {
|
||||
const currentDate = this.date;
|
||||
const version: Version = {
|
||||
let version: Version = {
|
||||
main: undefined,
|
||||
partial: [],
|
||||
latest: false
|
||||
@@ -43,6 +47,9 @@ export class Meta {
|
||||
});
|
||||
} else if (/^refs\/tags\//.test(this.context.ref)) {
|
||||
version.main = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
if (this.inputs.tagSemver.length > 0 && !semver.valid(version.main)) {
|
||||
core.warning(`${version.main} is not a valid semver. More info: https://semver.org/`);
|
||||
}
|
||||
if (this.inputs.tagSemver.length > 0 && semver.valid(version.main)) {
|
||||
const sver = semver.parse(version.main, {
|
||||
includePrerelease: true
|
||||
@@ -50,7 +57,7 @@ export class Meta {
|
||||
if (semver.prerelease(version.main)) {
|
||||
version.main = handlebars.compile('{{version}}')(sver);
|
||||
} else {
|
||||
version.latest = true;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
version.main = handlebars.compile(this.inputs.tagSemver[0])(sver);
|
||||
for (const semverTpl of this.inputs.tagSemver) {
|
||||
const partial = handlebars.compile(semverTpl)(sver);
|
||||
@@ -70,10 +77,10 @@ export class Meta {
|
||||
}
|
||||
if (tagMatch) {
|
||||
version.main = tagMatch[this.inputs.tagMatchGroup];
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
} else {
|
||||
version.latest = this.inputs.tagMatchLatest;
|
||||
version.latest = this.inputs.tagLatest;
|
||||
}
|
||||
} else if (/^refs\/heads\//.test(this.context.ref)) {
|
||||
version.main = this.context.ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
|
||||
@@ -84,24 +91,35 @@ export class Meta {
|
||||
version.main = `pr-${this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, '')}`;
|
||||
}
|
||||
|
||||
if (this.inputs.tagCustom.length > 0) {
|
||||
if (this.inputs.tagCustomOnly) {
|
||||
version = {
|
||||
main: this.inputs.tagCustom.shift(),
|
||||
partial: this.inputs.tagCustom,
|
||||
latest: false
|
||||
};
|
||||
} else {
|
||||
version.partial.push(...this.inputs.tagCustom);
|
||||
}
|
||||
}
|
||||
|
||||
version.partial = version.partial.filter((item, index) => version.partial.indexOf(item) === index);
|
||||
return version;
|
||||
}
|
||||
|
||||
public tags(): Array<string> {
|
||||
const version: Version = this.version();
|
||||
if (!version.main) {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let tags: Array<string> = [];
|
||||
for (const image of this.inputs.images) {
|
||||
const imageLc = image.toLowerCase();
|
||||
tags.push(`${imageLc}:${version.main}`);
|
||||
for (const partial of version.partial) {
|
||||
tags.push(`${imageLc}:${this.version.main}`);
|
||||
for (const partial of this.version.partial) {
|
||||
tags.push(`${imageLc}:${partial}`);
|
||||
}
|
||||
if (version.latest) {
|
||||
if (this.version.latest) {
|
||||
tags.push(`${imageLc}:latest`);
|
||||
}
|
||||
if (this.context.sha && this.inputs.tagSha) {
|
||||
@@ -117,7 +135,7 @@ export class Meta {
|
||||
`org.opencontainers.image.description=${this.repo.description || ''}`,
|
||||
`org.opencontainers.image.url=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.source=${this.repo.html_url || ''}`,
|
||||
`org.opencontainers.image.version=${this.version().main || ''}`,
|
||||
`org.opencontainers.image.version=${this.version.main || ''}`,
|
||||
`org.opencontainers.image.created=${this.date.toISOString()}`,
|
||||
`org.opencontainers.image.revision=${this.context.sha || ''}`,
|
||||
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
|
||||
|
Reference in New Issue
Block a user