Skip to content

Cleanup

Cleanup #13899

Workflow file for this run

name: Cleanup
on:
registry_package:
types: [published, updated]
workflow_call:
inputs:
keep-days:
type: number
default: 30
required: false
permissions:
packages: write # gh api ... DELETE package versions
jobs:
cleanup:
runs-on: ubuntu-slim
env:
GH_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
PACKAGE_NAME: ${{ github.event.registry_package.name }}
KEEP_DAYS: ${{ inputs.keep-days || 30 }}
steps:
# actions/delete-package-versions only supports keeping a fixed count of
# versions, not an age cutoff, and is stuck on a Node 20 runtime with no newer
# release available -- hence the inline script instead of the action.
- name: Delete preview package versions older than ${{ env.KEEP_DAYS }} days
run: |
set -euo pipefail
cutoff=$(date -u -d "-${KEEP_DAYS} days" +%s)
gh api --paginate "/orgs/${OWNER}/packages/nuget/${PACKAGE_NAME}/versions" \
--jq '.[] | [.id, .name, .created_at] | @tsv' |
while IFS=$'\t' read -r id name created; do
[[ "$name" == *-preview* ]] || continue
created_ts=$(date -u -d "$created" +%s)
if [ "$created_ts" -lt "$cutoff" ]; then
echo "Deleting $name ($id), created $created"
gh api -X DELETE "/orgs/${OWNER}/packages/nuget/${PACKAGE_NAME}/versions/${id}"
fi
done