Github Action not triggered when pushing to branch - github

My build_and_test.yml file in .github/workflows is as follows:
name: CI
on:
push:
branches:
- main
- name-of-my-branch
pull_request:
branches:
- main
jobs:
build:
# Code to build
However, when I push to any branch other than the main branch, the build doesn't trigger. Any ideas why this might be?

I realized that this Github Actions file was on the main branch, and Github uses the actions that are configured for the branch that is getting pushed. It doesn't do anything if name-of-my-branch has different on: push: branches: specified in its .github/workflows/build_and_test.yml. So branches: name-of-my-branch in the main branch is a bit deceptive - a build-on-push will only occur if that branch is specified under push in its own .yml.
I pulled from main to name-of-my-branch to update the build_and_test.yml, pushed, and the build was triggered.

Related

Github Action is not being triggered from any branch but master

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.

Is it possible to allow github workflows defined in master branch only?

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?

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'

Unexpected github action trigger

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.

Github Action: Trigger a workflow from another branch

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 ?