To get the example to work (i.e. to have one workflow wait for another to complete) you need two files. Both files live in the .github/workflows folder of a repository.

The first file would be set up as usual. This file will be triggered by whatever event(s) are set in the on section:

---
name: Preflight

on:
  - pull_request
  - push

jobs:
  preflight-job:
    name: Preflight Step
    runs-on: ubuntu-latest
    steps:
      - run: env

The second file states that it should only trigger on the workflow_run event for any workflows with the name Preflight and must be on your repository's default branch, usually main or master:

---
name: Test

on:
  workflow_run:
    workflows:
      - Preflight
    types:
      - completed

jobs:
  test-job:
    name: Test Step
    runs-on: ubuntu-latest
    steps:
      - run: env

This more-or-less the same as the example from the GitHub Actions manual.

As you can see on the actions page of my example repo, the Preflight workflow will run first. After it has completed, the Test workflow will be triggered:

When you try this out, you will find that the Test workflow always runs the code and workflow configuration on your default branch, usually main or master.

This is because, (quoting from the manual):

This event will only trigger a workflow run if the workflow file is on the default branch.

This means you'll need to develop workflows triggered by workflow_run on your default branch, which is a little unfortunate.

This also means that if you need the "Test" workflow to run against the code of your branch or pull request, then you'll need to do more work as described below:

Every actions is run with a set of contexts. The github context holds information about the event that triggered the workflow. This includes the branch that the event was originally triggered from/for: github.event.workflow_run.head_branch.

This can be used to check out the origination branch in the action, using the actions/checkout action provided by GitHub.

To do this, the Yaml would be:

---
name: Test

on:
  workflow_run:
    workflows:
      - Preflight
    types:
      - completed

jobs:
  test-job:
    name: Test Step
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          repository: '${{ github.event.workflow_run.head_repository.full_name }}'
          ref: ${{ github.event.workflow_run.head_branch }}
      - run: git branch
      - run: env
Answer from Potherca on Stack Overflow
Top answer
1 of 1
67

To get the example to work (i.e. to have one workflow wait for another to complete) you need two files. Both files live in the .github/workflows folder of a repository.

The first file would be set up as usual. This file will be triggered by whatever event(s) are set in the on section:

---
name: Preflight

on:
  - pull_request
  - push

jobs:
  preflight-job:
    name: Preflight Step
    runs-on: ubuntu-latest
    steps:
      - run: env

The second file states that it should only trigger on the workflow_run event for any workflows with the name Preflight and must be on your repository's default branch, usually main or master:

---
name: Test

on:
  workflow_run:
    workflows:
      - Preflight
    types:
      - completed

jobs:
  test-job:
    name: Test Step
    runs-on: ubuntu-latest
    steps:
      - run: env

This more-or-less the same as the example from the GitHub Actions manual.

As you can see on the actions page of my example repo, the Preflight workflow will run first. After it has completed, the Test workflow will be triggered:

When you try this out, you will find that the Test workflow always runs the code and workflow configuration on your default branch, usually main or master.

This is because, (quoting from the manual):

This event will only trigger a workflow run if the workflow file is on the default branch.

This means you'll need to develop workflows triggered by workflow_run on your default branch, which is a little unfortunate.

This also means that if you need the "Test" workflow to run against the code of your branch or pull request, then you'll need to do more work as described below:

Every actions is run with a set of contexts. The github context holds information about the event that triggered the workflow. This includes the branch that the event was originally triggered from/for: github.event.workflow_run.head_branch.

This can be used to check out the origination branch in the action, using the actions/checkout action provided by GitHub.

To do this, the Yaml would be:

---
name: Test

on:
  workflow_run:
    workflows:
      - Preflight
    types:
      - completed

jobs:
  test-job:
    name: Test Step
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          repository: '${{ github.event.workflow_run.head_repository.full_name }}'
          ref: ${{ github.event.workflow_run.head_branch }}
      - run: git branch
      - run: env
🌐
GitHub
docs.github.com › actions › using-workflows › events-that-trigger-workflows
Events that trigger workflows - GitHub Docs
Runs your workflow when a new version of a specified image becomes available for use. This event is typically triggered after a successful image version creation, allowing you to automate actions such as deployment or notifications in response ...
🌐
GitHub
docs.github.com › actions › using-workflows › workflow-syntax-for-github-actions
Workflow syntax for GitHub Actions - GitHub Docs
GitHub displays the workflow run name in the list of workflow runs on your repository's "Actions" tab. If run-name is omitted or is only whitespace, then the run name is set to event-specific information for the workflow run.
🌐
Medium
jiminbyun.medium.com › github-actions-workflow-run-vs-workflow-call-3f1a5c6e19d4
GitHub Actions: workflow_run vs. workflow_call | by Jimin | Medium
October 17, 2023 - Both workflow_run and workflow_call serve essential roles in optimizing and modularizing workflows in GitHub Actions. workflow_run is about sequencing workflows based ont he completion status of another, while workflow_call focuses on reusability ...
🌐
NimblePros
blog.nimblepros.com › blogs › using-workflow-run-in-github-actions
Using `workflow_run` in GitHub Actions | NimblePros Blog
March 1, 2023 - A write-access workflow_run trigger that runs after the first one does and writes the code coverage to the PR · The commenting workflow does need access to some of the files created by the first workflow, so I’ve added upload and download artifacts and am using the dawidd6/action-download-artifact action to get the artifacts from another workflow.
🌐
GitHub
github.com › orgs › community › discussions › 102876
workflow_run triggered only on success · community · Discussion #102876
Thank you for joining the discussion! You're right, employing the if condition to filter for successful runs or manual triggers (workflow_dispatch) is a popular workaround in GitHub Actions. Although this method is effective, it can indeed become quite cumbersome.
Find elsewhere
🌐
GitHub
docs.github.com › en › actions › concepts › workflows-and-actions › workflows
Workflows - GitHub Docs
One or more events that will trigger the workflow. One or more jobs, each of which will execute on a runner machine and run a series of one or more steps. Each step can either run a script that you define or run an action, which is a reusable ...
🌐
GitHub
docs.github.com › en › rest › actions › workflow-runs
REST API endpoints for workflow runs - GitHub Docs
You can use the REST API to view, re-run, cancel, and view logs for workflow runs in GitHub Actions. A workflow run is an instance of your workflow that runs when the pre-configured event occurs.
🌐
GitHub
docs.github.com › en › actions › tutorials › create-an-example-workflow
Creating an example workflow - GitHub Docs
If this field is omitted, the name of the workflow file will be used instead. name: learn-github-actions # Optional - The name for workflow runs generated from the workflow, which will appear in the list of workflow runs on your repository's "Actions" tab. This example uses an expression with the `github` context to display the username of the actor that triggered the workflow run.
🌐
GitHub
github.com › orgs › community › discussions › 16059
Allow workflow_run to wait for all workflows it depends on · community · Discussion #16059
# A sub-project workflow name: project-x on: workflow_call: inputs: job: required: true type: string jobs: build: runs-on: ubuntu-latest if: ${{ inputs.job == 'build' }} steps: - uses: actions/checkout@v2 - run: build deploy: runs-on: ubuntu-latest if: ${{ inputs.job == 'deploy' }} concurrency: project-x-main steps: - uses: actions/checkout@v2 - run: deploy # Infrastructure workflow that orchestrates everything name: infra on: push: branches: [main] jobs: run-project-1-build: name: Project 1 uses: ./.github/workflows/project-1.yml with: job: build secrets: inherit run-project-2-build: name: Pr
🌐
GitHub
github.com › marketplace › actions › workflow_run-status
workflow_run status · Actions · GitHub Marketplace · GitHub
name: 'test_post' on: workflow_run: workflows: ["test"] types: - completed jobs: post-test-success: runs-on: ubuntu-latest steps: - uses: haya14busa/action-workflow_run-status@v1 - uses: actions/checkout@v2 - run: exit 0 post-test-failure: runs-on: ubuntu-latest steps: - uses: haya14busa/action-workflow_run-status@v1 - uses: actions/checkout@v2 - run: exit 1
🌐
GitHub
docs.github.com › en › actions › using-workflows › manually-running-a-workflow
Manually running a workflow - GitHub Docs
September 28, 2022 - To run a workflow manually, the workflow must be configured to run on the workflow_dispatch event. To trigger the workflow_dispatch event, your workflow must be in the default branch. For more information about configuring the workflow_dispatch event, see Events that trigger workflows. Write access to the repository is required to perform these steps. On GitHub, navigate to the main page of the repository....
🌐
GitHub
docs.github.com › en › actions › reference › workflows-and-actions › workflow-commands
Workflow commands for GitHub Actions - GitHub Docs
The actions/toolkit includes a number of functions that can be executed as workflow commands. Use the :: syntax to run the workflow commands within your YAML file; these commands are then sent to the runner over stdout.
🌐
GitHub
docs.github.com › en › actions › learn-github-actions › understanding-github-actions
Understanding GitHub Actions - GitHub Docs
October 18, 2022 - Your workflow contains one or more jobs which can run in sequential order or in parallel. Each job will run inside its own virtual machine runner, or inside a container, and has one or more steps that either run a script that you define or run ...
🌐
GitHub
docs.github.com › en › actions › get-started › quickstart
Quickstart for GitHub Actions - GitHub Docs
You can give the workflow file any name you like, but you must use .yml or .yaml as the file name extension. YAML is a markup language that's commonly used for configuration files. Copy the following YAML contents into the github-actions-demo.yml file: ... name: GitHub Actions Demo run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 on: [push] jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest steps: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
🌐
GitHub
github.blog › home › developer skills › github for beginners: getting started with github actions
GitHub for Beginners: Getting started with GitHub Actions - The GitHub Blog
2 weeks ago - When that event fires and triggers the workflow, GitHub spins up one or more jobs that execute on a runner. GitHub then follows the steps you programmed into the workflow until it reaches the end. And it does this all on its own, without any interaction necessary on your behalf. This is essentially how the GitHub Action workflow works.
🌐
GitHub
docs.github.com › en › actions › how-tos › write-workflows › choose-when-workflows-run › trigger-a-workflow
Triggering a workflow - GitHub Docs
If you do want to trigger a workflow from within a workflow run, you can use a GitHub App installation access token or a personal access token instead of GITHUB_TOKEN to trigger events that require a token. If you use a GitHub App, you'll need to create a GitHub App and store the app ID and private key as secrets. For more information, see Making authenticated API requests with a GitHub App in a GitHub Actions ...
🌐
GitHub
docs.github.com › actions › managing-workflow-runs
Managing workflow runs - GitHub Docs
When a workflow is configured to run on the workflow_dispatch event, you can run the workflow using the Actions tab on GitHub, GitHub CLI, or the REST API.