Skip to content

Commit

Permalink
Add global expression "date"
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Aug 19, 2021
1 parent a67f45c commit e4f5485
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -612,6 +612,7 @@ attributes are available:
| `{{branch}}` | `master` |
| `{{tag}}` | `v1.2.3` |
| `{{sha}}` | `90dd603` |
| `{{date 'YYYYMMDD'}}` | `20210326` |
```yaml
tags: |
Expand Down
4 changes: 3 additions & 1 deletion __tests__/meta.test.ts
Expand Up @@ -585,16 +585,18 @@ describe('push', () => {
images: ['user/app'],
tags: [
`type=raw,value=mytag-{{branch}}`,
`type=raw,value=mytag-{{date 'YYYYMMDD'}}`,
`type=raw,value=mytag-{{tag}}`
],
} as Inputs,
{
main: 'mytag-master',
partial: ['mytag-'],
partial: ['mytag-20200110', 'mytag-'],
latest: false
} as Version,
[
'user/app:mytag-master',
'user/app:mytag-20200110',
'user/app:mytag-'
],
[
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/meta.ts
Expand Up @@ -323,6 +323,7 @@ export class Meta {

private setGlobalExp(val): string {
const ctx = this.context;
const currentDate = this.date;
return handlebars.compile(val)({
branch: function () {
if (!/^refs\/heads\//.test(ctx.ref)) {
Expand All @@ -338,6 +339,9 @@ export class Meta {
},
sha: function () {
return ctx.sha.substr(0, 7);
},
date: function (format) {
return moment(currentDate).utc().format(format);
}
});
}
Expand Down

0 comments on commit e4f5485

Please sign in to comment.