I have the following question regarding GitHub's behaviour:
- I created a folder locally, initialized a git repo, added GitHub remote, added few files and committed them.
Now I want to add some GitHub action workflows, so I created
.github/workflows/demo.yml
I pushed it to GitHub repo on another branch (not on main), so my question is: isdemo.yml
branch specific or not?
CodePudding user response:
Short version: workflows can only be run on a specific branch if the workflow files are present on that particular branch.
When you push some code to GitHub, then GitHub Actions will look at what is in the .github
directory on that branch you just pushed and run those workflows.
So yes, they are only run on branches where those files exist.
As an example:
If you add a .github/workflows/demo.yml
in your main
branch, and push that, GitHub Actions will check if that workflow should be executed. If it is configured to run on the main branch and on pushes, it will run.
After this, if you create a branch based on the main
branch, and push some changes to that new branch, GitHub Actions will again look under the .github/workflows
directory to see what lies there in your new branch, and it will check if those workflows should run.
The scenario you describe is that you have created a .github/workflows/demo.yml
and you have pushed that on a branch that is not main
. That means the workflow will only be run on this branch, until you merge it into main
.
And then, even if the workflow files exist on some branch, the workflows might be configured to only run on some specific branches, using filters. See the documentation for more info on that: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#using-filters