Trigger One GitHub Actions Workflow After Another Finishes
Use the workflow_run event to start a GitHub Actions workflow after another one completes, filter by conclusion, pass artifacts, and avoid common pitfalls.
At a glance
- Last reviewed
- Versions referenced
actions/checkout@v7actions/upload-artifact@v7actions/download-artifact@v8- Reading time
- 3 min read
Code samples are not run in a live repository. See our editorial standards.
On this page
Use the workflow_run event. List the upstream workflow’s name under workflows, set types: [completed], and gate the job on github.event.workflow_run.conclusion. The event fires whether the upstream run succeeded or failed, so without that condition your workflow runs either way.
name: After Build
on:
workflow_run:
workflows: [Build]
types: [completed]
jobs:
on-success:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- run: echo "Build succeeded"
The value in workflows must match the name: of the upstream workflow, not its file name. The workflow file containing the workflow_run trigger must exist on the repository’s default branch, or the event never starts it. For a related walkthrough, see Fix workflow_dispatch Inputs Not Showing in the Actions UI.
To confirm it works, run the upstream workflow, then open the Actions tab. A new run of After Build should appear with the event shown as workflow_run. If it does not, check the name match and the default-branch requirement first.
Filter by conclusion
conclusion is available on the event payload as github.event.workflow_run.conclusion. Common values are success, failure, cancelled, skipped, timed_out, neutral and action_required.
on:
workflow_run:
workflows: [Build]
types: [completed]
jobs:
on-success:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- run: echo "The triggering workflow passed"
on-failure:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
steps:
- run: echo "The triggering workflow failed"
Each job is evaluated independently. In the run summary, the job whose condition is false is shown as skipped, and the matching job executes.
Filter by branch
The branches and branches-ignore filters on workflow_run match the branch of the upstream run, not the branch where your workflow file lives.
on:
workflow_run:
workflows: [Build]
types: [completed]
branches: [main]
With this filter, the workflow starts only when Build ran on main. It does not replace the default-branch requirement described above.
Pass data between workflows with artifacts
A workflow_run workflow does not receive the upstream workspace. Upload an artifact upstream, then download it by run ID downstream.
Upload in the upstream workflow
name: Build
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Build project
run: |
mkdir -p dist
echo "build-$(date +%s)" > dist/version.txt
- uses: actions/upload-artifact@v7
with:
name: build-output
path: dist/
retention-days: 5
Download in the triggered workflow
name: Deploy
on:
workflow_run:
workflows: [Build]
types: [completed]
permissions:
actions: read
contents: read
jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
name: build-output
path: dist/
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: cat dist/version.txt
By default, download-artifact only looks in the current run. Setting run-id and github-token makes it fetch from the upstream run, and the token needs actions: read for that.
To verify, check that the download step log lists the artifact and that cat dist/version.txt prints the value written upstream. If the download step cannot find the artifact, confirm that name matches the upload step and that the upstream run has not passed its retention period.
Pitfalls
- Wrong code checked out. A
workflow_runworkflow runs against the default branch’s latest commit. To build the commit that triggered the upstream run, useactions/checkoutwithref: ${{ github.event.workflow_run.head_sha }}. - Untrusted pull requests.
workflow_runworkflows run with a token that can write and with access to secrets, even when the upstream run came from a fork’s pull request. Treat artifacts from such runs as untrusted data. Never execute their contents or interpolate their values intorun:scripts. - Chain depth.
workflow_runcannot chain more than three levels of workflows. Workflows beyond that depth do not run. - Events created with
GITHUB_TOKEN. Events created by the repository’sGITHUB_TOKENdo not start new workflow runs, exceptworkflow_dispatchandrepository_dispatch.pull_requestevents (opened,synchronize,reopened) create runs that wait for approval. To trigger other events from a workflow, use a GitHub App installation token or a personal access token.
Alternatives to workflow_run
| Option | Use when | Trade-off |
|---|---|---|
workflow_run |
A separate workflow must react to another’s completion or conclusion | Runs on the default branch context; data passes only via artifacts |
workflow_call (reusable workflow) |
You want one workflow to run as a step in a larger pipeline | The caller owns ordering; the called workflow appears inside the caller’s run |
repository_dispatch or workflow_dispatch |
You need to start a workflow from an API call or another workflow, with inputs | Requires a token with permission to dispatch events |
To call a reusable workflow, declare on: workflow_call in it and reference it from a job with uses, then order jobs with needs:
# .github/workflows/deploy.yml (called workflow)
on:
workflow_call:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- run: echo "Deploying"
# .github/workflows/pipeline.yml (caller)
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo "Building"
deploy:
needs: build
uses: ./.github/workflows/deploy.yml
Here deploy starts only after build succeeds, and both appear in a single run, so you see the whole pipeline in one place.
Spotted an error? Report it on our Contact page and see our editorial standards for how we correct articles.