Skip to content

Commit

Permalink
add cron to prune tags
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Jun 6, 2024
1 parent f26245b commit acd0bd9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
publish: pnpm run changeset:release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_ORG_PERMISSIONLESS_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_ORG_PIMLICO_TOKEN }}
57 changes: 57 additions & 0 deletions .github/workflows/prune-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 }}

0 comments on commit acd0bd9

Please sign in to comment.