Adds Github Actions to Clean Vercel Deployments

This commit is contained in:
2023-12-29 03:22:00 -03:00
parent 04ab3446df
commit 139b20984c
3 changed files with 62 additions and 0 deletions

27
.github/workflows/vercel-cleanup-pr.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
name: vercel-cleanup-pr
on:
pull_request:
types: [closed]
env:
VERCEL_CLI_TOKEN: ${{ secrets.VERCEL_CLI_TOKEN }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
GITHUB_PR_ID: ${{github.event.pull_request.number}}
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Cleanup Vercel Deployments
run: |
closed_deployments=$(curl "https://api.vercel.com/v6/deployments?projectId=$VERCEL_PROJECT_ID" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${VERCEL_CLI_TOKEN}" | jq -r ".deployments[] | select(.meta.githubPrId == \"${GITHUB_PR_ID}\") | .uid")
for deployment in $closed_deployments; do
echo "Deleting Deployment: $deployment"
curl "https://api.vercel.com/v6/now/deployments/$deployment" \
-X DELETE \
-H "Authorization: Bearer ${VERCEL_CLI_TOKEN}"
done

View File

@@ -0,0 +1,33 @@
name: vercel-cleanup-preview
on:
push:
branches:
- '*'
- '!main'
- '!devel'
env:
VERCEL_CLI_TOKEN: ${{ secrets.VERCEL_CLI_TOKEN }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
GIT_PREVIOS_COMMIT: ${{github.event.before}}
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cleanup Vercel Deployments
run: |
invalid_deployments=$(curl "https://api.vercel.com/v6/deployments?projectId=$VERCEL_PROJECT_ID" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${VERCEL_CLI_TOKEN}" | jq -r ".deployments[] | select(.meta.githubCommitSha == \"${GIT_PREVIOS_COMMIT}\") | .uid")
for deployment in $invalid_deployments; do
echo "Deleting Deployment: $deployment"
curl "https://api.vercel.com/v6/now/deployments/$deployment" \
-X DELETE \
-H "Authorization: Bearer ${VERCEL_CLI_TOKEN}"
done