Learning center

Your job downloaded an artifact from another run. Which commit built it?

Whatever commit that other run checked out, which need not be the one your job runs on. A step that fetches "the latest successful" artifact picks a run by time and conclusion. Before you deploy or test what you downloaded, read the source run's head_sha and the artifact's digest, and fail the job when the commit is not the one you ship.

How a job ends up with another run's files#

actions/download-artifact reads from the current run by default. Its README says the github-token input "is required when downloading artifacts from a different repository or from a different workflow run", and that run-id defaults to ${{ github.run_id }}. actions/download-artifact A job that sets run-id gets exactly that run's artifact; the question moves to how the job chose the ID.

Third-party actions choose for you. The README of dawidd6/action-download-artifact says that if none of commit, pr, branch, ref, run_id or workflow_conclusion is specified, "the artifact from the most recent successfully completed workflow run will be downloaded". dawidd6/action-download-artifact If the newest successful run was for another commit, or for another branch's queue, that is the artifact you get, and the step still succeeds.

The same commit, two different artifacts#

The artifacts API records the run behind each artifact, including workflow_run.head_sha and head_branch, and a digest. Artifacts REST API Listing the newest artifacts named screenshots-linux in a public game engine repository:

[…]
15568746384	2026-12-02T03:49:46Z	46803585219	main	70ce41556e4b	sha256:c01dd413d250717b
15565787377	2026-12-02T03:07:50Z	46799036202	gh-readonly-queue/main/pr-25664-5d378cf5459999ab2c639cc07599c59a9a1fcf33	70ce41556e4b	sha256:526314191275a030
15554352694	2026-12-02T00:13:24Z	46774671184	main	5d378cf54599	sha256:1e5cae8a45339284
[…]

The columns are artifact ID, creation time, source run, branch, commit and the start of the digest. The first two came from a push run and a merge_group run of the same workflow on the same commit, and their digests differ. A matching commit says which source built the files. It does not say two builds of it produced the same bytes. Here the two uploads differ, and a change in any file or in the archive itself would produce that.

Check before you use it#

Look up the artifact you are about to download:

gh api --paginate "repos/OWNER/REPO/actions/artifacts?name=ARTIFACT_NAME&per_page=100" \
  --jq '.artifacts[] | [.id, .workflow_run.id, .workflow_run.head_sha, .digest] | @tsv'

In the workflow, pass the run explicitly and compare the commit:

permissions:
  actions: read
steps:
  - uses: actions/download-artifact@v8
    with:
      name: build
      github-token: ${{ github.token }}
      run-id: ${{ inputs.build_run_id }}
  - run: |
      built=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$BUILD_RUN_ID" --jq .head_sha)
      test "$built" = "$GITHUB_SHA" || { echo "artifact built from $built"; exit 1; }
    env:
      GH_TOKEN: ${{ github.token }}
      BUILD_RUN_ID: ${{ inputs.build_run_id }}

The run ID reaches the shell as an environment variable, not as text pasted into the script. GitHub's secure use reference recommends this intermediate environment variable. The run's head_sha is the commit its event named; a build job that checks out another ref, such as a pull request's head, builds other source, so read the source workflow's checkout step too.

What a match covers#

ObservationWhat it showsWhat it cannot exclude
Source run head_sha equals your commitThe files came from a run on that commitA different build of that commit with different bytes
Digest equals the one you recordedThe bytes are the ones you recordedNothing about the commit, unless you recorded both together
Source run is a pull_request runIt built the merge commit with the base at that timeThat the base has not moved since

The download action checks the digest against the server's value and fails on a mismatch by default (digest-mismatch: error). That protects the transfer, not the choice of run.

Artifacts expire with the retention period; see keeping review CI artifacts and promote the tested artifact. Return to handing over evidence.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading