-
Notifications
You must be signed in to change notification settings - Fork 115
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
is_default_branch global expression #192
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -32,6 +32,12 @@ ___ | |||
* [Notes](#notes) | ||||
* [Latest tag](#latest-tag) | ||||
* [Global expressions](#global-expressions) | ||||
* [`{{branch}}`](#branch) | ||||
* [`{{tag}}`](#tag) | ||||
* [`{{sha}}`](#sha) | ||||
* [`{{base_ref}}`](#base_ref) | ||||
* [`{{is_default_branch}}`](#is_default_branch) | ||||
* [`{{date '<format>'}}`](#date-format) | ||||
* [Major version zero](#major-version-zero) | ||||
* [JSON output object](#json-output-object) | ||||
* [Overwrite labels](#overwrite-labels) | ||||
|
@@ -232,7 +238,7 @@ Content of `${{ steps.meta.outputs.bake-file }}` file will look like this with ` | |||
"org.opencontainers.image.source": "https://github.com/octocat/Hello-World", | ||||
"org.opencontainers.image.version": "1.2.3", | ||||
"org.opencontainers.image.created": "2020-01-10T00:30:00.000Z", | ||||
"org.opencontainers.image.revision": "90dd6032fac8bda1b6c4436a2e65de27961ed071", | ||||
"org.opencontainers.image.revision": "860c1904a1ce19322e91ac35af1ab07466440c37", | ||||
"org.opencontainers.image.licenses": "MIT" | ||||
}, | ||||
"args": { | ||||
|
@@ -605,26 +611,28 @@ tags: | | |||
* [`type=semver,pattern=...`](#typesemver) | ||||
* [`type=match,pattern=...`](#typematch) | ||||
|
||||
For conditionally tagging with latest for a specific branch name, e.g. if your default branch name | ||||
is not `master`, use `type=raw` with a boolean expression: | ||||
For conditionally tagging with latest for a specific branch name, e.g. if your | ||||
default branch name is not `master`, use `type=raw` with a boolean expression: | ||||
|
||||
```yaml | ||||
tags: | | ||||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | ||||
# set latest tag for master branch | ||||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} | ||||
``` | ||||
|
||||
### Global expressions | ||||
You can also use the [`{{is_default_branch}}` global expression](#is_default_branch) | ||||
to conditionally tag with latest for the default branch: | ||||
|
||||
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions for `prefix`, `suffix` and `value` | ||||
attributes are available: | ||||
```yaml | ||||
tags: | | ||||
# set latest tag for default branch | ||||
type=raw,value=latest,enable={{is_default_branch}} | ||||
``` | ||||
|
||||
| Expression | Output | | ||||
|--------------------------|----------------------| | ||||
| `{{branch}}` | `master` | | ||||
| `{{tag}}` | `v1.2.3` | | ||||
| `{{sha}}` | `90dd603` | | ||||
| `{{base_ref}}` | `master` | | ||||
| `{{date 'YYYYMMDD'}}` | `20210326` | | ||||
### Global expressions | ||||
|
||||
The following [Handlebars' template](https://handlebarsjs.com/guide/) expressions | ||||
for `prefix`, `suffix`, `value` and `enable` attributes are available: | ||||
|
||||
```yaml | ||||
tags: | | ||||
|
@@ -634,6 +642,63 @@ tags: | | |||
type=raw,value=mytag-{{branch}}-{{sha}} | ||||
``` | ||||
|
||||
#### `{{branch}}` | ||||
|
||||
Returns the branch name that triggered the workflow run. Will be empty if not | ||||
a branch reference: | ||||
|
||||
| Event | Ref | Output | | ||||
|-----------------|-------------------------------|---------------------| | ||||
| `pull_request` | `refs/pull/2/merge` | | | ||||
| `push` | `refs/heads/master` | `master` | | ||||
| `push` | `refs/heads/my/branch` | `my-branch` | | ||||
| `push tag` | `refs/tags/v1.2.3` | | | ||||
|
||||
#### `{{tag}}` | ||||
|
||||
Returns the tag name that triggered the workflow run. Will be empty if not a | ||||
tag reference: | ||||
|
||||
| Event | Ref | Output | | ||||
|-----------------|-------------------------------|--------------------| | ||||
| `pull_request` | `refs/pull/2/merge` | | | ||||
| `push` | `refs/heads/master` | | | ||||
| `push` | `refs/heads/my/branch` | | | ||||
| `push tag` | `refs/tags/v1.2.3` | `v1.2.3` | | ||||
|
||||
#### `{{sha}}` | ||||
|
||||
Returns the short commit SHA that triggered the workflow run (e.g., `90dd603`). | ||||
|
||||
#### `{{base_ref}}` | ||||
|
||||
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` | | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you should not populate this variable in tag events, because it will always be the default branch. Tags aren't anyhow tied to a branch in Git. Example: $ git checkout -b feature
$ git commit -m "Test commit" --allow-empty
$ git tag v1.2.3
$ git push --follow-tags And the result is: $ git checkout master
$ git tag v1.2.3-master
$ git push origin v1.2.3-master Results in: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree that a tag points to a commit, and commits exist independently of branches. But GitHub context seems to record the branch where this event occurs:
You can see it in your logs: https://github.com/felipecrs/ghaction-dump-context/runs/6104549396?check_suite_focus=true#step:3:360 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very interesting. Thank you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I made both This was created with: $ git checkout master
$ git tag v1.2.3-sentfrommaster
$ git push origin v1.2.3-sentfrommaster And it shows This is just to say that this information isn't something to be relied on. I don't know if is worth mention this in the documentation or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say it's GitHub' side bug:
I suppose GitHub manages a DB that records the base ref of a tag. In this case you have created both tag against the same commit so I presume GitHub logic returns all tags for the same commit and matches the first one he found in the DB and therefore here the wrong ref is returned. Just speculations ofc but that seems to be it. Maybe they There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, that would make sense. Let me try again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep no tag event in your workflow for this commit: https://github.com/felipecrs/ghaction-dump-context/blob/4cf159ecaf43bd0f2487e3fb8f5fc723fce1d32c/.github/workflows/ci.yml There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, check my new tags. I believe the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, in case you publish a tag against a revision which does not point to the latest version of a tag neither another tag, here is what you get ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes just saw that too and I don't like that. I will remove support of |
||||
|
||||
#### `{{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. | ||||
|
||||
#### `{{date '<format>'}}` | ||||
|
||||
Returns the current date rendered by its [moment format](https://momentjs.com/docs/#/displaying/format/). | ||||
|
||||
| Expression | Output example | | ||||
|--------------------------------------------|-----------------------------------------| | ||||
| `{{date 'YYYYMMDD'}}` | `20200110` | | ||||
| `{{date 'dddd, MMMM Do YYYY, h:mm:ss a'}}` | `Friday, January 10th 2020, 3:25:50 pm` | | ||||
|
||||
### Major version zero | ||||
|
||||
Major version zero (`0.y.z`) is for initial development and **may** change at any time. This means the public API | ||||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you should remove this entirely. A solution which may not work under some circumstances should not be suggested, especially without warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually updated this example with a hardcoded branch name to show how to handle this case for a specific branch as it seems still valid for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. I didn't notice.