All Projects → christian-korneck → delete-run-artifacts-action

christian-korneck / delete-run-artifacts-action

Licence: MIT License
github action to delete artifacts at the end of a workflow run

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to delete-run-artifacts-action

jcefbuild
Binary builds of java-cef
Stars: ✭ 160 (+661.9%)
Mutual labels:  github-workflow, github-actions
action-github-workflow-sync
Github Action To Sync Github Action's Workflow Files Across Repositories
Stars: ✭ 51 (+142.86%)
Mutual labels:  github-workflow, github-actions
update-container-description-action
github action to update a Docker Hub, Quay or Harbor repository description from a README file
Stars: ✭ 20 (-4.76%)
Mutual labels:  github-workflow, github-actions
python-actions-alpha-archived
Please note that this was for the *alpha* version of GitHub Actions for Python.
Stars: ✭ 15 (-28.57%)
Mutual labels:  github-workflow, github-actions
GradleMavenPush
Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Central, Corporate staging/snapshot servers and local Maven repositories).
Stars: ✭ 21 (+0%)
Mutual labels:  artifacts, artifact
prettier
🔨 Native, blazingly-fast Prettier CLI on Github Actions
Stars: ✭ 19 (-9.52%)
Mutual labels:  github-workflow, github-actions
actions-pixela
GitHub Actions for Pixela (a-know/pi) - a-know/pi Setup Action. Linux (Ubuntu), macOS, and Windows are supported.
Stars: ✭ 12 (-42.86%)
Mutual labels:  github-actions
install-swift
GitHub Action to install a version of Swift 🏎
Stars: ✭ 23 (+9.52%)
Mutual labels:  github-actions
setup-clang
GitHub action to set up Clang & LLVM
Stars: ✭ 28 (+33.33%)
Mutual labels:  github-actions
action-label-syncer
GitHub Action to sync GitHub labels in the declarative way
Stars: ✭ 138 (+557.14%)
Mutual labels:  github-actions
metadatamanagement
Metadatamanagement (MDM) - Data Search for Higher Education Research and Science Studies
Stars: ✭ 21 (+0%)
Mutual labels:  github-actions
github-readme-learn-section-notion
Update your github README with data fetched from a notion database
Stars: ✭ 24 (+14.29%)
Mutual labels:  github-actions
github-actions-automate-projects
GitHub Actions adding GitHub Issues & Pull requests to the specified GitHub Project column automatically ♻️
Stars: ✭ 44 (+109.52%)
Mutual labels:  github-actions
pytest-coverage-comment
Comments a pull request with the pytest code coverage badge and full report
Stars: ✭ 32 (+52.38%)
Mutual labels:  github-actions
arduino-lint-action
GitHub Actions action to check Arduino projects for problems
Stars: ✭ 20 (-4.76%)
Mutual labels:  github-actions
content-reminder
⏰ A GitHub Action that reminds you to share your own content
Stars: ✭ 28 (+33.33%)
Mutual labels:  github-actions
maven-settings-action
This action setup maven settings.xml
Stars: ✭ 39 (+85.71%)
Mutual labels:  github-actions
nodejs-postgresql-azure
Repositório responsável pela série de artigos sobre Node.js com PostgreSQL
Stars: ✭ 70 (+233.33%)
Mutual labels:  github-actions
purescript-github-actions-toolkit
PureScript wrapper around GitHub's Actions Toolkit
Stars: ✭ 21 (+0%)
Mutual labels:  github-actions
setup-scheme
Github Actions CI / CD setup for Scheme
Stars: ✭ 13 (-38.1%)
Mutual labels:  github-actions

WARNING: This action deletes data. Use with care and at your own risk.

testrun

delete-run-artifacts

This github action deletes all artifacts generated by a github workflow run. It's intended to be used to delete all artifacts generated by a run at the end of this run.

This can be useful if your workflow temporarily stores artifacts and they're not needed anymore by the end of the run (i.e. because they got uploaded or published as a release by one of the steps). Deleting these redundant artifacts at the end of the run saves storage space (which is limited for private repos).

How to use

This action requires a bit more preparation in your repo than most other actions. Because artifacts cannot get deleted during a workflow run (only after a run has completed), we need to spawn a separate workflow run for the deletion by a webhook at the end of the main workflow run.

First, create a personal access token (required to call a webhook):

then store the token as a secret in the repo, so that the workflow can use it:

  • in your github repo settings: Settings tab -> Secrets -> add a new secret
    • Name: FOR_WEBHOOKS_SECRET
    • Value: <YOUR-TOKEN>

then create a file in your repo .github/workflows/webhook_target.yml with:

name: delete calling job's artifacts
on: repository_dispatch
jobs:
  main:
    runs-on: ubuntu-latest
    steps:
    - name: Delete artifacts
      if: github.event.action == 'delete_all_artifacts'
      uses: christian-korneck/delete-run-artifacts-action@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        parent_runid: ${{ github.event.client_payload.parent_runid  }}
        parent_repo: ${{ github.event.client_payload.parent_repo }}

and finally add the following cleanup job to your actual workflow (i.e. in .github/workflows/workflow.yml). Make sure that needs: points to your last job in the workflow, otherwise the cleanup might run too early.

name: your workflow
on: [push]
  your_last_job:
    (... add your stuff here ...)
  cleanup_job:
    needs: [your_last_job]
    if: always()
    runs-on: ubuntu-latest
    steps:
    - name: call webhook to delete artifacts
      env:
        FOR_WEBHOOKS_SECRET: ${{ secrets.FOR_WEBHOOKS_SECRET }}
      run: |
        echo "::add-mask::$FOR_WEBHOOKS_SECRET"
        curl --verbose --fail --show-error --location --request POST "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" --header "Authorization: token $FOR_WEBHOOKS_SECRET" --header 'Content-Type: application/json' --header 'Accept: application/vnd.github.everest-preview+json' --data-raw "{ \"event_type\": \"delete_all_artifacts\", \"client_payload\": {\"parent_runid\": \"$GITHUB_RUN_ID\", \"parent_repo\": \"$GITHUB_REPOSITORY\"} }"

Please note: Due to a github limitation, the file .github/workflows/webhook_target.yml needs to be always present in your master or default branch. The action will work with any branch however.

(Check this repo or the .github/workflow dir for a working example)

Reference

The action can also be used without a webhook on any past workflow run:

Inputs

parent_repo

Required the github repo that hosts the parent github workflow run. Example: "github-user/hello-world".

parent_runid

Required the id of the parent github workflow run whos artifacts should get deleted. Example: "0000000".

Outputs

none (just succeeds or fails)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].