Skip to content

Commit 2bc3f4e

Browse files
committed
is_not_default_branch global expression
Signed-off-by: CrazyMax <[email protected]>
1 parent be19121 commit 2bc3f4e

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ jobs:
278278
type=raw,value=gexp-tag-{{tag}}
279279
type=raw,value=gexp-baseref-{{base_ref}}
280280
type=raw,value=gexp-defbranch,enable={{is_default_branch}}
281+
type=raw,value=gexp-notdefbranch,enable={{is_not_default_branch}}
281282
282283
json:
283284
runs-on: ubuntu-latest

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ___
4444
* [`{{sha}}`](#sha)
4545
* [`{{base_ref}}`](#base_ref)
4646
* [`{{is_default_branch}}`](#is_default_branch)
47+
* [`{{is_not_default_branch}}`](#is_not_default_branch)
4748
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
4849
* [`{{commit_date '<format>' tz='<timezone>'}}`](#commit_date-format-tztimezone)
4950
* [Major version zero](#major-version-zero)
@@ -874,6 +875,11 @@ workflow run. Will be empty for a branch reference:
874875
Returns `true` if the branch that triggered the workflow run is the default
875876
one, otherwise `false`.
876877

878+
#### `{{is_not_default_branch}}`
879+
880+
Returns `true` if the branch that triggered the workflow run is not the default
881+
one, otherwise `false`.
882+
877883
#### `{{date '<format>' tz='<timezone>'}}`
878884

879885
Returns the current date rendered by its [moment format](https://momentjs.com/docs/#/displaying/format/).

__tests__/meta.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,40 @@ describe('push', () => {
821821
"org.opencontainers.image.version=mytag-master"
822822
],
823823
undefined
824+
],
825+
[
826+
'push22',
827+
'event_push_dev.env',
828+
{
829+
images: ['org/app'],
830+
tags: [
831+
`type=edge,branch=master`,
832+
`type=sha,format=long`,
833+
`type=raw,value=notdefbranch,enable={{is_not_default_branch}}`
834+
],
835+
} as Inputs,
836+
{
837+
main: 'notdefbranch',
838+
partial: [
839+
'sha-860c1904a1ce19322e91ac35af1ab07466440c37'
840+
],
841+
latest: false
842+
} as Version,
843+
[
844+
"org/app:notdefbranch",
845+
"org/app:sha-860c1904a1ce19322e91ac35af1ab07466440c37"
846+
],
847+
[
848+
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
849+
"org.opencontainers.image.description=This your first repo!",
850+
"org.opencontainers.image.licenses=MIT",
851+
"org.opencontainers.image.revision=860c1904a1ce19322e91ac35af1ab07466440c37",
852+
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
853+
"org.opencontainers.image.title=Hello-World",
854+
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
855+
"org.opencontainers.image.version=notdefbranch"
856+
],
857+
undefined
824858
]
825859
])('given %p with %p event', tagsLabelsTest);
826860
});

src/meta.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ export class Meta {
439439
}
440440
return 'false';
441441
},
442+
is_not_default_branch: function () {
443+
return this.is_default_branch() === 'false' ? 'true' : 'false';
444+
},
442445
date: function (format, options) {
443446
const m = moment(currentDate);
444447
let tz = 'UTC';

0 commit comments

Comments
 (0)