GitHub Actions to remove unused npm packages from github registry

Viewed 24

I am trying to remove all the published versions not downloaded or not downloaded after sometimes. I found one GH-Action actions/delete-package-versions, It allows to remove old versions or pre-released versions. It is close to what I need but not based on download number or date base but it would be okay to be see this one in action.

The problem is when I run this action, there are no visible results and I am not able to find why.

- uses: actions/delete-package-versions@v3
  with:
    owner: 'github'
    repo: 'packages'
    package-name: 'test-package'
    token: ${{ secrets.PAT }}
    min-versions-to-keep: 2

https://github.com/actions/delete-package-versions

1 Answers

I posted an issue on their GitHub about that:

https://github.com/actions/delete-package-versions/issues/78

I was experiencing the same problem - it seems that this action doesn't work a all.

I ended up writing my own cleanup one-liner based on GitHub CLI:

touch emptyfile #workaround the problem for empty POST in CLI
gh api /orgs/${ORG}/packages/npm/{$PACKAGE__NAME}/versions --paginate -q '.[].id' | tail -n +101 | xargs -n1 -I {} gh api --method DELETE /orgs/${ORG}/packages/npm/${PACKAGE__NAME}/versions/{} --input emptyfile

This will only leave you last 100 versions.

Related