Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove uploaded artifact? #5

Closed
williamli opened this issue Aug 21, 2019 · 67 comments
Closed

How to remove uploaded artifact? #5

williamli opened this issue Aug 21, 2019 · 67 comments
Labels
enhancement New feature or request

Comments

@williamli
Copy link

It is possible to remove an uploaded artifact?

@eine
Copy link

eine commented Sep 5, 2019

ping...

@TingluoHuang
Copy link
Member

@madhurig for artifact questions

@madhurig
Copy link

madhurig commented Sep 5, 2019

Currently there is no experience to remove uploaded artifacts. Is there a scenario you have that you would need this feature for or are you looking to remove an artifact accidentally uploaded?

@eine
Copy link

eine commented Sep 5, 2019

Is there a scenario you have that you would need this feature for or are you looking to remove an artifact accidentally uploaded?

We expect to use GitHub Action and artifacts to provide 'nightly builds' without having to deal with GitHub Releases. I.e., we currently build a tarball and run tests with it, as a regular CI job. We expect to reuse the same tarball, instead of triggering all the release procedure (which is meant for tagged commits/releases).

In the situations when a tarball passes the tests but it is not valid because of any other reason, we want to remove the artifacts. This would allow us to tell users: you can pick the latest successful (green) run which contains artifacts, and ensure that the first file they download will work.

BTW, can you please have a look at #3?

@williamli
Copy link
Author

Is there a scenario you have that you would need this feature for or are you looking to remove an artifact accidentally uploaded?

@madhurig I was using artifacts to pass docker images and some gcloud configs between jobs so that I don't have to re-auth with the gcloud sdk in different jobs. It might not be the most optimised way but I was exploring that idea a few weeks ago. It will be good if we can remove these artifacts at the end of the jobs to clean up.

@madhurig
Copy link

madhurig commented Sep 6, 2019

@williamli - Thanks for elaborating. We will evaluate this feature.

@madhurig madhurig added the enhancement New feature or request label Sep 6, 2019
@Godin Godin mentioned this issue Oct 6, 2019
@arnavzoman
Copy link

We need this feature because there is a 1GB limits on artifacts and we do not need the older ones.

@mieszko4
Copy link

Is there some API to remove uploaded artifacts instead?
I would like to set up a github action cronjob to remove artifacts older than 1 month.

@kf6kjg
Copy link

kf6kjg commented Nov 28, 2019

As far as I can tell there’s not only no API, but no manual removal route either. This is because, as noted above, they’d not been evaluated the needed user experience. For instance, while they could release an api, would an expiration policy work better? Or maybe something else? Perhaps a totally different tool is needed, eg a cleaner way to pass messages or files from one job to another.
Hence they are on the discovery phase for this and need our input on how and why we are using artifacts.

ATM my use case is that of inter job communications. Later I might use artifacts to hold build or test results for review.

@mieszko4
Copy link

Thanx @kf6kjg
For me I guess expiration policy would work, too.

I mean, not having a way to remove artifacts and at the same time billing for over-filled storage is a contradiction to me.

Btw my usecase: we integrated cypress with videos stored as artifacts - there is no need to have them for longer than few days.

@mscoutermarsh
Copy link

Hi all, we're working on an API for deleting an artifact. Thanks for sharing your use cases ❤️.

I don't have a timeline yet that I can share on when it will be available.

@hellwolf
Copy link

hellwolf commented Dec 16, 2019

There is a workaround, you could create an empty directory and upload a new artifact of the same name with path of the empty directory.

      - name: create empty directory
        run: |
          mkdir empty.d

      - name: empty dist archive
        uses: actions/upload-artifact@v1
        with:
          name: dist
          path: empty.d

Example: https://github.com/rtoken-project/rdai/blob/master/.github/workflows/cd.yml

Update: it seems github changed some logic, the workround is no longer working!!

@kf6kjg
Copy link

kf6kjg commented Dec 16, 2019

Unless there's special server code for that case, a zip file of an empty directory still occupies ~80kB of space. Certainly less than the zip it replaced, but continual growth is still growth even if you manage to reduce the rate.
All that said, while I don't consider it a workaround, @hellwolf you've got a clever technique to reduce the impact. Thanks! :D

@dodie
Copy link

dodie commented Jan 16, 2020

I could not manage to make @hellwolf 's workaround to work:

After uploading the empty folder with the same name as an artifact I could download the original artifact from action's UI, and the size displayed matched with the original file size as if nothing changed.

When I added an empty file to empty.d with the name of the original file, I could no longer access the original file as if it was replaced by the empty one, but the UI still displayed the original file size.

Even though I could not access the artifact in the last case, I'm not sure it's actually replaced with the empty file behind the scenes.

@hellwolf
Copy link

@dodie yes, it seems github changed some logic, the workround is no longer working!!

@dentarg
Copy link

dentarg commented Jan 16, 2020

@gimenete
Copy link
Contributor

Actions engineer here 👋 There's now the possibility to delete the artifact in the UI. You'll see a trash can icon if you have permissions to write in the repository contents.

Screen Shot 2020-01-07 at 16 08 06

@xt0rted
Copy link

xt0rted commented Jan 16, 2020

@gimenete not sure if this is intentional or not but there's no confirmation dialog on mobile like there is on desktop.

@konradpabjan
Copy link
Collaborator

@dodie @hellwolf @dentarg The workaround should no longer work, we recently made some backend changes to our artifacts service. The recent changes to the download experience were part of a broader backend update but not directly responsible for the workaroud no longer working.

Recommend to use the new UI now 😀 That will completely delete the artifact and there won't be any empty directories.

I've updated the README in this repo with some information about deleting an artifact from the UI with a new screenshot. A DELETE API for artifacts is in development so there will be more ways to delete an artifact down the road. Going to close this issue now that there is at least one way to delete an artifact.

@JCMais
Copy link

JCMais commented Jan 16, 2020

is it possible to remove the artifacts from an action / api?

@eine
Copy link

eine commented Jan 16, 2020

is it possible to remove the artifacts from an action / api?

A DELETE API for artifacts is in development so there will be more ways to delete an artifact down the road.

@chrispat
Copy link
Member

https://developer.github.com/v3/actions/artifacts/#delete-an-artifact

@kf6kjg
Copy link

kf6kjg commented Jan 28, 2020

And there was joyful singing! Now to get that incorporated into the actions that need it! :D

@jacek-jablonski
Copy link

Any news on this? Would love to see actions/delete-artifact official action.

@steve-taylor
Copy link

Currently there is no experience to remove uploaded artifacts. Is there a scenario you have that you would need this feature for or are you looking to remove an artifact accidentally uploaded?

That's a joke, right?

The scenario is that 30 well paid developers are suddenly and completely blocked because artifacts are unnecessarily persisted beyond the workflow run.

thenewguy added a commit to thenewguy/ippsample that referenced this issue Oct 11, 2021
per actions/upload-artifact#5 there is no way
to automatically remove them after this job completes
@SKuhlmanns SKuhlmanns mentioned this issue Oct 11, 2021
6 tasks
@princemokut
Copy link

It's almost 12 hours since I deleted artifacts from all previous workflow run and I still get this error: "Create Artifact Container failed: Artifact storage quota has been hit. Unable to upload any new artifacts". This is frustrating our agile process. And I have removed spending limit for about an hour too, still can't run my workflow successfully... :(

@framerate
Copy link

framerate commented Jun 22, 2022

@princemokut How did you solve your problem? I'm hitting it now, 6 months later and can't figure out how to increase my quota (and I deleted my old artifacts). I'm blocked!

Edit it looks like its a caching issue and eventually it "fixes itself". Ugh..

kkourt added a commit to cilium/tetragon that referenced this issue Aug 8, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Intsead, this patch truncates them so
at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this issue Aug 8, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Intsead, this patch truncates them so
at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this issue Aug 8, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Instead, this patch truncates the
build artifact so at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this issue Aug 10, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Instead, this patch truncates the
build artifact so at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this issue Aug 10, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Instead, this patch truncates the
build artifact so at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this issue Aug 10, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Instead, this patch truncates the
build artifact so at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
kkourt added a commit to cilium/tetragon that referenced this issue Aug 10, 2022
There does not seem to be an easy way to delete artifacts of the
existing run (see details below). Instead, this patch truncates the
build artifact so at least we do not waste space.

I tried the following:
- name: Delete artifacts
uses: actions/github-script@v3
with:
  github-token: ${{ github.token }}
  script: |
    const {GITHUB_RUN_ID, GITHUB_REPOSITORY} = process.env
    const artifactsURL = `/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts`
    console.log(`Deleting artifacs from ${artifactsURL}`)
    const response = await github.request(`GET ${artifactsURL}`)
    console.log(response.data)
    for (artifact of response.data.artifacts) {
	  console.log(`Deleting artifact with name=${artifact.name}, id=${artifact.id}`)
	  const deleteResponse = await github.request(`DELETE /repos/${repo}/actions/artifacts/${artifact.id}`)
    }

But it did not work, because the GITHUB_RUN_ID does not seem to be available over the REST API until
after the action is finished.

The logs from my action printed:
Deleting artifacs from /repos/cilium/tetragon/actions/runs/2817658181/artifacts
...
{ total_count: 0, artifacts: [] }

But if I curl the above URL after the action, I get:
{
  "total_count": 1,
  "artifacts": [
    {
      "id": 322874447,
      "node_id": "MDg6QXJ0aWZhY3QzMjI4NzQ0NDc=",
      "name": "tetragon-build",
      "size_in_bytes": 6,
      "url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447",
      "archive_download_url": "https://api.github.com/repos/cilium/tetragon/actions/artifacts/322874447/zip",
      "expired": false,
      "created_at": "2022-08-08T11:50:54Z",
      "updated_at": "2022-08-08T11:50:54Z",
      "expires_at": "2022-08-13T11:49:30Z",
      "workflow_run": {
        "id": 2817658181,
        "repository_id": 473137633,
        "head_repository_id": 473137633,
        "head_branch": "pr/kkourt/lvhtest",
        "head_sha": "ea22990af2283c38aac92f7e6febacabf3786280"
      }
    }
  ]
}

For (even) more context, see: actions/upload-artifact#5

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
@vHeemstra
Copy link

vHeemstra commented Jan 9, 2023

The actions/github-script approach still can't find any artifacts for a running workflow and thus can't delete them.

But I found geekyeggo/delete-artifact@v2 which does remove artifacts created in the same workflow before finishing the workflow.

@otaviobertucini
Copy link

otaviobertucini commented Jan 23, 2023

It's almost 12 hours since I deleted artifacts from all previous workflow run and I still get this error: "Create Artifact Container failed: Artifact storage quota has been hit. Unable to upload any new artifacts". This is frustrating our agile process. And I have removed spending limit for about an hour too, still can't run my workflow successfully... :(

I managed to stop this error by adding a new step on my deploy script:

  - name: Delete Old Artifacts
    uses: actions/github-script@v6
    id: artifact
    with:
      script: |
        const res = await github.rest.actions.listArtifactsForRepo({
          owner: context.repo.owner,
          repo: context.repo.repo,
        })

        res.data.artifacts
          .forEach(({ id }) => {
            github.rest.actions.deleteArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: id,
            })
          })

Place it right above the upload step and it will delete all previous artifacts of the repo.

@kolpav
Copy link

kolpav commented Jan 23, 2023

I am starting to think that having to

And I have removed spending limit

is feature not a bug and with my tinfoil hat on I would guess theres number of such people glowing somewhere in GH HQ.

for people landing from google here have this (if solutions from this issue are not working)

# https://github.com/actions/upload-artifact/issues/290#issuecomment-1374207010

name: Test

on:
  workflow_run:
    branches: [main]
    workflows: [nonprod,prod,test]
    types:
      - completed
jobs:
  on-success:
    runs-on: ubuntu-latest
    name: Delete artifact
    if: github.event.workflow_run.head_branch == 'main' # feel free to take this out if you don't need it
    steps:
      - id: get-id
        run: | # grab the id of the artifact we just created
          echo "ARTIFACT_ID=$(gh api -H 'Accept: application/vnd.github+json'   ${{github.event.workflow_run.artifacts_url}} --jq .artifacts[].id)" >> $GITHUB_ENV
        env:
          GITHUB_TOKEN: ${{ secrets.GH_REPO_ACCESS_PAT }}
      - run: |
          echo "artifact id is ${{ env.ARTIFACT_ID}}"
          echo "run url is ${{github.event.workflow_run.artifacts_url}}"
      - id: delete-artifact
        run: | # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#delete-an-artifact
          gh api --method DELETE -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/actions/artifacts/${{env.ARTIFACT_ID}}
        env:
          GITHUB_TOKEN: ${{ secrets.GH_REPO_ACCESS_PAT }}
  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - run: echo 'The triggering workflow failed'

@DPatrickBoyd
Copy link

I am starting to think that having to

And I have removed spending limit

is feature not a bug and with my tinfoil hat on I would guess theres number of such people glowing somewhere in GH HQ.

for people landing from google here have this (if solutions from this issue are not working)

# https://github.com/actions/upload-artifact/issues/290#issuecomment-1374207010

name: Test

on:
  workflow_run:
    branches: [main]
    workflows: [nonprod,prod,test]
    types:
      - completed
jobs:
  on-success:
    runs-on: ubuntu-latest
    name: Delete artifact
    if: github.event.workflow_run.head_branch == 'main' # feel free to take this out if you don't need it
    steps:
      - id: get-id
        run: | # grab the id of the artifact we just created
          echo "ARTIFACT_ID=$(gh api -H 'Accept: application/vnd.github+json'   ${{github.event.workflow_run.artifacts_url}} --jq .artifacts[].id)" >> $GITHUB_ENV
        env:
          GITHUB_TOKEN: ${{ secrets.GH_REPO_ACCESS_PAT }}
      - run: |
          echo "artifact id is ${{ env.ARTIFACT_ID}}"
          echo "run url is ${{github.event.workflow_run.artifacts_url}}"
      - id: delete-artifact
        run: | # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#delete-an-artifact
          gh api --method DELETE -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/actions/artifacts/${{env.ARTIFACT_ID}}
        env:
          GITHUB_TOKEN: ${{ secrets.GH_REPO_ACCESS_PAT }}
  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - run: echo 'The triggering workflow failed'

hey this is my workflow :)

I have a stand alone script on CLI that will delete artifacts based on creation date:

https://gist.github.com/DPatrickBoyd/afb54165df0f51903be3f0edea77f9cb

@NHAS
Copy link

NHAS commented Jun 11, 2023

Why is this issue closed? There still doesnt seem to be a particularly good way to remove artifacts?

@danijeljw-RPC
Copy link

The issue is not resolved. Continuously closing it is not solving any problems and you've not addressed what people are raising. This has completely stopped my workflow and I need it to resolve to deploy something into prod.

@relrod
Copy link

relrod commented Aug 31, 2023

+1 for an official actions/delete-artifact please.

@tymocoder
Copy link

Do we have any workarounds on how to delete not all artifacts, but those associated with certain branches? Something using ${{ github.head_ref }} ?

@rathorer
Copy link

rathorer commented Nov 28, 2023

It's almost 12 hours since I deleted artifacts from all previous workflow run and I still get this error: "Create Artifact Container failed: Artifact storage quota has been hit. Unable to upload any new artifacts". This is frustrating our agile process. And I have removed spending limit for about an hour too, still can't run my workflow successfully... :(

I managed to stop this error by adding a new step on my deploy script:

  - name: Delete Old Artifacts
    uses: actions/github-script@v6
    id: artifact
    with:
      script: |
        const res = await github.rest.actions.listArtifactsForRepo({
          owner: context.repo.owner,
          repo: context.repo.repo,
        })

        res.data.artifacts
          .forEach(({ id }) => {
            github.rest.actions.deleteArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: id,
            })
          })

Place it right above the upload step and it will delete all previous artifacts of the repo.

Not sure if this is completely fixed.
I was facing issue with quota and my pipeline was not running, I could not see any option to delete artifacts from UI, so I used the yml solution to delete all old artifacts. But I am still facing same error.
Create Artifact Container failed: Artifact storage quota has been hit. Unable to upload any new artifacts
I also used the artifacts APIs (via curl) to list artifacts, it shows me 0 artifacts:

.github.com/repos/rathorer/proprank/actions/artifacts
{
  "total_count": 0,
  "artifacts": [

  ]
}

but the error doesn't go away. Not sure why its keep complaining even if there are no artifacts.
This is frustrating, I already spent 3-4 days on this.

@JudgeGazza
Copy link

This seems to work:

https://github.com/marketplace/actions/delete-artifact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests