Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global expressions support for labels and annotations #489

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ jobs:
images: |
${{ env.DOCKER_IMAGE }}
ghcr.io/name/app
labels: |
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
tags: |
type=sha
type=raw,value=gexp-branch-{{branch}}
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ Each tags `type` attribute has a default priority:
### Global expressions

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

```yaml
tags: |
Expand All @@ -828,6 +829,13 @@ tags: |
type=raw,value=mytag-{{branch}}-{{sha}}
```

They can also be applied to `labels` and `annotations` inputs:

```yaml
labels: |
org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}
```

#### `{{branch}}`

Returns the branch name that triggered the workflow run. Will be empty if not
Expand Down
3 changes: 3 additions & 0 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,9 @@ describe('push', () => {
`type=raw,value=mytag-baseref-{{base_ref}}`,
`type=raw,value=mytag-defbranch,enable={{is_default_branch}}`
],
labels: [
"org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}}"
]
} as Inputs,
{
main: 'mytag-master',
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class Meta {
return val;
}

private setGlobalExp(val): string {
private setGlobalExp(val: string): string {
const context = this.context;
const currentDate = this.date;
const commitDate = this.context.commitDate;
Expand Down Expand Up @@ -517,7 +517,9 @@ export class Meta {
`org.opencontainers.image.revision=${this.context.sha || ''}`,
`org.opencontainers.image.licenses=${this.repo.license?.spdx_id || ''}`
];
res.push(...extra);
extra.forEach(label => {
res.push(this.setGlobalExp(label));
});

return Array.from(
new Map<string, string>(
Expand Down
Loading