Deletes containers that do not have tags from Github container registry (ghcr.io)
Note that this has not been fully tested with non-user orgs as the APIs differ. Use at your own risk
Required: The name of the package to delete
Required: Access token to use for deleting packages
Required: The name of the org that the package belongs to (if an organization, otherwise you can use user
or rely on automatic detection)
Required: The name of the user that the package belongs to
It is now possible (and recommended) to use an automatic Github Actions token rather than a person access token. Which repos are allowed to access which packages can be configured in "Manage Actions access" under the settings for a given package.
NOTE: This does not work with org-scoped packages. If you're having Package not found
errors when using secrets.GITHUB_TOKEN
, try using a personal access token instead. Follow this thread for details.
name: Remove old package versions
on:
workflow_dispatch:
inputs:
package_name:
description: 'The name of the package to delete'
required: true
jobs:
remove-package-versions:
runs-on: ubuntu-latest
steps:
- name: purge packages
uses: dylanratcliffe/delete-untagged-containers@main
with:
package_name: ${{ github.event.inputs.package_name }}
token: ${{ secrets.GITHUB_TOKEN }}
This example uses a personal access token with the following permissions:
read:packages
write:packages
delete:packages
name: Remove old package versions
on:
workflow_dispatch:
inputs:
package_name:
description: 'The name of the package to delete'
required: true
jobs:
remove-package-versions:
runs-on: ubuntu-latest
steps:
- name: purge packages
uses: dylanratcliffe/delete-untagged-containers@main
with:
package_name: ${{ github.event.inputs.package_name }}
# This is a person access token
token: ${{ secrets.CR_PAT }}