actions / upload-artifact

MIT License
3.01k stars 683 forks source link

[feat req] Merge artifacts option #483

Open mmuzikar opened 6 months ago

mmuzikar commented 6 months ago

What would you like to be added?

An option to not throw 409 Conflict when an existing artifact exists, but merge the artifacts as it was possible in the previous version.

Why is this needed?

In v3, it was possible to have an artifact of the same name that would get merged when a new upload action was invoked, and as a result, it was really easy to create an aggregate artifact with the results of all matrix jobs. As an example, I had a test-results artifact that contained folders for each matrix combination containing all the matrix runs. This was really nice for reporting summaries for PRs, and collecting the results in one click.

henryiii commented 6 months ago

See #472

robherley commented 5 months ago

👋 We introduced a new sub-action, actions/upload-artifact/merge

This facilitates combining all your workflow run's artifacts into a new, merged artifact.

For example:

jobs:
  upload:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        foo: [a, b, c]

    steps:
      - name: Run a one-line script
        run: echo "hello from job ${{ matrix.foo }}" > file-${{ matrix.foo }}.txt
      - name: Upload
        uses: actions/upload-artifact@v4
        with:
          name: my-artifact-${{ matrix.foo }}
          path: file-${{ matrix.foo }}.txt
  merge:
    runs-on: ubuntu-latest
    needs: upload
    steps:
      - name: Merge Artifacts
        uses: actions/upload-artifact/merge@v4
        with:
          name: my-amazing-merged-artifact
          pattern: my-artifact-*

The above workflow would:

  1. In upload job matrix, upload three artifacts: my-artifact-a, my-artifact-b and my-artifact-c
  2. In the merge job, it will download and re-upload each into a single artifact, my-amazing-merged-artifact.

The resulting my-amazing-merged-artifact would have the following files:

.
  ∟ file-a.txt
  ∟ file-b.txt
  ∟ file-c.txt

There are plenty of inputs to customize the merging behavior, including prefixing files with directories and deleting any artifacts that were merged.

We've enumerated some use cases in the action's README.

Hope this helps, and thanks for your feedback!