actions / upload-artifact

MIT License
3.17k stars 711 forks source link

[feat req] Allow `retention-days` to be `0` #290

Open kolpav opened 2 years ago

kolpav commented 2 years ago

What would you like to be added?

Allow retention-days to be 0 meaning do not store artifacts after workflow run.

Why is this needed?


These solutions might be proposed but actually doesn't solve the problem with few points why I think they don't.

Use UI

Use API

Use action from marketplace

This issue is duplicate

praenubilus commented 2 years ago

Can't believe it, the original issue was created 3 years ago and it still has no official action

kolpav commented 2 years ago

@praenubilus I share your disbelief. To be completely honest I wouldn't be surprised if this is "by design" or fix would be very hard to approve in github's chain of command because people would stop polluting their storage with useless artifacts just to share data between jobs (build -> test -> deploy) it would decrease amount of people

but lets not jump to conclusions and wait for feedback.

praenubilus commented 2 years ago

@kolpav I hope the day it comes out I am still alive

Koushikphy commented 2 years ago

I was releasing nodejs application binary with GitHub workflow for different os and architecture. In the initial stage, I was testing different workflow patterns and quickly hit the quota limit. I don't really need the artifacts after the workflow is run and the artifacts are released. It's disappointing to see that it does not have the delete option when the workflow si complete.

yanniboi commented 2 years ago

Currently we have to manually delete the artifacts after every run. This would be so much easier if we could just set them to be removed after the run automatically.

laureanray commented 2 years ago

This seems like it should've been implemented in the first place. I've been constantly reaching artifact storage quota errors. 😞

DPatrickBoyd commented 1 year ago

here is an example that I just got to work for deletion after a run is done. This is triggered from the workflow that made the artifact secrets.GH_REPO_ACCESS_PAT is a PAT that I made and gave it the ability read repos and org stuff as well, not sure how important the scope is.

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'
kolpav commented 1 year ago

@DPatrickBoyd I linked your comment if you don't mind :) https://github.com/kolpav/purge-artifacts-action/blob/master/README.md

DPatrickBoyd commented 1 year ago

@DPatrickBoyd I linked your comment if you don't mind :) https://github.com/kolpav/purge-artifacts-action/blob/master/README.md

not a problem! glad to help anyone else out, I have been saved so many times in the past by a random github comment so trying to return the favor

zumbiepig commented 5 months ago

bump

brmb commented 23 hours ago

bump!