From fae82a30e7b127427199cfe2b2fc2a1f095a2414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=AB=98=E7=8C=9B?= Date: Thu, 25 Jan 2024 16:53:03 +0800 Subject: [PATCH 1/4] fix: cicd, delete vercel pre --- scripts/delete-deployment-preview.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/delete-deployment-preview.sh b/scripts/delete-deployment-preview.sh index fbad29a5d29..4f2bb34957d 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. From ba3e7e79741289c9eddee533828aa40c1e9e940a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=AB=98=E7=8C=9B?= Date: Thu, 25 Jan 2024 19:31:17 +0800 Subject: [PATCH 2/4] fix: cicd, vercel alias domain --- .github/workflows/deploy_preview.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 2524990d812..387585f469f 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 }}) From 15d25df2458ff9160eff5184158aea3bfa6571d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=AB=98=E7=8C=9B?= Date: Thu, 25 Jan 2024 19:43:26 +0800 Subject: [PATCH 3/4] fix: cicd, delete velcel pre --- .github/workflows/remove_deploy_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/remove_deploy_preview.yml b/.github/workflows/remove_deploy_preview.yml index 924b8dd0746..4846cda2d6a 100644 --- a/.github/workflows/remove_deploy_preview.yml +++ b/.github/workflows/remove_deploy_preview.yml @@ -11,7 +11,7 @@ env: VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} on: - pull_request: + pull_request_target: types: - closed From ecbab75a25a347f8990db7e902cb900cb7ebb990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=AB=98=E7=8C=9B?= Date: Thu, 25 Jan 2024 19:54:58 +0800 Subject: [PATCH 4/4] fix: cicd, alias domain env name --- .github/workflows/deploy_preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 387585f469f..a62a5fc205a 100644 --- a/.github/workflows/deploy_preview.yml +++ b/.github/workflows/deploy_preview.yml @@ -41,7 +41,7 @@ jobs: - name: Set Environment Variables id: set_env - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request_target' run: | echo "VERCEL_ALIAS_DOMAIN=${{ github.event.pull_request.number }}-${{ github.workflow }}.${VERCEL_PR_DOMAIN_SUFFIX}" >> $GITHUB_OUTPUT