Skip to content

Commit 32bcdb8

Browse files
authored
fix: cicd, delete vercel pre (ChatGPTNextWeb#3910)
1 parent 5ce1a55 commit 32bcdb8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

.github/workflows/deploy_preview.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ jobs:
6464
env:
6565
META_TAG: ${{ steps.hash_branch.outputs.digest }}-${{ github.run_number }}-${{ github.run_attempt}}
6666
run: |
67+
set -e
6768
vercel pull --yes --environment=preview --token=${VERCEL_TOKEN}
6869
vercel build --token=${VERCEL_TOKEN}
6970
vercel deploy --prebuilt --archive=tgz --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }}
7071
71-
vercel ls --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }} &> vercel-output
72-
DEFAULT_URL=$(cat vercel-output | grep http | awk '{print $2}')
72+
DEFAULT_URL=$(vercel ls --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }})
73+
echo "preview URL:${DEFAULT_URL} , alias URL:${{ steps.set_env.outputs.VERCEL_ALIAS_DOMAIN }}"
7374
ALIAS_URL=$(vercel alias set ${DEFAULT_URL} ${{ steps.set_env.outputs.VERCEL_ALIAS_DOMAIN }} --token=${VERCEL_TOKEN} --scope ${VERCEL_TEAM}| awk '{print $3}')
7475
7576
echo "New preview URL: ${DEFAULT_URL}"
7677
echo "New alias URL: ${ALIAS_URL}"
77-
echo "META_TAG=${META_TAG}"
7878
echo "VERCEL_URL=${ALIAS_URL}" >> "$GITHUB_OUTPUT"
7979
8080
- uses: mshick/add-pr-comment@v2
8181
with:
8282
message: |
8383
Your build has completed!
8484
85-
[Preview deployment](${{ steps.vercel.outputs.VERCEL_URL }})
85+
[Preview deployment](${{ steps.vercel.outputs.VERCEL_URL }})

scripts/delete-deployment-preview.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ GET_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v6/deployments"
77
DELETE_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v13/deployments"
88

99
# Create a list of deployments.
10-
# deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ")
11-
deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID" -H "Authorization: Bearer $VERCEL_TOKEN ")
10+
deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ")
11+
#deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID" -H "Authorization: Bearer $VERCEL_TOKEN ")
1212

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

1717
# Clears the values from filtered_deployments
@@ -24,7 +24,7 @@ echo "Filtered deployments ${filtered_deployments}"
2424
for uid in "${values[@]}"; do
2525
echo "Deleting ${uid}"
2626

27-
delete_url=${DELETE_DEPLOYMENTS_ENDPOINT}/${uid}
27+
delete_url="${DELETE_DEPLOYMENTS_ENDPOINT}/${uid}?teamId=${VERCEL_ORG_ID}"
2828
echo $delete_url
2929

3030
# Make DELETE a request to the /v13/deployments/{id} endpoint.

0 commit comments

Comments
 (0)