remove support of default branch global exp for push tag events

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-04-26 14:47:46 +02:00
parent 0978a0678a
commit aca951f8f5
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
5 changed files with 26 additions and 17 deletions

View File

@ -675,12 +675,18 @@ Returns the short commit SHA that triggered the workflow run (e.g., `90dd603`).
Returns the base ref or target branch of the pull request that triggered the
workflow run. Will be empty for a branch reference:
| Event | Ref | Output |
|-----------------|-------------------------------|--------------------|
| `pull_request` | `refs/pull/2/merge` | `master` |
| `push` | `refs/heads/master` | |
| `push` | `refs/heads/my/branch` | |
| `push tag` | `refs/tags/v1.2.3` | `master` |
| Event | Ref | Output |
|----------------|-------------------------------|--------------------|
| `pull_request` | `refs/pull/2/merge` | `master` |
| `push` | `refs/heads/master` | |
| `push` | `refs/heads/my/branch` | |
| `push tag`* | `refs/tags/v1.2.3` | `master` |
> *`base_ref` is available in the push payload but doesn't always seem to
> return the expected branch when the push tag event occurs. It's also
> [not documented in GitHub docs](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push).
> We keep it for backward compatibility, but it's **not recommended relying on it**.
> More context in [#192](https://github.com/docker/metadata-action/pull/192#discussion_r854673012).
#### `{{is_default_branch}}`
@ -688,7 +694,7 @@ Returns `true` if the branch that triggered the workflow run is the default
one, otherwise `false`.
Will compare against the branch name that triggered the workflow run or the
base ref or target branch for a pull request or a tag.
base ref for a pull request.
#### `{{date '<format>'}}`

View File

@ -1332,18 +1332,15 @@ describe('tag', () => {
{
main: 'v1.1.1-860c190-foo',
partial: [
'master-foo',
'defbranch-foo'
'master-foo'
],
latest: false
} as Version,
[
'org/app:v1.1.1-860c190-foo',
'org/app:master-foo',
'org/app:defbranch-foo',
'ghcr.io/user/app:v1.1.1-860c190-foo',
'ghcr.io/user/app:master-foo',
'ghcr.io/user/app:defbranch-foo'
'ghcr.io/user/app:master-foo'
],
[
"org.opencontainers.image.title=Hello-World",

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -369,6 +369,8 @@ export class Meta {
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
return ctx.payload.base_ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
}
// FIXME: keep this for backward compatibility even if doesn't always seem
// to return the expected branch. See the comment below.
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
return ctx.payload.pull_request.base.ref;
}
@ -376,9 +378,13 @@ export class Meta {
},
is_default_branch: function () {
let branch = ctx.ref.replace(/^refs\/heads\//g, '');
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
}
// TODO: "base_ref" is available in the push payload but doesn't always seem to
// return the expected branch when the push tag event occurs. It's also not
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
// if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
// branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
// }
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
branch = ctx.payload.pull_request.base.ref;
}