Skip to content

Commit

Permalink
Handle global expressions (#71)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max committed May 7, 2021
1 parent e09df4d commit 5e6d515
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 211 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -38,6 +38,7 @@ ___
* [`type=sha`](#typesha)
* [Notes](#notes)
* [Latest tag](#latest-tag)
* [Global expressions](#global-expressions)
* [Overwrite labels](#overwrite-labels)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [Contributing](#contributing)
Expand Down Expand Up @@ -554,6 +555,25 @@ tags: |
* [`type=semver,pattern=...`](#typesemver)
* [`type=match,pattern=...`](#typematch)
### Global expressions
The following [Handlebars template](https://handlebarsjs.com/guide/) expressions for `prefix`, `suffix` and `value`
attributes are available:
| Expression | Output |
|--------------------------|----------------------|
| `{{branch}}` | `master` |
| `{{tag}}` | `v1.2.3` |
| `{{sha}}` | `90dd603` |
```yaml
tags: |
# dynamically set the branch name as a prefix
type=sha,prefix={{branch}}-
# dynamically set the branch name and sha as a custom tag
type=raw,value=mytag-{{branch}}-{{sha}}
```
### Overwrite labels
If some of the [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
Expand Down
62 changes: 61 additions & 1 deletion __tests__/meta.test.ts
Expand Up @@ -89,7 +89,8 @@ describe('null', () => {
{
images: ['user/app'],
tags: [
`type=sha`
`type=sha`,
`type=raw,{{branch}}`,
]
} as Inputs,
{
Expand Down Expand Up @@ -586,6 +587,36 @@ describe('push', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'push17',
'event_push_defbranch.env',
{
images: ['user/app'],
tags: [
`type=raw,value=mytag-{{branch}}`,
`type=raw,value=mytag-{{tag}}`
],
} as Inputs,
{
main: 'mytag-master',
partial: ['mytag-'],
latest: false
} as Version,
[
'user/app:mytag-master',
'user/app:mytag-'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=mytag-master",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest);
});
Expand Down Expand Up @@ -1210,6 +1241,35 @@ describe('tag', () => {
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
],
[
'tag20',
'event_tag_v1.1.1.env',
{
images: ['org/app', 'ghcr.io/user/app'],
tags: [
`type=raw,{{tag}}-{{sha}}-foo`
]
} as Inputs,
{
main: 'v1.1.1-90dd603-foo',
partial: [],
latest: false
} as Version,
[
'org/app:v1.1.1-90dd603-foo',
'ghcr.io/user/app:v1.1.1-90dd603-foo'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=v1.1.1-90dd603-foo",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=90dd6032fac8bda1b6c4436a2e65de27961ed071",
"org.opencontainers.image.licenses=MIT"
]
]
])('given %p with %p event', tagsLabelsTest);
});
Expand Down
159 changes: 56 additions & 103 deletions dist/index.js

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

0 comments on commit 5e6d515

Please sign in to comment.