Skip to content

Commit

Permalink
filter pruneable deployments based on PR number
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain89 committed Jun 10, 2024
1 parent 331bd37 commit f2fe468
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/prune-deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DELETE_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v13/deployments"
deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ")

# Filter the deployments list by meta.base_hash === meta tag.
filtered_deployments=$(echo $deployments | jq --arg META_TAG "$META_TAG" '[.deployments[] | select(.meta.base_hash | type == "string" and contains($META_TAG)) | .uid] | join(",")')
filtered_deployments=$(echo $deployments | jq --arg META_TAG "$META_TAG" '[.deployments[] | select(.meta.pr_number | type == "string" and contains($META_TAG)) | .uid] | join(",")')
filtered_deployments="${filtered_deployments//\"/}" # Remove double quotes

# Clears the values from filtered_deployments
Expand Down
14 changes: 1 addition & 13 deletions .github/workflows/delete-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,8 @@ jobs:
fetch-depth: 2
show-progress: false

- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Hash branch name
uses: pplanel/hash-calculator-action@v1.3.1
id: hash_branch
with:
input: ${{ steps.extract_branch.outputs.branch }}
method: MD5

- name: Prune preview deployments associated with merged PR
env:
META_TAG: ${{ steps.hash_branch.outputs.digest }}
META_TAG: ${{ github.event.number }}
run: |
bash .github/scripts/prune-deployment.sh

0 comments on commit f2fe468

Please sign in to comment.