From 7c254d082b604c7cda3f4004aee16effdf9861c3 Mon Sep 17 00:00:00 2001 From: sungaomeng <18810164094@163.com> Date: Thu, 25 Jan 2024 19:37:29 +0800 Subject: [PATCH] fix: cicd, delete vercel pre (#3910) --- .github/workflows/deploy_preview.yml | 8 ++++---- scripts/delete-deployment-preview.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 2524990d8127..387585f469fe 100644 --- a/.github/workflows/deploy_preview.yml +++ b/.github/workflows/deploy_preview.yml @@ -64,17 +64,17 @@ jobs: env: META_TAG: ${{ steps.hash_branch.outputs.digest }}-${{ github.run_number }}-${{ github.run_attempt}} run: | + set -e vercel pull --yes --environment=preview --token=${VERCEL_TOKEN} vercel build --token=${VERCEL_TOKEN} vercel deploy --prebuilt --archive=tgz --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }} - vercel ls --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }} &> vercel-output - DEFAULT_URL=$(cat vercel-output | grep http | awk '{print $2}') + DEFAULT_URL=$(vercel ls --token=${VERCEL_TOKEN} --meta base_hash=${{ env.META_TAG }}) + echo "preview URL:${DEFAULT_URL} , alias URL:${{ steps.set_env.outputs.VERCEL_ALIAS_DOMAIN }}" ALIAS_URL=$(vercel alias set ${DEFAULT_URL} ${{ steps.set_env.outputs.VERCEL_ALIAS_DOMAIN }} --token=${VERCEL_TOKEN} --scope ${VERCEL_TEAM}| awk '{print $3}') echo "New preview URL: ${DEFAULT_URL}" echo "New alias URL: ${ALIAS_URL}" - echo "META_TAG=${META_TAG}" echo "VERCEL_URL=${ALIAS_URL}" >> "$GITHUB_OUTPUT" - uses: mshick/add-pr-comment@v2 @@ -82,4 +82,4 @@ jobs: message: | Your build has completed! - [Preview deployment](${{ steps.vercel.outputs.VERCEL_URL }}) \ No newline at end of file + [Preview deployment](${{ steps.vercel.outputs.VERCEL_URL }}) diff --git a/scripts/delete-deployment-preview.sh b/scripts/delete-deployment-preview.sh index fbad29a5d29b..4f2bb34957d7 100755 --- a/scripts/delete-deployment-preview.sh +++ b/scripts/delete-deployment-preview.sh @@ -7,11 +7,11 @@ GET_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v6/deployments" DELETE_DEPLOYMENTS_ENDPOINT="https://api.vercel.com/v13/deployments" # Create a list of deployments. -# deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ") -deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID" -H "Authorization: Bearer $VERCEL_TOKEN ") +deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_ID&teamId=$VERCEL_ORG_ID" -H "Authorization: Bearer $VERCEL_TOKEN ") +#deployments=$(curl -s -X GET "$GET_DEPLOYMENTS_ENDPOINT/?projectId=$VERCEL_PROJECT_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 -E $deployments | jq --arg META_TAG "$META_TAG" '[.deployments[] | select(.meta.base_hash | type == "string" and contains($META_TAG)) | .uid] | join(",")') filtered_deployments="${filtered_deployments//\"/}" # Remove double quotes # Clears the values from filtered_deployments @@ -24,7 +24,7 @@ echo "Filtered deployments ${filtered_deployments}" for uid in "${values[@]}"; do echo "Deleting ${uid}" - delete_url=${DELETE_DEPLOYMENTS_ENDPOINT}/${uid} + delete_url="${DELETE_DEPLOYMENTS_ENDPOINT}/${uid}?teamId=${VERCEL_ORG_ID}" echo $delete_url # Make DELETE a request to the /v13/deployments/{id} endpoint.