This action will allow you to remove older versions of all GitHub Packages in a private repository.
To use the action, simply refer to it in your workflow:
name: Remove package versions
on: push
jobs:
remove-package-versions:
runs-on: ubuntu-latest
steps:
- name: Remove package versions
id: remove-package-versions
uses: navikt/remove-package-versions@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
The above example will trigger the action whenever the push
event occurs. All events that can be used are found in the GitHub documentation.
If you want to run the action periodically instead, use a scheduled workflow:
name: Remove package versions
on:
schedule:
- cron: '0 8 * * *'
jobs:
remove-package-versions:
runs-on: ubuntu-latest
steps:
- name: Remove package versions
id: remove-package-versions
uses: navikt/remove-package-versions@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Note: The underlying HTTP client in this action does not currently do any pagination which means it has a hard limit on 100 packages, and 100 versions per package when fetching the packages / versions to determine what to remove.
The action uses the following environment variables:
A valid token that is used to interact with GitHubs API. This token must have the following scopes:
repo
read:packages
delete:packages
As seen from the above example the autogenerated installation token within a workflow run can be used, so there is no need to generate a personal access token for this purpose.
This environment variable is automatically available inside a workflow run, and the format is owner:repo
, for instance navikt/remove-package-versions
.
The action supports the following parameters:
Number of versions to keep per package. Defaults to 5
.
Wheter or not to keep the latest
version. Defaults to true
.
Whether or not to remove semantic versions. Defaults to false
.
Keep in mind that if you use date-based versions with .
as a separator, for instance yyyy.mm.dd-<sha>
, some dates are valid semantic versions, while others aren't. The ones who aren't valid semantic versions are the ones who have the month or day parts of the date starting with 0
, for instance 2019.12.01
. When using date-based versions it's advisable to use -
as a separator instead of .
.
The action outputs a JSON-encoded list of removed package versions prefixed with the owner and the repository name. The name of the output is removed_package_versions
. Using the id
from the workflow example above, you can refer to the output using ${{ steps.remove-package-versions.outputs.removed_package_versions }}
.
Use the release.sh
script to easily tag the main
branch:
./release.sh v1.2.3
will create three tags, all pointing to HEAD
:
v1
v1.2
v1.2.3
The script will also ask if you want to push the tags. Existing major and/or minor tags will be replaced.
MIT, see LICENSE.