Bug ? workflow_run skips workflows depending on repository default branch

Hi GitHub Support!

The workflow I try to achieve is quite simple, however it seems like workflow_run is not working as expected.

We got a first workflow (simplified, so you can reproduce it :slight_smile:)

name: Test - Base Workflow

on:
  push:
    branches:
      - master
      - rc
      - dev

jobs:
  base_workflow:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

Then we got a second workflow triggered through the workflow_run when the first one ends:

name: Test - Workflow Run

on:
  workflow_run:
    workflows: ["Test - Base Workflow"]
    branches: ["master", "rc"]
    types:
      - completed

jobs:
  test_workflow_run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - run: echo ${{ github.event.workflow_run.head_branch }}

Finally there’s a last workflow triggered after the second completes:

name: Test - Third Workflow

on:
  workflow_dispatch:
    inputs:
      nodejs_git_branch:
        description: xxx
        default: ""
        required: true
  workflow_run:
    workflows: ["Test - Workflow Run"]
    branches: ['rc']
    types:
      - completed

env:

jobs:
  test_workflow_run:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - run: echo ${{ github.event.workflow_run.head_branch }}

Expectation:

  • When there’s a push on rc

    • Test - Base workflowTest - Second workflowTest - Third workflow
  • When there’s a push on master

    • Test - Base workflowTest - Second workflow

Actual behaviour:

  • When there’s a push on rc

    • Test - Base workflowTest - Second workflow → Third workflow is skipped but should be run since it matches the branches condition
  • When there’s a push on master

    • Test - Base workflowTest - Second workflow (third workflow is skipped as expected from the branches condition

Demonstration

We’ve found that the expected behaviour for the rc branch can only happen if rc becomes the repository default branch

If any other branch is set as the default branch, the third workflow is skipped but shouldn’t be => Actual behaviour

Now if I set rc as the default branch, the workflow runs as expected.

Thanks for your help !

This behavior makes sense to me: According to the workflow_run event description the workflow is picked up only from the default branch, so the branch on which the second workflow runs is always the default branch. That’s why the third workflow never runs if rc isn’t the default branch.

2 Likes