diff --git a/.github/workflows/vercel-cleanup-pr.yml b/.github/workflows/vercel-cleanup-pr.yml new file mode 100644 index 0000000..2138d0c --- /dev/null +++ b/.github/workflows/vercel-cleanup-pr.yml @@ -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 + diff --git a/.github/workflows/vercel-cleanup-previous-preview.yml b/.github/workflows/vercel-cleanup-previous-preview.yml new file mode 100644 index 0000000..1df8114 --- /dev/null +++ b/.github/workflows/vercel-cleanup-previous-preview.yml @@ -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 diff --git a/.gitignore b/.gitignore index 32953f9..d04aabd 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ Thumbs.db src/assets/env.js .env + +.secret