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@v4with apattern:and targetname:.
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: falseto keep them. - The merge action was added in upload-artifact v4; v3 has no equivalent.
Related guides
How to Name an Artifact Dynamically in a Matrix in GitHub ActionsGive each matrix leg a unique GitHub Actions artifact name by interpolating matrix values into the name input…
How to Download All Artifacts in GitHub ActionsDownload every artifact from a GitHub Actions run at once by calling actions/download-artifact@v4 with no nam…