Open sni opened 7 months ago
👋 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!
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?
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.
@robherley I guess that will not work in matrix
@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.
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 :(
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 👋 I agree. Going to bring this back to the team considering how likely it'll be required. Thanks for the feedback!
@robherley: were you able to address the issue with the team?
👋 @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
👋 This is now possible! Check out the example in the readme: https://github.com/actions/upload-artifact#overwriting-an-artifact
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
Me too seeing this issue in v4. Downgrading to v3 fixes it for me.
👋 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
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.
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 usegeekyeggo/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.