Skip to content
Latchkey

How to Merge Multiple Artifacts in GitHub Actions

actions/upload-artifact/merge@v4 collects several artifacts into a single new one in a follow-up job.

After a matrix uploads one artifact per leg, run actions/upload-artifact/merge@v4 in a dependent job to merge them into a single artifact by pattern.

Steps

  • Upload a distinctly named artifact from each matrix leg.
  • Add a merge job with needs: on the matrix job.
  • Run actions/upload-artifact/merge@v4 with a pattern: and target name:.

Workflow

.github/workflows/ci.yml
jobs:
  test:
    strategy:
      matrix:
        shard: [1, 2, 3]
    runs-on: ubuntu-latest
    steps:
      - run: npm test -- --shard=${{ matrix.shard }}/3
      - uses: actions/upload-artifact@v4
        with:
          name: coverage-${{ matrix.shard }}
          path: coverage/
  merge:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/upload-artifact/merge@v4
        with:
          name: coverage-all
          pattern: coverage-*

Gotchas

  • By default merge deletes the source artifacts; set delete-merged: false to keep them.
  • The merge action was added in upload-artifact v4; v3 has no equivalent.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →