Skip to content

Commit 906ecf0

Browse files
authored
Merge pull request #489 from crazy-max/labels-template
global expressions support for labels and annotations
2 parents b53be03 + f78c299 commit 906ecf0

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ jobs:
269269
images: |
270270
${{ env.DOCKER_IMAGE }}
271271
ghcr.io/name/app
272+
labels: |
273+
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
272274
tags: |
273275
type=sha
274276
type=raw,value=gexp-branch-{{branch}}

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,8 @@ Each tags `type` attribute has a default priority:
818818
### Global expressions
819819

820820
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions
821-
for `prefix`, `suffix`, `value` and `enable` attributes are available:
821+
for `prefix`, `suffix`, `value` and `enable` attributes of `tags` input are
822+
available:
822823

823824
```yaml
824825
tags: |
@@ -828,6 +829,13 @@ tags: |
828829
type=raw,value=mytag-{{branch}}-{{sha}}
829830
```
830831

832+
They can also be applied to `labels` and `annotations` inputs:
833+
834+
```yaml
835+
labels: |
836+
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
837+
```
838+
831839
#### `{{branch}}`
832840

833841
Returns the branch name that triggered the workflow run. Will be empty if not

__tests__/meta.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,9 @@ describe('push', () => {
785785
`type=raw,value=mytag-baseref-{{base_ref}}`,
786786
`type=raw,value=mytag-defbranch,enable={{is_default_branch}}`
787787
],
788+
labels: [
789+
"org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}"
790+
]
788791
} as Inputs,
789792
{
790793
main: 'mytag-master',

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/meta.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export class Meta {
372372
return val;
373373
}
374374

375-
private setGlobalExp(val): string {
375+
private setGlobalExp(val: string): string {
376376
const context = this.context;
377377
const currentDate = this.date;
378378
const commitDate = this.context.commitDate;
@@ -517,7 +517,9 @@ export class Meta {
517517
`org.opencontainers.image.revision=${this.context.sha || ''}`,
518518
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
519519
];
520-
res.push(...extra);
520+
extra.forEach(label => {
521+
res.push(this.setGlobalExp(label));
522+
});
521523

522524
return Array.from(
523525
new Map<string, string>(

0 commit comments

Comments
 (0)