From 30d9249d67cd31f3441748679766632188276eb6 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Jan 2025 15:35:17 +0000 Subject: [PATCH] Automate vercel alias test --- .github/workflows/ci-website.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/ci-website.yml b/.github/workflows/ci-website.yml index e2a40713f62..9e7c3976297 100644 --- a/.github/workflows/ci-website.yml +++ b/.github/workflows/ci-website.yml @@ -69,3 +69,34 @@ jobs: - name: Run Tests run: yarn run test:ember working-directory: website + + create-vercel-alias: + name: 'Create Vercel Alias' + runs-on: ubuntu-latest + needs: [test] + steps: + - uses: actions/checkout@v2 + - name: Extract Current Version + id: extract_version + run: echo "VERSION=$(jq -r .version packages/components/package.json | sed 's/\./-/g')" >> $GITHUB_ENV + - name: Determine Branch Name + id: determine_branch + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV + else + echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV + - name: Get Latest Vercel Deployment + id: get_vercel_deployment + run: | + DEPLOYMENT_URL=$(curl -s -H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" \ + "https://api.vercel.com/v6/deployments?teamId=${{ secrets.VERCEL_TEAM_ID }}&projectId=${{ secrets.VERCEL_WEBSITE_PROJECT_ID }}" \ + | jq -r --arg branch "${{ env.BRANCH_NAME }}" '.deployments[] | select(.meta.githubCommitRef == $branch) | .url' | head -n 1) + echo "DEPLOYMENT_URL=$DEPLOYMENT_URL" >> $GITHUB_ENV + - name: Alias Vercel Deployment + id: alias_vercel_deployment + run: | + curl -X POST "https://api.vercel.com/v2/now/deployments/${{ env.DEPLOYMENT_URL }}/aliases" \ + -H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "{\"alias\": \"hds-website-${{ env.VERSION }}-test.vercel.app\", \"teamId\": \"${{ secrets.VERCEL_TEAM_ID }}\"}"