Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Action triggered by success of a different action

I am trying to trigger a Github action to run after a successful run of a different action.

the 2 workflows are:

Unit Test Action (Which runs first, and should trigger the Follow on Test action below

name: unit-tests

on:
  push:
    branches:
      - '**'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup .NET Core
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: "3.1.x"
      - name: Test
        run: dotnet test src/XXXXXXXXXX

Follow on Test Action (This is just a test action)

name: Test action triggered by previous action success

on:
  workflow_run:
    workflows:
      - unit-tests
    types:
      - completed

jobs:
  test-job:
    name: Test Step
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.workflow_run.head_branch }}
      - run: echo "The follow on works!!"

The issue is that when this is triggered on a feature branch and not the default branch (as it should be because I want the actions to run all all branches) it doest work?

Any ideas?

like image 688
bruzza42 Avatar asked Dec 31 '25 10:12

bruzza42


1 Answers

As discussed in the comments:

First: It is necessary to have both workflows on the branch and to first merge the branch into your default branch, then onwards it will work.

Second: It is possible to use if: ${{ github.event.workflow_run.conclusion == 'success' }} to only run the jobs if the previous workflow was successful.

Example:

 on:
   workflow_run:
     workflows: ["Other Workflow Name"]
     types: [completed] #requested

 jobs:
   on-success:
     runs-on: ubuntu-latest
     if: ${{ github.event.workflow_run.conclusion == 'success' }}
     steps:
       - run: echo "First workflow was a success"

   on-failure:
     runs-on: ubuntu-latest
     if: ${{ github.event.workflow_run.conclusion == 'failure' }}
     steps:
       - run: echo "First workflow was a failure"
like image 194
GuiFalourd Avatar answered Jan 02 '26 01:01

GuiFalourd