mirror of
https://github.com/docker/metadata-action.git
synced 2024-12-22 23:55:38 +00:00
Merge pull request #121 from crazy-max/data-expr
Add global expression "date"
This commit is contained in:
commit
03cec7cbca
|
@ -612,6 +612,7 @@ attributes are available:
|
||||||
| `{{branch}}` | `master` |
|
| `{{branch}}` | `master` |
|
||||||
| `{{tag}}` | `v1.2.3` |
|
| `{{tag}}` | `v1.2.3` |
|
||||||
| `{{sha}}` | `90dd603` |
|
| `{{sha}}` | `90dd603` |
|
||||||
|
| `{{date 'YYYYMMDD'}}` | `20210326` |
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
tags: |
|
tags: |
|
||||||
|
|
|
@ -585,16 +585,18 @@ describe('push', () => {
|
||||||
images: ['user/app'],
|
images: ['user/app'],
|
||||||
tags: [
|
tags: [
|
||||||
`type=raw,value=mytag-{{branch}}`,
|
`type=raw,value=mytag-{{branch}}`,
|
||||||
|
`type=raw,value=mytag-{{date 'YYYYMMDD'}}`,
|
||||||
`type=raw,value=mytag-{{tag}}`
|
`type=raw,value=mytag-{{tag}}`
|
||||||
],
|
],
|
||||||
} as Inputs,
|
} as Inputs,
|
||||||
{
|
{
|
||||||
main: 'mytag-master',
|
main: 'mytag-master',
|
||||||
partial: ['mytag-'],
|
partial: ['mytag-20200110', 'mytag-'],
|
||||||
latest: false
|
latest: false
|
||||||
} as Version,
|
} as Version,
|
||||||
[
|
[
|
||||||
'user/app:mytag-master',
|
'user/app:mytag-master',
|
||||||
|
'user/app:mytag-20200110',
|
||||||
'user/app:mytag-'
|
'user/app:mytag-'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|
4
dist/index.js
generated
vendored
4
dist/index.js
generated
vendored
|
@ -682,6 +682,7 @@ class Meta {
|
||||||
}
|
}
|
||||||
setGlobalExp(val) {
|
setGlobalExp(val) {
|
||||||
const ctx = this.context;
|
const ctx = this.context;
|
||||||
|
const currentDate = this.date;
|
||||||
return handlebars.compile(val)({
|
return handlebars.compile(val)({
|
||||||
branch: function () {
|
branch: function () {
|
||||||
if (!/^refs\/heads\//.test(ctx.ref)) {
|
if (!/^refs\/heads\//.test(ctx.ref)) {
|
||||||
|
@ -697,6 +698,9 @@ class Meta {
|
||||||
},
|
},
|
||||||
sha: function () {
|
sha: function () {
|
||||||
return ctx.sha.substr(0, 7);
|
return ctx.sha.substr(0, 7);
|
||||||
|
},
|
||||||
|
date: function (format) {
|
||||||
|
return moment_1.default(currentDate).utc().format(format);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,6 +323,7 @@ export class Meta {
|
||||||
|
|
||||||
private setGlobalExp(val): string {
|
private setGlobalExp(val): string {
|
||||||
const ctx = this.context;
|
const ctx = this.context;
|
||||||
|
const currentDate = this.date;
|
||||||
return handlebars.compile(val)({
|
return handlebars.compile(val)({
|
||||||
branch: function () {
|
branch: function () {
|
||||||
if (!/^refs\/heads\//.test(ctx.ref)) {
|
if (!/^refs\/heads\//.test(ctx.ref)) {
|
||||||
|
@ -338,6 +339,9 @@ export class Meta {
|
||||||
},
|
},
|
||||||
sha: function () {
|
sha: function () {
|
||||||
return ctx.sha.substr(0, 7);
|
return ctx.sha.substr(0, 7);
|
||||||
|
},
|
||||||
|
date: function (format) {
|
||||||
|
return moment(currentDate).utc().format(format);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue