Github Action: Trigger a workflow from another branch - github

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 ?

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.

how to exclude Master branch on a push event

I have a GitHub Action workflow that I want to run on a push to any of the branches in my repository with an exception of 'Master. I don't want the workflow to run on a push to master branch but run on push to other branches in my repository. Please how can I specify that in the workflow?
In your Github Actions workflows file you can specify
name: Deploy staging
on:
push:
branches-ignore:
- master
You can also explicitly include branches you want by doing the following:
name: Deploy staging
on:
push:
branches:
- develop
Changing or adding branches to include the relevant branches that you want. In this manner, workflows will only run to those elected branches.
Here is the relevant section of the Github docs on branches and tags

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 :)

Github Action not triggered when pushing to branch

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.

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.