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 329239e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
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: 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 329239e

Please sign in to comment.