Compare commits
5 Commits
v2.4.0
...
releases/v
Author | SHA1 | Date | |
---|---|---|---|
|
f02d9f4f9b | ||
|
400bd87b5a | ||
|
e4fc7e9e11 | ||
|
9583a0f404 | ||
|
5e6d5157fb |
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 2.5.0 (2021/05/08)
|
||||
|
||||
* Major version zero doc (#74)
|
||||
* Bump hosted-git-info from 2.8.8 to 2.8.9 (#73)
|
||||
* Bump lodash from 4.17.20 to 4.17.21 (#72)
|
||||
* Handle global expressions (#71)
|
||||
|
||||
## 2.4.0 (2021/04/30)
|
||||
|
||||
* Add `bake-target` input (#69)
|
||||
|
40
README.md
40
README.md
@@ -38,6 +38,8 @@ ___
|
||||
* [`type=sha`](#typesha)
|
||||
* [Notes](#notes)
|
||||
* [Latest tag](#latest-tag)
|
||||
* [Global expressions](#global-expressions)
|
||||
* [Major version zero](#major-version-zero)
|
||||
* [Overwrite labels](#overwrite-labels)
|
||||
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
|
||||
* [Contributing](#contributing)
|
||||
@@ -554,6 +556,44 @@ tags: |
|
||||
* [`type=semver,pattern=...`](#typesemver)
|
||||
* [`type=match,pattern=...`](#typematch)
|
||||
|
||||
### Global expressions
|
||||
|
||||
The following [Handlebars template](https://handlebarsjs.com/guide/) expressions for `prefix`, `suffix` and `value`
|
||||
attributes are available:
|
||||
|
||||
| Expression | Output |
|
||||
|--------------------------|----------------------|
|
||||
| `{{branch}}` | `master` |
|
||||
| `{{tag}}` | `v1.2.3` |
|
||||
| `{{sha}}` | `90dd603` |
|
||||
|
||||
```yaml
|
||||
tags: |
|
||||
# dynamically set the branch name as a prefix
|
||||
type=sha,prefix={{branch}}-
|
||||
# dynamically set the branch name and sha as a custom tag
|
||||
type=raw,value=mytag-{{branch}}-{{sha}}
|
||||
```
|
||||
|
||||
### Major version zero
|
||||
|
||||
Major version zero (`0.y.z`) is for initial development and **may** change at any time. This means the public API
|
||||
[**should not** be considered stable](https://semver.org/#spec-item-4).
|
||||
|
||||
In this case, Docker tag `0` **should not** be generated if you're using [`type=semver`](#typesemver) with `{{major}}`
|
||||
pattern. You can manage this behavior like this:
|
||||
|
||||
```yaml
|
||||
# refs/tags/v0.1.2
|
||||
tags: |
|
||||
# output 0.1.2
|
||||
type=semver,pattern={{version}}
|
||||
# output 0.1
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
# disabled if major zero
|
||||
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
|
||||
```
|
||||
|
||||
### Overwrite labels
|
||||
|
||||
If some of the [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
|
||||
|
@@ -89,7 +89,8 @@ describe('null', () => {
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=sha`
|
||||
`type=sha`,
|
||||
`type=raw,{{branch}}`,
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
@@ -586,6 +587,36 @@ describe('push', () => {
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'push17',
|
||||
'event_push_defbranch.env',
|
||||
{
|
||||
images: ['user/app'],
|
||||
tags: [
|
||||
`type=raw,value=mytag-{{branch}}`,
|
||||
`type=raw,value=mytag-{{tag}}`
|
||||
],
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'mytag-master',
|
||||
partial: ['mytag-'],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'user/app:mytag-master',
|
||||
'user/app:mytag-'
|
||||
],
|
||||
[
|
||||
"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=mytag-master",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
]
|
||||
])('given %p with %p event', tagsLabelsTest);
|
||||
});
|
||||
@@ -1210,6 +1241,35 @@ describe('tag', () => {
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
],
|
||||
[
|
||||
'tag20',
|
||||
'event_tag_v1.1.1.env',
|
||||
{
|
||||
images: ['org/app', 'ghcr.io/user/app'],
|
||||
tags: [
|
||||
`type=raw,{{tag}}-{{sha}}-foo`
|
||||
]
|
||||
} as Inputs,
|
||||
{
|
||||
main: 'v1.1.1-90dd603-foo',
|
||||
partial: [],
|
||||
latest: false
|
||||
} as Version,
|
||||
[
|
||||
'org/app:v1.1.1-90dd603-foo',
|
||||
'ghcr.io/user/app:v1.1.1-90dd603-foo'
|
||||
],
|
||||
[
|
||||
"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=v1.1.1-90dd603-foo",
|
||||
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
|
||||
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
|
||||
"org.opencontainers.image.licenses=MIT"
|
||||
]
|
||||
]
|
||||
])('given %p with %p event', tagsLabelsTest);
|
||||
});
|
||||
|
161
dist/index.js
generated
vendored
161
dist/index.js
generated
vendored
@@ -393,7 +393,7 @@ class Meta {
|
||||
latest: undefined
|
||||
};
|
||||
for (const tag of this.tags) {
|
||||
if (tag.attrs['enable'] == 'false') {
|
||||
if (!/true/i.test(tag.attrs['enable'])) {
|
||||
continue;
|
||||
}
|
||||
switch (tag.type) {
|
||||
@@ -446,21 +446,12 @@ class Meta {
|
||||
return version;
|
||||
}
|
||||
const currentDate = this.date;
|
||||
const vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])({
|
||||
const vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])({
|
||||
date: function (format) {
|
||||
return moment_1.default(currentDate).utc().format(format);
|
||||
}
|
||||
}), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
procSemver(version, tag) {
|
||||
if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) {
|
||||
@@ -468,7 +459,7 @@ class Meta {
|
||||
}
|
||||
let vraw;
|
||||
if (tag.attrs['value'].length > 0) {
|
||||
vraw = tag.attrs['value'];
|
||||
vraw = this.setGlobalExp(tag.attrs['value']);
|
||||
}
|
||||
else {
|
||||
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
@@ -482,22 +473,13 @@ class Meta {
|
||||
includePrerelease: true
|
||||
});
|
||||
if (semver.prerelease(vraw)) {
|
||||
vraw = this.setFlavor(handlebars.compile('{{version}}')(sver), tag);
|
||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
||||
}
|
||||
else {
|
||||
vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||
latest = true;
|
||||
}
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
|
||||
}
|
||||
procMatch(version, tag) {
|
||||
if (!/^refs\/tags\//.test(this.context.ref) && tag.attrs['value'].length == 0) {
|
||||
@@ -505,7 +487,7 @@ class Meta {
|
||||
}
|
||||
let vraw;
|
||||
if (tag.attrs['value'].length > 0) {
|
||||
vraw = tag.attrs['value'];
|
||||
vraw = this.setGlobalExp(tag.attrs['value']);
|
||||
}
|
||||
else {
|
||||
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
@@ -527,66 +509,29 @@ class Meta {
|
||||
core.warning(`Group ${tag.attrs['group']} does not exist for ${tag.attrs['pattern']} pattern.`);
|
||||
return version;
|
||||
}
|
||||
vraw = this.setFlavor(tmatch[tag.attrs['group']], tag);
|
||||
latest = true;
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
vraw = this.setValue(tmatch[tag.attrs['group']], tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
|
||||
}
|
||||
procRefBranch(version, tag) {
|
||||
if (!/^refs\/heads\//.test(this.context.ref)) {
|
||||
return version;
|
||||
}
|
||||
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
const vraw = this.setValue(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
procRefTag(version, tag) {
|
||||
if (!/^refs\/tags\//.test(this.context.ref)) {
|
||||
return version;
|
||||
}
|
||||
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
const vraw = this.setValue(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
|
||||
}
|
||||
procRefPr(version, tag) {
|
||||
if (!/^refs\/pull\//.test(this.context.ref)) {
|
||||
return version;
|
||||
}
|
||||
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
procEdge(version, tag) {
|
||||
if (!/^refs\/heads\//.test(this.context.ref)) {
|
||||
@@ -599,62 +544,70 @@ class Meta {
|
||||
if (tag.attrs['branch'] === val) {
|
||||
val = 'edge';
|
||||
}
|
||||
const vraw = this.setFlavor(val, tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
const vraw = this.setValue(val, tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
procRaw(version, tag) {
|
||||
const vraw = this.setFlavor(tag.attrs['value'], tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
return version;
|
||||
const vraw = this.setValue(this.setGlobalExp(tag.attrs['value']), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
procSha(version, tag) {
|
||||
if (!this.context.sha) {
|
||||
return version;
|
||||
}
|
||||
const vraw = this.setFlavor(this.context.sha.substr(0, 7), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
const vraw = this.setValue(this.context.sha.substr(0, 7), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
static setVersion(version, val, latest) {
|
||||
if (val.length == 0) {
|
||||
return version;
|
||||
}
|
||||
else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
if (version.main == undefined) {
|
||||
version.main = val;
|
||||
}
|
||||
else if (val !== version.main) {
|
||||
version.partial.push(val);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
version.latest = latest;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
setFlavor(val, tag) {
|
||||
setValue(val, tag) {
|
||||
if (tag.attrs.hasOwnProperty('prefix')) {
|
||||
val = `${tag.attrs['prefix']}${val}`;
|
||||
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
||||
}
|
||||
else if (this.flavor.prefix.length > 0) {
|
||||
val = `${this.flavor.prefix}${val}`;
|
||||
val = `${this.setGlobalExp(this.flavor.prefix)}${val}`;
|
||||
}
|
||||
if (tag.attrs.hasOwnProperty('suffix')) {
|
||||
val = `${val}${tag.attrs['suffix']}`;
|
||||
val = `${val}${this.setGlobalExp(tag.attrs['suffix'])}`;
|
||||
}
|
||||
else if (this.flavor.suffix.length > 0) {
|
||||
val = `${val}${this.flavor.suffix}`;
|
||||
val = `${val}${this.setGlobalExp(this.flavor.suffix)}`;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
setGlobalExp(val) {
|
||||
const ctx = this.context;
|
||||
return handlebars.compile(val)({
|
||||
branch: function () {
|
||||
if (!/^refs\/heads\//.test(ctx.ref)) {
|
||||
return '';
|
||||
}
|
||||
return ctx.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-');
|
||||
},
|
||||
tag: function () {
|
||||
if (!/^refs\/tags\//.test(ctx.ref)) {
|
||||
return '';
|
||||
}
|
||||
return ctx.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
},
|
||||
sha: function () {
|
||||
return ctx.sha.substr(0, 7);
|
||||
}
|
||||
});
|
||||
}
|
||||
getTags() {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
|
164
src/meta.ts
164
src/meta.ts
@@ -44,7 +44,7 @@ export class Meta {
|
||||
};
|
||||
|
||||
for (const tag of this.tags) {
|
||||
if (tag.attrs['enable'] == 'false') {
|
||||
if (!/true/i.test(tag.attrs['enable'])) {
|
||||
continue;
|
||||
}
|
||||
switch (tag.type) {
|
||||
@@ -99,7 +99,7 @@ export class Meta {
|
||||
}
|
||||
|
||||
const currentDate = this.date;
|
||||
const vraw = this.setFlavor(
|
||||
const vraw = this.setValue(
|
||||
handlebars.compile(tag.attrs['pattern'])({
|
||||
date: function (format) {
|
||||
return moment(currentDate).utc().format(format);
|
||||
@@ -108,16 +108,7 @@ export class Meta {
|
||||
tag
|
||||
);
|
||||
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procSemver(version: Version, tag: tcl.Tag): Version {
|
||||
@@ -127,7 +118,7 @@ export class Meta {
|
||||
|
||||
let vraw: string;
|
||||
if (tag.attrs['value'].length > 0) {
|
||||
vraw = tag.attrs['value'];
|
||||
vraw = this.setGlobalExp(tag.attrs['value']);
|
||||
} else {
|
||||
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
}
|
||||
@@ -141,21 +132,13 @@ export class Meta {
|
||||
includePrerelease: true
|
||||
});
|
||||
if (semver.prerelease(vraw)) {
|
||||
vraw = this.setFlavor(handlebars.compile('{{version}}')(sver), tag);
|
||||
vraw = this.setValue(handlebars.compile('{{version}}')(sver), tag);
|
||||
} else {
|
||||
vraw = this.setFlavor(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||
vraw = this.setValue(handlebars.compile(tag.attrs['pattern'])(sver), tag);
|
||||
latest = true;
|
||||
}
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procMatch(version: Version, tag: tcl.Tag): Version {
|
||||
@@ -165,7 +148,7 @@ export class Meta {
|
||||
|
||||
let vraw: string;
|
||||
if (tag.attrs['value'].length > 0) {
|
||||
vraw = tag.attrs['value'];
|
||||
vraw = this.setGlobalExp(tag.attrs['value']);
|
||||
} else {
|
||||
vraw = this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
}
|
||||
@@ -187,73 +170,32 @@ export class Meta {
|
||||
return version;
|
||||
}
|
||||
|
||||
vraw = this.setFlavor(tmatch[tag.attrs['group']], tag);
|
||||
latest = true;
|
||||
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? latest : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
vraw = this.setValue(tmatch[tag.attrs['group']], tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procRefBranch(version: Version, tag: tcl.Tag): Version {
|
||||
if (!/^refs\/heads\//.test(this.context.ref)) {
|
||||
return version;
|
||||
}
|
||||
|
||||
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
const vraw = this.setValue(this.context.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-'), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procRefTag(version: Version, tag: tcl.Tag): Version {
|
||||
if (!/^refs\/tags\//.test(this.context.ref)) {
|
||||
return version;
|
||||
}
|
||||
|
||||
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
const vraw = this.setValue(this.context.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-'), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procRefPr(version: Version, tag: tcl.Tag): Version {
|
||||
if (!/^refs\/pull\//.test(this.context.ref)) {
|
||||
return version;
|
||||
}
|
||||
|
||||
const vraw = this.setFlavor(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procEdge(version: Version, tag: tcl.Tag): Version {
|
||||
@@ -269,65 +211,73 @@ export class Meta {
|
||||
val = 'edge';
|
||||
}
|
||||
|
||||
const vraw = this.setFlavor(val, tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
const vraw = this.setValue(val, tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procRaw(version: Version, tag: tcl.Tag): Version {
|
||||
const vraw = this.setFlavor(tag.attrs['value'], tag);
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
}
|
||||
|
||||
return version;
|
||||
const vraw = this.setValue(this.setGlobalExp(tag.attrs['value']), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
private procSha(version: Version, tag: tcl.Tag): Version {
|
||||
if (!this.context.sha) {
|
||||
return version;
|
||||
}
|
||||
const vraw = this.setValue(this.context.sha.substr(0, 7), tag);
|
||||
return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true');
|
||||
}
|
||||
|
||||
const vraw = this.setFlavor(this.context.sha.substr(0, 7), tag);
|
||||
private static setVersion(version: Version, val: string, latest: boolean): Version {
|
||||
if (val.length == 0) {
|
||||
return version;
|
||||
}
|
||||
if (version.main == undefined) {
|
||||
version.main = vraw;
|
||||
} else if (vraw !== version.main) {
|
||||
version.partial.push(vraw);
|
||||
version.main = val;
|
||||
} else if (val !== version.main) {
|
||||
version.partial.push(val);
|
||||
}
|
||||
if (version.latest == undefined) {
|
||||
version.latest = this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true';
|
||||
version.latest = latest;
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
private setFlavor(val: string, tag: tcl.Tag): string {
|
||||
private setValue(val: string, tag: tcl.Tag): string {
|
||||
if (tag.attrs.hasOwnProperty('prefix')) {
|
||||
val = `${tag.attrs['prefix']}${val}`;
|
||||
val = `${this.setGlobalExp(tag.attrs['prefix'])}${val}`;
|
||||
} else if (this.flavor.prefix.length > 0) {
|
||||
val = `${this.flavor.prefix}${val}`;
|
||||
val = `${this.setGlobalExp(this.flavor.prefix)}${val}`;
|
||||
}
|
||||
if (tag.attrs.hasOwnProperty('suffix')) {
|
||||
val = `${val}${tag.attrs['suffix']}`;
|
||||
val = `${val}${this.setGlobalExp(tag.attrs['suffix'])}`;
|
||||
} else if (this.flavor.suffix.length > 0) {
|
||||
val = `${val}${this.flavor.suffix}`;
|
||||
val = `${val}${this.setGlobalExp(this.flavor.suffix)}`;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
private setGlobalExp(val): string {
|
||||
const ctx = this.context;
|
||||
return handlebars.compile(val)({
|
||||
branch: function () {
|
||||
if (!/^refs\/heads\//.test(ctx.ref)) {
|
||||
return '';
|
||||
}
|
||||
return ctx.ref.replace(/^refs\/heads\//g, '').replace(/[^a-zA-Z0-9._-]+/g, '-');
|
||||
},
|
||||
tag: function () {
|
||||
if (!/^refs\/tags\//.test(ctx.ref)) {
|
||||
return '';
|
||||
}
|
||||
return ctx.ref.replace(/^refs\/tags\//g, '').replace(/\//g, '-');
|
||||
},
|
||||
sha: function () {
|
||||
return ctx.sha.substr(0, 7);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public getTags(): Array<string> {
|
||||
if (!this.version.main) {
|
||||
return [];
|
||||
|
12
yarn.lock
12
yarn.lock
@@ -1701,9 +1701,9 @@ has@^1.0.3:
|
||||
function-bind "^1.1.1"
|
||||
|
||||
hosted-git-info@^2.1.4:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488"
|
||||
integrity sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==
|
||||
version "2.8.9"
|
||||
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
|
||||
integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==
|
||||
|
||||
html-encoding-sniffer@^2.0.1:
|
||||
version "2.0.1"
|
||||
@@ -2546,9 +2546,9 @@ lodash.sortby@^4.7.0:
|
||||
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
|
||||
|
||||
lodash@^4.17.19:
|
||||
version "4.17.20"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
|
||||
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
|
||||
version "4.17.21"
|
||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||
|
||||
lru-cache@^6.0.0:
|
||||
version "6.0.0"
|
||||
|
Reference in New Issue
Block a user