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
🌐
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 ...
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
Discussions

Using `workflow_run` in pull requests from non-default branches or forks
Select Topic Area Question Body I'm working a python repository, where I am using pre-commit. I have one workflow that runs code quality checks, and a set of other workflows (>=1) that will ... More on github.com
🌐 github.com
2
2
On: workflow_run: does not work for me
And this workflow will only run ... workflow run on other branches or not. On the Actions page of a repository, under the “All workflows”, generally the following workflows are listed: The workflow files exist on any branches, and the workflows have been triggered … · In addition, if you want the workflow “GitHub Linux Release” ... More on github.com
🌐 github.com
12
11
How can I pass a variable output from one workflow to another workflow?
To pass the should_build output from your release.yml workflow to your deploy.yml workflow, you can use workflow_run context in the on section of your deploy.yml workflow. Here's how you can do it: name: Deploy on: workflow_run: workflows: ["Release"] types: - completed jobs: deploy: name: deploy if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.should_build == 'true' runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 # Add your deploy steps here In this deploy.yml workflow, we're using the workflow_run event with the completed type to trigger the workflow whenever the Release workflow completes. We're also checking if the should_build output from the Release workflow is equal to 'true'. If it is, then the deploy job will run. Otherwise, it will be skipped. More on reddit.com
🌐 r/github
6
4
March 15, 2024
Obtain run_id of completed workflow in workflow_run
I don't see it in the workflow_run payload, but I may be looking at the wrong place. Any suggestion would be welcome! ... Beta Was this translation helpful? Give feedback. ... @dpo - here are all you need https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#usin... More on github.com
🌐 github.com
6
2
🌐
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 ...
🌐
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.
Find elsewhere
🌐
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.
🌐
GitHub
github.com › orgs › community › discussions › 21090
Workflows triggered by the workflow_run event are sometimes skipped · community · Discussion #21090
Reference: Workflow Events - workflow_run documentation · Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... In my case, you have to use a workflow name without space then you can get value of github.event.workflow_run.conclusion
🌐
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 › orgs › community › discussions › 66784
How to get the branch name that triggered a workflow_run? · community · Discussion #66784
Select Topic Area Question Body I've set up a workflow_run that is triggered when another workflow is completed and if the branch is either main or beta. Like this: on: workflow_run: workflows: - T...
🌐
GitHub
docs.github.com › en › actions › reference › workflows-and-actions › contexts
Contexts reference - GitHub Docs
The if check is processed by GitHub Actions, and the job is only sent to the runner if the result is true. Once the job is sent to the runner, the step is executed and refers to the $GITHUB_REF variable from the runner. Different contexts are available throughout a workflow run.
🌐
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
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
🌐
DEV Community
dev.to › kalkwst › workflow-triggering-events-and-event-actions-5cec
Workflow Triggering Events and Event Actions - DEV Community
September 18, 2023 - The push event triggers a workflow run whenever someone pushes changes to the repository. This means that when you push changes to a branch, or even when you create a new branch or a tag, the event will trigger.
🌐
GitHub
docs.github.com › articles › getting-started-with-github-actions
Understanding GitHub Actions - GitHub Docs
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 ...
🌐
Polpiella
polpiella.dev › github-action-workflows-side-effects
GitHub Actions workflows side effects
April 26, 2023 - As part of its execution, the workflow above checks out an external repository and then runs a script to log metrics from the Lint’s workflow run to a third-party service. As you can see in the code above, the workflow can access the webhook payload data using the github.event.workflow_run context variable and pass the relevant information from the event to the metrics script.