Search code examples
githubcontinuous-integrationgithub-actions

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?


Solution

  • 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.