add script for deleting old deployments in Vercel#2300
add script for deleting old deployments in Vercel#2300witoszekdev wants to merge 3 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
There was a problem hiding this comment.
Pull request overview
Adds a small utility under scripts/ to help identify and bulk-delete Vercel deployments for a given app by generating a UID list, along with usage documentation for running the workflow from the CLI.
Changes:
- Added
list-old-deployments.pyto fetch/paginate Vercel deployments, identify the current promoted production deployment, and output non-current deployment UIDs for deletion. - Added
scripts/README.mddocumenting prerequisites and the batch deletion workflow using Vercel CLI.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| scripts/list-old-deployments.py | Implements deployment listing/pagination and writes a UID file intended for bulk deletion. |
| scripts/README.md | Documents how to run the script and delete deployments in batches. |
| ### Prerequisites | ||
|
|
||
| - Vercel CLI installed and authenticated (`vercel login`) | ||
| - Access to the `saleorcommerce` scope | ||
|
|
||
| ### Usage | ||
|
|
||
| 1. Edit `APP_NAME` in the script to the target app. | ||
|
|
||
| 2. Run the script to generate the list: | ||
|
|
||
| ```bash | ||
| python3 scripts/list-old-deployments.py | ||
| ``` |
There was a problem hiding this comment.
This script uses Python 3.10+ typing syntax (list[dict], int | None). The README only says python3; please document the minimum required Python version (or switch to typing.List/Optional if you want broader compatibility).
| 4. Delete all remaining deployments (Vercel will show the list and ask for confirmation): | ||
|
|
||
| ```bash | ||
| vercel remove $(cat old-deployment-uids.txt) --scope saleorcommerce | ||
| ``` |
There was a problem hiding this comment.
The sed -i '' ... examples are BSD/macOS-specific; on GNU/Linux sed -i syntax differs. Please either mention the platform assumption or provide a Linux-compatible alternative command in the README so the instructions work for all contributors.
| @@ -0,0 +1,123 @@ | |||
| #!/usr/bin/env python3 | |||
| """List all Vercel deployments for saleor-app-smtp that are older than the current production deployment.""" | |||
There was a problem hiding this comment.
The module docstring says this lists deployments for saleor-app-smtp and that they are "older than the current production deployment", but the script defaults APP_NAME to saleor-app-products-feed and the later filter includes all non-current-production deployments regardless of age. Please update the docstring to match the actual behavior (or adjust the filtering logic to match the docstring).
| """List all Vercel deployments for saleor-app-smtp that are older than the current production deployment.""" | |
| """List Vercel deployments for the app defined in APP_NAME (default: saleor-app-products-feed), showing the current production deployment and all other non-current-production deployments.""" |
| # Filter: everything except current production, not already soft-deleted | ||
| old_deps = [ | ||
| d | ||
| for d in all_deps | ||
| if d["uid"] != current_prod["uid"] and not d.get("softDeletedByRetention") | ||
| ] | ||
|
|
||
| print( | ||
| f"\nOld deployments to delete: {len(old_deps)} (out of {len(all_deps)} total)\n", | ||
| file=sys.stderr, | ||
| ) |
There was a problem hiding this comment.
old_deps is described/printed as "Old deployments" but the filter currently removes only the current promoted production deployment. This will also include preview (and even newer-than-production) deployments, which makes it easy to accidentally delete recent previews someone may still be using. If the intent is truly "older than current production", filter by created < current_prod['created'] (and possibly also keep the newest preview per branch); otherwise rename the variable/output to reflect "non-current production" instead of "old".
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2300 +/- ##
=======================================
Coverage 37.24% 37.24%
=======================================
Files 1015 1015
Lines 65929 65929
Branches 3391 3391
=======================================
Hits 24557 24557
Misses 40997 40997
Partials 375 375
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
why not typescript? |
With this script we can delete old deployments in Vercel, tested already for smtp and product-feed apps