3

I have created the following GitHub Actions workflow.

name: Testing CI

on:
  push:
    branches: [ my-branch ]

Here in branches: [my-branch] I am putting the name of the current branch.

But I want the workflow file to automatically take the name of the current branch.

Is there a parameter I can pass branches: [my-branch] here to automatically take the branch name?

torek
  • 448,244
  • 59
  • 642
  • 775
manish soni
  • 515
  • 1
  • 7
  • 19

2 Answers2

0

You should not specify a branch name, then, in order for your action to run on push for all branches: on: [push]

Then you can use EthanSK/git-branch-name-action in order to get the current branch name.

That action uses process.env.GITHUB_REF,
and is the equivalent of this solution:
export GIT_BRANCH=$(echo ${GITHUB_REF:-dev} | sed s/.*\\///g).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Just use this And it will run on push of any branch:

on: [push]
Ryan
  • 5,229
  • 1
  • 20
  • 31