Sunday, October 9, 2022

[FIXED] How do i run GithHub actions .yaml files in certain order?

Issue

I have two .yaml files for my GitHub actions. I need the second file to be executed only after first. How can I achieve this if the jobs are both in other files?


Solution

You could use the workflow_run syntax for Github Actions workflows.

In the example below, a workflow with the following trigger will only run when the workflow named Workflow Tester is completed (you could also started them in sequence using the requested type).

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

Note that when using the trigger that way (with the completed type) you can also check the previous workflow, and perform different jobs depending on the workflow conclusion.

Example

jobs:
  on-success:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      [...]
  
  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      [...]

I've tested this syntax in this workflow if you want to have a look and check the workflow runs in the repo Actions tab.



Answered By - GuiFalourd
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.