diff --git a/.github/actions/vercel-deploy/action.yml b/.github/actions/vercel-deploy/action.yml index 7ff908f4..368b9ada 100644 --- a/.github/actions/vercel-deploy/action.yml +++ b/.github/actions/vercel-deploy/action.yml @@ -14,6 +14,10 @@ inputs: required: true vercel_token: required: true + custom_domain: + description: "Custom domain in the format {locale}-{pr}.nextjs.im (optional)" + required: false + default: "" outputs: inspect_url: description: "Vercel inspect URL" @@ -21,6 +25,9 @@ outputs: prod_url: description: "Vercel preview/production URL" value: ${{ steps.vercel_deploy.outputs.prod_url }} + custom_domain_url: + description: "Custom domain URL if set" + value: ${{ steps.set_custom_domain.outputs.custom_domain_url }} runs: using: "composite" steps: @@ -56,3 +63,15 @@ runs: VERCEL_PROJECT_ID: ${{ inputs.vercel_project_id }} VERCEL_ORG_ID: ${{ inputs.vercel_org_id }} shell: bash + - name: Set Custom Domain (if provided) + id: set_custom_domain + if: ${{ inputs.custom_domain != '' }} + run: | + deployment_url=${{ steps.vercel_deploy.outputs.prod_url }} + custom_domain="${{ inputs.custom_domain }}" + npx vercel alias set "$deployment_url" "$custom_domain" --token=${{ inputs.vercel_token }} + echo "custom_domain_url=https://$custom_domain" >> $GITHUB_OUTPUT + env: + VERCEL_PROJECT_ID: ${{ inputs.vercel_project_id }} + VERCEL_ORG_ID: ${{ inputs.vercel_org_id }} + shell: bash diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 9d8a05fa..813cc3c7 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -14,7 +14,6 @@ permissions: jobs: deploy: - if: contains(github.event.pull_request.labels.*.name, 'prerelease') runs-on: ubuntu-latest strategy: matrix: @@ -27,13 +26,41 @@ jobs: secret_project_id: VERCEL_PROJECT_ZH_HANT_ID name: Deploy ${{ matrix.locale }} steps: + # Calculate if this matrix job should run based on PR labels + # + # This job will deploy if: + # - The event is NOT a pull_request (e.g., workflow_dispatch) + # - OR the PR has the label 'prerelease' + # - OR the PR has the label 'prerelease:' matching the current matrix locale + - name: Calculate should_deploy + id: should_deploy + shell: bash + run: | + LABELS_JSON='${{ toJson(github.event.pull_request.labels.*.name) }}' + echo "LABELS_JSON: $LABELS_JSON" + SHOULD_DEPLOY=false + if [[ "${{ github.event_name }}" != "pull_request" ]]; then + SHOULD_DEPLOY=true + elif echo "$LABELS_JSON" | grep -E '"prerelease"' > /dev/null; then + SHOULD_DEPLOY=true + elif echo "$LABELS_JSON" | grep -E '"prerelease:'"${{ matrix.locale }}"'"' > /dev/null; then + SHOULD_DEPLOY=true + fi + echo "should_deploy=$SHOULD_DEPLOY" >> $GITHUB_OUTPUT - name: Checkout code + if: steps.should_deploy.outputs.should_deploy == 'true' uses: actions/checkout@v3 with: fetch-depth: 1 + ref: ${{ github.head_ref }} + - name: Log checked out commit + if: steps.should_deploy.outputs.should_deploy == 'true' + run: git log -1 - name: Setup Tools + if: steps.should_deploy.outputs.should_deploy == 'true' uses: ./.github/actions/setup - name: Deploy to Vercel (${{ matrix.locale }}) + if: steps.should_deploy.outputs.should_deploy == 'true' id: deploy uses: ./.github/actions/vercel-deploy with: @@ -41,7 +68,9 @@ jobs: vercel_project_id: ${{ secrets[matrix.secret_project_id] }} vercel_org_id: ${{ secrets.VERCEL_ORG_ID }} vercel_token: ${{ secrets.VERCEL_TOKEN }} + custom_domain: ${{ matrix.locale }}-${{ github.event.pull_request.number }}.nextjs.im - name: Comment PR with Vercel Preview Links (${{ matrix.locale }}) + if: steps.should_deploy.outputs.should_deploy == 'true' uses: ./.github/actions/comment-vercel-preview with: inspect_url: ${{ steps.deploy.outputs.inspect_url }}