I have a repository on GitHub, and I want to create a GitHub Action to automate the process of building and publishing a Docker image to DockerHub.
I know how to do this but if I create the action in a branch other than master
GitHub it doesn't recognize it and it doesn't execute it when the event configured in it ( push
) occurs.
This is a known issue ( Workflow files only picked up from master? ) but I haven't found any tricks to make it work.
Any ideas?
The problem is caused by the behavior of the GitHub Actions platform itself.
According to the official documentation, when an event is triggered, the workflow files are searched in the folder
.github/workflows
corresponding to the commit and the Git reference (egrefs/heads/master
for the branchmaster
) and for those whose definitionon:
includes the triggered event, the workflow will be executed.This means that if an event occurs on a specific branch, then the workflow definition has to be on that branch and on the specific commit linked to the event. Otherwise it won't run.
It is important to emphasize that, although the file with the workflow definition is in the branch linked to the event, the version of the workflow corresponding to the commit also linked to the event will always be executed. Therefore, if there is no such workflow in that commit, it will NOT be executed either.
For more information refer to the official documentation: About workflow events