Skip to content

Prune NPM tags

Prune NPM tags #161

Workflow file for this run

name: Prune NPM tags
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
prune:
name: Prune NPM tags
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 'latest'
- name: Setup .npmrc file
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
- name: Prune @pimlico/alto tags
run: |
PACKAGE_NAME=$(jq -r '.name' package.json)
npm view $PACKAGE_NAME dist-tags --json | jq -r 'to_entries | .[] | select(.key != "latest") | select(.key != "main") | select(.key != "next") | .key' | xargs -I % npm dist-tag rm $PACKAGE_NAME %
working-directory: src
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ORG_PIMLICO_TOKEN }}
- name: Deprecate @pimlico/alto canary versions
working-directory: src
run: |
PACKAGE_NAME=$(jq -r '.name' package.json)
TWO_DAYS_AGO=$(date --date='2 days ago' +%s)
FOUR_DAYS_AGO=$(date --date='4 days ago' +%s)
npm view $PACKAGE_NAME time --json | jq -c 'to_entries | .[] | select(.key | test("^0.0.0-.+$"))' \
| while read line; do
VERSION=$(echo $line | jq -r '.key')
TIME=$(echo $line | jq -r '.value')
PUBLISH_DATE=$(date --date=$TIME +%s)
if [ $PUBLISH_DATE -lt $FOUR_DAYS_AGO ]; then
continue # skip versions older than 4 days to reduce the number of npm deprecate calls
fi
if [ $PUBLISH_DATE -lt $TWO_DAYS_AGO ]; then
echo "Deprecate $PACKAGE_NAME@$VERSION"
npm deprecate $PACKAGE_NAME@$VERSION "This canary version is deprecated because it is older than 2 days." || true
echo "Deprecated $PACKAGE_NAME@$VERSION"
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ORG_PIMLICO_TOKEN }}