upload-artifact icon indicating copy to clipboard operation
upload-artifact copied to clipboard

[feat req] add option to overwrite existing artifacts

Open sni opened this issue 2 years ago • 16 comments

What would you like to be added?

It would be nice to have a option to allow overwrite existing artifacts like it was possible in v3.

Why is this needed?

I have an optional workflow step to sign artifacts, it downloads an artifact, signs it and uploads it with the same name again. Worked perfectly fine with actions/upload-artifact@v3. I tried to use geekyeggo/delete-artifact@v2 but even that doesn't work. Since this step is not applicable for pull requests, it would make things quite complicated to continue with separate artifact names.

sni avatar Dec 15 '23 08:12 sni

👋 If you need to delete an artifact, you can do it with @actions/github-script.

Here's a full example:

name: Delete Artifact Example
on:
  workflow_dispatch:

permissions:
  actions: write # required permission to delete artifact

jobs:
  upload-and-delete:
    runs-on: ubuntu-latest
    steps:
    - name: Create a File
      run: echo "hello world" > hello.txt
    - name: Upload Artifact
      id: artifact-upload
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact
        path: hello.txt
    - name: Delete Artifact
      uses: actions/github-script@v7
      with:
        script: |
          github.rest.actions.deleteArtifact({
            owner: context.repo.owner,
            repo: context.repo.repo,
            artifact_id: ${{ steps.artifact-upload.outputs.artifact-id }}
          });
    - name: Upload Artifact (again)
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact
        path: hello.txt

Make sure you have the correct permissions set for the GITHUB_TOKEN, as noted above:

permissions:
  actions: write

I'm not sure if we're going to have an official "overwrite" at this time, since artifacts become immediately available in the public API in v4, unlike in v3 where you had to wait until the end of the run. But thanks for the feedback and I'll bring it up with the team!

robherley avatar Dec 15 '23 17:12 robherley

thanks for the workaround. For now, i just keep using v3 while hoping there will be a option to overwrite again in the future. If there are any implications, you could mention this in the docs and leave the decision to the user?

sni avatar Dec 16 '23 09:12 sni

I would like to see this feature added too, I saw the workaround but I will keep using v3 until this is addressed as well.

onedr0p avatar Dec 16 '23 13:12 onedr0p

@robherley I guess that will not work in matrix

zdgeorgiev avatar Dec 18 '23 08:12 zdgeorgiev

@zdgeorgiev It still works fine in a matrix:


name: Delete Artifact Matrix Example
on:
  workflow_dispatch:

permissions:
  actions: write # required permission to delete artifact

jobs:
  upload-and-delete:
    strategy:
      matrix:
        example: ['foo', 'bar']
    runs-on: ubuntu-latest
    steps:
    - name: Create a File
      run: echo "hello world" > hello.txt
    - name: Upload Artifact
      id: artifact-upload
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact-${{ matrix.example }}
        path: hello.txt
    - name: Delete Artifact
      uses: actions/github-script@v7
      with:
        script: |
          github.rest.actions.deleteArtifact({
            owner: context.repo.owner,
            repo: context.repo.repo,
            artifact_id: ${{ steps.artifact-upload.outputs.artifact-id }}
          });
    - name: Upload Artifact (again)
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact-${{ matrix.example }}
        path: hello.txt

You can even use the list artifacts API in octokit to list/filter/reduce on the artifact names and pass them to delete artifact.

robherley avatar Dec 19 '23 16:12 robherley

I'm not sure if we're going to have an official "overwrite" at this time

TBH, that would be great as you would have easier interaction among jobs, not when a simple way to pass artifact-id from jon foo to job bar so this with aggregating artifacts may not work :(

Borda avatar Dec 19 '23 17:12 Borda

I'm not sure if we're going to have an official "overwrite" at this time

@robherley that's unfortunate, I hope by looking at the number of issues/pr linked that will change. It seems like most are downgrading due to this not being a feature in v4.

onedr0p avatar Dec 24 '23 14:12 onedr0p

@onedr0p 👋 I agree. Going to bring this back to the team considering how likely it'll be required. Thanks for the feedback!

robherley avatar Dec 24 '23 14:12 robherley

@robherley: were you able to address the issue with the team?

sni avatar Jan 10 '24 09:01 sni

👋 @sni If all goes well, we should have this ready by tomorrow! I have a toolkit PR open to delete artifacts, once that is merged and published I'll add an input to overwrite which will delete the previous artifact before uploading the next

robherley avatar Jan 17 '24 23:01 robherley

👋 This is now possible! Check out the example in the readme: https://github.com/actions/upload-artifact#overwriting-an-artifact

robherley avatar Jan 18 '24 22:01 robherley

Is this rolled out yet? we are seeing the following error on this workflow:

Run actions/upload-artifact@v4
  with:
    name: pull-request-number
    path: pull_request_number.txt
    overwrite: true
    if-no-files-found: warn
    compression-level: 6
  env:
    FORCE_COLOR: 1
    FLAKINESS_CONNECTION_STRING: 
    ELECTRON_SKIP_BINARY_DOWNLOAD: 1
    PWTEST_BOT_NAME: chromium-ubuntu-22.04-node20
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: (409) Conflict: an artifact with this name already exists on the workflow run

yury-s avatar Jan 23 '24 03:01 yury-s

Me too seeing this issue in v4. Downgrading to v3 fixes it for me.

melloware avatar Feb 04 '24 00:02 melloware

👋 This is now possible! Check out the example in the readme: https://github.com/actions/upload-artifact#overwriting-an-artifact

This worked for me! Thanks for adding this

harry-s-grewal avatar Feb 21 '24 17:02 harry-s-grewal

Is this rolled out yet? we are seeing the following error on this workflow:

I'm having the same issue. Even with overwrite: true I'm seeing the same error.

SimonCockx avatar Apr 29 '24 10:04 SimonCockx