name: Preview Deployment env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} VERCEL_CLI: vercel@50.14.1 on: push: branches-ignore: - main paths: - "web/**" permissions: contents: read jobs: check-credentials: runs-on: ubuntu-latest timeout-minutes: 10 outputs: has-credentials: ${{ steps.check.outputs.has-credentials }} steps: - name: Check Vercel credentials id: check env: VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} run: | if [ -n "$VERCEL_ORG_ID" ] && [ -n "$VERCEL_PROJECT_ID" ] && [ -n "$VERCEL_TOKEN" ]; then echo "has-credentials=true" >> "$GITHUB_OUTPUT" else echo "has-credentials=false" >> "$GITHUB_OUTPUT" echo "Vercel credentials not set; skipping preview deployment." fi Deploy-Preview: needs: check-credentials if: needs.check-credentials.outputs.has-credentials == 'true' runs-on: ubuntu-latest timeout-minutes: 30 permissions: contents: read pull-requests: write steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: persist-credentials: false - name: Setup bun uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # ratchet:oven-sh/setup-bun@v2 with: bun-version: "1.3.13" - name: Pull Vercel Environment Information run: bunx ${{ env.VERCEL_CLI }} pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} - name: Install dependencies and build Opal + Shared working-directory: ./web run: bun install --frozen-lockfile && bun run --filter './lib/opal' build && bun run --filter './lib/shared' build - name: Build Project Artifacts run: bunx ${{ env.VERCEL_CLI }} build --token=${{ secrets.VERCEL_TOKEN }} - name: Deploy Project Artifacts to Vercel id: deploy run: | DEPLOYMENT_URL=$(bunx ${{ env.VERCEL_CLI }} deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) echo "url=$DEPLOYMENT_URL" >> "$GITHUB_OUTPUT" - name: Update PR comment with deployment URL if: always() && steps.deploy.outputs.url env: GH_TOKEN: ${{ github.token }} DEPLOYMENT_URL: ${{ steps.deploy.outputs.url }} run: | # Find the PR for this branch PR_NUMBER=$(gh pr list --head "$GITHUB_REF_NAME" --json number --jq '.[0].number') if [ -z "$PR_NUMBER" ]; then echo "No open PR found for branch $GITHUB_REF_NAME, skipping comment." exit 0 fi COMMENT_MARKER="" COMMENT_BODY="$COMMENT_MARKER **Preview Deployment** | Status | Preview | Commit | Updated | | --- | --- | --- | --- | | ✅ | $DEPLOYMENT_URL | \`${GITHUB_SHA::7}\` | $(date -u '+%Y-%m-%d %H:%M:%S UTC') |" # Find existing comment by marker EXISTING_COMMENT_ID=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \ --jq ".[] | select(.body | startswith(\"$COMMENT_MARKER\")) | .id" | head -1) if [ -n "$EXISTING_COMMENT_ID" ]; then gh api "repos/$GITHUB_REPOSITORY/issues/comments/$EXISTING_COMMENT_ID" \ --method PATCH --field body="$COMMENT_BODY" else gh pr comment "$PR_NUMBER" --body "$COMMENT_BODY" fi