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

remove support of default branch global exp for push tag events #197

Merged
merged 1 commit into from Apr 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -675,20 +675,26 @@ 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}}`

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>'}}`

Expand Down
7 changes: 2 additions & 5 deletions __tests__/meta.test.ts
Expand Up @@ -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",
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.

12 changes: 9 additions & 3 deletions src/meta.ts
Expand Up @@ -369,16 +369,22 @@ 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;
}
return '';
},
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;
}
Expand Down