Sub topic 10
Downloading artifacts from another workflow run
This chapter assumes you can already upload an artifact with actions/upload-artifact@v4 and download one in a later job of the same run. It also assumes you know that each run has its own ID and its own set of artifacts.
Why the default does not work across runs
By default, actions/download-artifact@v4 looks only at the current workflow run. If a deploy workflow asks for an artifact named dist, it searches its own run and finds nothing. The build happened in a different run.
Common reasons to cross that boundary:
- A separate deploy workflow that you start by hand and point at a known good build.
- A release workflow that reuses the build from the commit it is releasing.
- A reporting workflow that runs after a test workflow finishes.
The three inputs that change the scope
Three inputs tell the action to look somewhere else.
| Input | Meaning | Default |
|---|---|---|
| `run-id` | ID of the run that produced the artifact | The current run |
| `repository` | Repository that owns that run, as `owner/name` | The current repository |
| `github-token` | Token used to call the artifacts API | Not set |
The action ignores github-token unless you also set run-id. Without run-id it reads from the current run, which needs no extra token.
A manual deploy from an earlier build
This workflow starts by hand. You give it the ID of the build run, and it downloads that run's dist artifact.
name: deploy-existing-build
on:
workflow_dispatch:
inputs:
build_run_id:
description: Run ID of the build to deploy
required: true
permissions:
contents: read
actions: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
run-id: ${{ inputs.build_run_id }}
repository: ${{ github.repository }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: ls -R dist/The actions: read permission matters. The artifacts API needs it, and a workflow that narrows permissions can lose it by accident. When that happens, the download fails with a 403 or "Not Found" error.
Which token to use
- Same repository:
secrets.GITHUB_TOKENworks if the workflow hasactions: read. - Different repository:
GITHUB_TOKENis scoped to the repository running the workflow. Use a personal access token or a GitHub App token that can read Actions data in the other repository. Store it as a secret, and pass it togithub-token.
Replace the empty block above with the diagram below. The diagram shows the order of events.
Triggering from the finished run
You do not always have to copy a run ID by hand. A workflow with the workflow_run trigger starts when another workflow finishes, and the event carries that run's ID.
name: after-build
on:
workflow_run:
workflows: [build]
types: [completed]
permissions:
contents: read
actions: read
jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: ls -R dist/The if line stops the job when the build failed. Without it, the job runs after failures too, and it then fails on a missing artifact.
Common errors
- Artifact not found. The name is wrong, the run never uploaded it, or the retention period ended. Expired artifacts cannot be downloaded.
- 403 or "Resource not accessible". The token lacks
actions: read, or it cannot see the other repository. - Download ignores
run-id. Thegithub-tokeninput is missing. Set both. - Wrong run. A run ID identifies one run attempt. Re-run attempts of the same run share the run ID, so check that you are getting the build you meant.
Security warning
An artifact is input to your workflow, so treat it as untrusted data when it comes from a run you do not control.
Doing it by hand
For a quick look at a run's output, you can skip a workflow and use the GitHub CLI. The next chapter covers gh run download and the web UI.
Exercise
A workflow in repository acme/site must download the dist artifact from run 555 of the same repository. The step sets name, path, and run-id: 555, and it fails with a "Not Found" error. Which two additional things should you check or set?
Show answer
Set github-token: ${{ secrets.GITHUB_TOKEN }}, because the action needs a token to read another run's artifacts. Also make sure the workflow's permissions include actions: read. If both are correct, check that the artifact name matches and that the artifact has not expired.