Skip to content

Commit 72fe50e

Browse files
authored
Merge pull request #197 from crazy-max/rm-baseref-def-branch
remove support of default branch global exp for push tag events
2 parents 0978a06 + aca951f commit 72fe50e

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,20 +675,26 @@ Returns the short commit SHA that triggered the workflow run (e.g., `90dd603`).
675675
Returns the base ref or target branch of the pull request that triggered the
676676
workflow run. Will be empty for a branch reference:
677677

678-
| Event | Ref | Output |
679-
|-----------------|-------------------------------|--------------------|
680-
| `pull_request` | `refs/pull/2/merge` | `master` |
681-
| `push` | `refs/heads/master` | |
682-
| `push` | `refs/heads/my/branch` | |
683-
| `push tag` | `refs/tags/v1.2.3` | `master` |
678+
| Event | Ref | Output |
679+
|----------------|-------------------------------|--------------------|
680+
| `pull_request` | `refs/pull/2/merge` | `master` |
681+
| `push` | `refs/heads/master` | |
682+
| `push` | `refs/heads/my/branch` | |
683+
| `push tag`* | `refs/tags/v1.2.3` | `master` |
684+
685+
> *`base_ref` is available in the push payload but doesn't always seem to
686+
> return the expected branch when the push tag event occurs. It's also
687+
> [not documented in GitHub docs](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push).
688+
> We keep it for backward compatibility, but it's **not recommended relying on it**.
689+
> More context in [#192](https://github.com/docker/metadata-action/pull/192#discussion_r854673012).
684690

685691
#### `{{is_default_branch}}`
686692

687693
Returns `true` if the branch that triggered the workflow run is the default
688694
one, otherwise `false`.
689695

690696
Will compare against the branch name that triggered the workflow run or the
691-
base ref or target branch for a pull request or a tag.
697+
base ref for a pull request.
692698

693699
#### `{{date '<format>'}}`
694700

__tests__/meta.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,18 +1332,15 @@ describe('tag', () => {
13321332
{
13331333
main: 'v1.1.1-860c190-foo',
13341334
partial: [
1335-
'master-foo',
1336-
'defbranch-foo'
1335+
'master-foo'
13371336
],
13381337
latest: false
13391338
} as Version,
13401339
[
13411340
'org/app:v1.1.1-860c190-foo',
13421341
'org/app:master-foo',
1343-
'org/app:defbranch-foo',
13441342
'ghcr.io/user/app:v1.1.1-860c190-foo',
1345-
'ghcr.io/user/app:master-foo',
1346-
'ghcr.io/user/app:defbranch-foo'
1343+
'ghcr.io/user/app:master-foo'
13471344
],
13481345
[
13491346
"org.opencontainers.image.title=Hello-World",

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,16 +369,22 @@ export class Meta {
369369
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
370370
return ctx.payload.base_ref.replace(/^refs\/heads\//g, '').replace(/\//g, '-');
371371
}
372+
// FIXME: keep this for backward compatibility even if doesn't always seem
373+
// to return the expected branch. See the comment below.
372374
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
373375
return ctx.payload.pull_request.base.ref;
374376
}
375377
return '';
376378
},
377379
is_default_branch: function () {
378380
let branch = ctx.ref.replace(/^refs\/heads\//g, '');
379-
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
380-
branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
381-
}
381+
// TODO: "base_ref" is available in the push payload but doesn't always seem to
382+
// return the expected branch when the push tag event occurs. It's also not
383+
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
384+
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
385+
// if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
386+
// branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
387+
// }
382388
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
383389
branch = ctx.payload.pull_request.base.ref;
384390
}

0 commit comments

Comments
 (0)