actions / upload-artifact

MIT License
3.14k stars 706 forks source link

[docs] Uploading different files to the same artifact from multiple jobs #279

Open PathogenDavid opened 2 years ago

PathogenDavid commented 2 years ago

What files would you like to change?

https://github.com/actions/upload-artifact/blob/f4ac36d2052d09212226799b513ca60c91a09bfc/README.md?plain=1#L131-L177

What are your suggested changes?

In the "Uploading to the same artifact" section, it is warned that uploading to the same artifact from multiple jobs can have unexpected results. The proposed workaround is to upload a different artifact from each job in the matrix.

While this does work, it's not super convenient if you need to be able to download all artifacts from a matrixed job in one go.


Based on my understanding of how artifacts in GitHub Actions work, it seems to me like it should be possible to upload to the same artifact from multiple jobs as long as the file paths are all different. For example:

    strategy:
      matrix:
          node-version: [8.x, 10.x, 12.x, 13.x]
    steps:
        - name: Create a file
          # Note the change below ______________________vvvvvvvvvvvvvvvvvvvvvvvvvvv
          run: echo ${{ matrix.node-version }} > my_file_${{ matrix.node-version }}.txt
        - name: Accidentally upload to the same artifact via multiple jobs
          uses: actions/upload-artifact@v2
          with:
              name: my-artifact
              path: ${{ github.workspace }}

In practice this seems to work fine, but it would be nice to have it clarified in the documentation whether A) this is an intended/supported feature or B) if it's actually still problematic and I'm relying on a race condition succeeding.

If someone from GitHub who knows how the backend works can clarify whether this works intentionally, I can submit a PR adding the appropriate example/disclaimer.

piotrekkr commented 10 months ago

I read somewhere (cannot find it atm) that uploading same artifact (even with different files) at same time from multiple jobs can lead to archive corruption. It is probably very rare or maybe it was fixed or is handled differently on backend side and this is not happening any more. Will link to this if I find this info again.

//EDIT

Found this in current docs:

Warning: Be careful when uploading to the same artifact via multiple jobs as artifacts may become corrupted. When uploading a file with an identical name and path in multiple jobs, uploads may fail with 503 errors due to conflicting uploads happening at the same time. Ensure uploads to identical locations to not interfere with each other.

It is still unclear. Based on second part of this warning when you try to upload to same artifact from multiple jobs then first job should work and the rest should get 503 error. Not really sure what is first part about because first upload will create an artifact (with files from this one job) and it should be proper archive but incomplete because rest of the jobs failing.

nonesky666 commented 9 months ago

hm

On Wed, 1 Nov 2023 at 13:59, Piotr @.***> wrote:

I read somewhere (cannot find it atm) that uploading same artifact (even with different files) at same time from multiple jobs can lead to archive corruption. It is probably very rare or maybe it was fixed or is handled differently on backend side and this is not happening any more. Will link to this if I find this info again.

— Reply to this email directly, view it on GitHub https://github.com/actions/upload-artifact/issues/279#issuecomment-1788914277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXNMDT5ZKOFTM6ETQGHBOT3YCJBURAVCNFSM5JRQWWGKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZYHA4TCNBSG43Q . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rjeczalik commented 9 months ago

In practice this seems to work fine,

It worked fine with actions/upload-artifact@v3.

With actions/upload-artifact@v4 an attempt to upload different files to the same artifact from mulitple jobs fails explicitely with:

Run actions/upload-artifact@v4
With the provided path, there will be 1 file uploaded
Artifact name is valid!
Root directory input is valid!
Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (40[9](https://github.com/(REDACTED)/actions/runs/(REDACTED)/job/(REDACTED)#step:10:10)) Conflict: an artifact with this name already exists on the workflow run

However this does not happen with actions/upload-artifact@v3 (same artifact, different paths).

flopana commented 5 months ago

Is there any update on this discussion? I'm having the same problem from uploading artifacts from a matrixed job

goakshit commented 2 months ago

@flopana You can't upload artifacts with same name using v4 Refer: docs