I wrote a simple Action that should be triggered only after push in a specific branch named "develop".
name: Develop
on:
push:
branches:
- 'develop'
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: run curl command
run: curl -X POST "https://<site>"
As I read, the action .yaml file must be only in master branch and so it is.
I expect from this action to be only be triggered for any push to a brach named develop.
In practice, no action is triggered when I push to develop.
If I change -'develop' to -'master' and push to master branch, I see the action is being triggered.
my team has a github repo with some github workflows set up. I noticed that if someone updates a .github/workflows/[workflow_name].yml file and push it to a dev branch, the updated workflow definition could also be triggered. I am trying to disallow workflows defined in a dev branch from being picked up, so that any un-reviewed workflow definitions in a dev branch would not be triggered. Is there a way to do that?
Eg. if the yml file in the origin master branch is like
on:
pull_request:
branches:
- master
jobs:
[do_something_here]
Then some one updated the yml file to
on:
pull_request:
branches:
- master
jobs:
[do_something_else_instead]
and push the code to a dev branch, and make a PR to master branch, at this point no one was requested to review anything, but the do_something_else_instead would be triggered.
I want to stop such behavior, only yml files in the master branch should be allowed to trigger workflows.
When you define your workflow to be triggered on a pull_request event, you can set a list of branches to be taken into account:
on:
pull_request:
branches:
- master
- 'releases/**'
So you can manage which target branch of a PR your workflow is triggered on.
If you want your workflow not to be triggered until a commit is in the master branch, the event you need is push. With it, you can also set a branches list, in your case your list would contain only 1 branch: master
on:
push:
branches:
- master
So if your workflow has been modified, do_something_else_instead would not be executed until PR is reviewed and merged into master branch.
You can a have look on Github documentation here: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
If you need you can set a mix of filter: branches, branches-ignore, paths, paths-ignore, that can be useful :)
On GitHub Actions, how do I run a job if a specific file in a specific branch has been pushed to?
I've used the following workflow, but I don't know how to specify a specific branch for that file (such as the main branch):
on:
push:
paths: [ index.js ]
Thanks for the help! :)
I have this running with.
Then it's only runs on push with changes in .github/workflows/BranchAndPath.yml and README.md
name: Branch & Path
on:
push:
branches:
- "**"
paths:
- '.github/workflows/BranchAndPath.yml'
- 'README.md'
This github action runs on a pull request to develop. This isn't what I expected and I could use some fishing tips on how to understand/debug why it is triggered.
on:
push:
branches:
- master
pull_request:
branches:
- master
develop is the default branch for the repository. I mention this because this action isn't triggered when I push to a feature branch. It is triggered on a pull request to master.
I have two branches: feat and master.
feat doesn't have a .github folder.
master has one with the following trigger:
on:
push:
branches:
- feat
When I push something on feat, the workflow on the master branch isn't triggered. Is there any away around it ?