|
1 | | -name: Deploy to GitHub Pages |
| 1 | +name: Deploy to Vercel |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: [ main ] |
6 | | - pull_request: |
7 | | - branches: [ main ] |
| 5 | + branches: |
| 6 | + - "**" |
8 | 7 |
|
9 | 8 | permissions: |
10 | | - contents: read |
11 | | - pages: write |
12 | | - id-token: write |
13 | | - |
14 | | -concurrency: |
15 | | - group: "pages" |
16 | | - cancel-in-progress: false |
17 | | - |
| 9 | + contents: write |
18 | 10 | jobs: |
19 | | - build: |
| 11 | + Build-and-Deploy: |
| 12 | + env: |
| 13 | + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} |
| 14 | + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} |
| 15 | + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} |
20 | 16 | runs-on: ubuntu-latest |
21 | 17 | steps: |
22 | | - - name: Checkout |
23 | | - uses: actions/checkout@v4 |
| 18 | + - uses: actions/checkout@v6 |
| 19 | + if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} |
24 | 20 |
|
25 | | - - name: Setup Bun |
26 | | - uses: oven-sh/setup-bun@v2 |
27 | | - with: |
28 | | - bun-version: latest |
| 21 | + - uses: oven-sh/setup-bun@v2 |
| 22 | + if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} |
29 | 23 |
|
30 | | - - name: Restore cache |
31 | | - uses: actions/cache@v4 |
32 | | - with: |
33 | | - path: | |
34 | | - .next/cache |
35 | | - key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lock', '**/package-lock.json') }} |
36 | | - restore-keys: | |
37 | | - ${{ runner.os }}-nextjs- |
38 | | -
|
39 | | - - name: Install dependencies |
40 | | - run: bun install |
41 | | - |
42 | | - - name: Build with Next.js |
43 | | - run: bun run build |
44 | | - env: |
45 | | - NODE_ENV: production |
46 | | - NEXT_TELEMETRY_DISABLED: 1 |
47 | | - |
48 | | - - name: Upload artifact |
49 | | - uses: actions/upload-pages-artifact@v3 |
50 | | - with: |
51 | | - path: ./out |
| 24 | + - name: Deploy to Vercel |
| 25 | + id: vercel-deployment |
| 26 | + if: ${{ env.VERCEL_TOKEN && env.VERCEL_ORG_ID && env.VERCEL_PROJECT_ID }} |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + set -euo pipefail |
52 | 30 |
|
53 | | - deploy: |
54 | | - environment: |
55 | | - name: github-pages |
56 | | - url: ${{ steps.deployment.outputs.page_url }} |
57 | | - runs-on: ubuntu-latest |
58 | | - needs: build |
59 | | - steps: |
60 | | - - name: Deploy to GitHub Pages |
61 | | - id: deployment |
62 | | - uses: actions/deploy-pages@v4 |
| 31 | + bun install vercel -g |
| 32 | +
|
| 33 | + if [[ "$GITHUB_REF" == 'refs/heads/main' ]]; then |
| 34 | + DeployOutput=$(vercel -t "$VERCEL_TOKEN" --prod) |
| 35 | + else |
| 36 | + DeployOutput=$(vercel -t "$VERCEL_TOKEN") |
| 37 | + fi |
| 38 | + echo "$DeployOutput" |
| 39 | +
|
| 40 | + ParsedURL=$(echo "$DeployOutput" | grep -Eo 'https://[^[:space:]]*\.vercel\.app' | tail -n 1) |
| 41 | +
|
| 42 | + if [[ -z "$ParsedURL" ]]; then |
| 43 | + echo "Failed to parse Vercel URL from deploy output" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + vercel inspect "$ParsedURL" -t "$VERCEL_TOKEN" -F json > vercel-inspect.json |
| 47 | +
|
| 48 | + InspectURL=$(jq -r '.url // empty' vercel-inspect.json) |
| 49 | +
|
| 50 | + if [[ -z "$InspectURL" ]]; then |
| 51 | + echo "Failed to parse inspect url from vercel-inspect.json" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + if [[ "$InspectURL" != http* ]]; then |
| 55 | + InspectURL="https://$InspectURL" |
| 56 | + fi |
| 57 | + echo "preview-url=$InspectURL" >> "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Lark notification |
| 60 | + uses: Open-Source-Bazaar/feishu-action@v3 |
| 61 | + with: |
| 62 | + url: ${{ secrets.LARK_CHATBOT_HOOK_URL }} |
| 63 | + msg_type: interactive |
| 64 | + content: | |
| 65 | + schema: "2.0" |
| 66 | + config: |
| 67 | + wide_screen_mode: true |
| 68 | + header: |
| 69 | + title: |
| 70 | + tag: plain_text |
| 71 | + content: Vercel deployment |
| 72 | + template: blue |
| 73 | + body: |
| 74 | + elements: |
| 75 | + - tag: markdown |
| 76 | + content: | |
| 77 | + - **Git Repository**: [${{ github.server_url }}/${{ github.repository }}](${{ github.server_url }}/${{ github.repository }}) |
| 78 | + - **Code Branch**: [${{ github.ref }}](${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }}) |
| 79 | + - **Commit Author**: [${{ github.actor }}](${{ github.server_url }}/${{ github.actor }}) |
| 80 | + - **Preview Link**: [${{ steps.vercel-deployment.outputs.preview-url }}](${{ steps.vercel-deployment.outputs.preview-url }}) |
0 commit comments