From 82b46408360ca88c9b890f80b9808de8fe377e2b Mon Sep 17 00:00:00 2001 From: Mogeko Date: Thu, 11 Jul 2024 00:02:52 +0800 Subject: [PATCH] build: deploy to Vercel --- .github/mergify.yml | 4 +-- .github/workflows/build.yml | 33 +++++++++++-------- .github/workflows/release.yml | 60 +++++++++++++---------------------- .github/workflows/test.yml | 17 ++++------ .gitignore | 3 ++ turbo.json | 6 ++-- vercel.json | 14 ++++++++ 7 files changed, 71 insertions(+), 66 deletions(-) create mode 100644 vercel.json diff --git a/.github/mergify.yml b/.github/mergify.yml index 35fda52..9ec80f8 100644 --- a/.github/mergify.yml +++ b/.github/mergify.yml @@ -1,7 +1,7 @@ queue_rules: - name: dependabot queue_conditions: - - "check-success=Build Userscript" + - "check-success=Build and Deploy to Vercel Preview" - "check-success=Run Tests and Generate Coverage Report" batch_size: 10 batch_max_wait_time: 5min @@ -20,7 +20,7 @@ pull_request_rules: conditions: - "author=dependabot[bot]" - "label=dependencies" - - "check-success=Build Userscript" + - "check-success=Build and Deploy to Vercel Preview" - "check-success=Run Tests and Generate Coverage Report" actions: queue: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da73618..5e6b003 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,22 +9,29 @@ on: jobs: build: - name: Build Userscript + name: Build and Deploy to Vercel Preview runs-on: ubuntu-latest + environment: + name: preview + url: ${{ steps.deployment.outputs.DEPLOYMENT_URL }} + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ github.actor }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} steps: - - uses: actions/checkout@v4 - - name: Setup pnpm + - uses: actions/checkout@v4.1.7 + - name: Set up pnpm uses: pnpm/action-setup@v4.0.0 - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Set up Node.js + uses: actions/setup-node@v4.0.2 with: node-version-file: package.json cache: "pnpm" - - name: Cache Turborepo Tasks - uses: actions/cache@v4 - with: - path: ${{ github.workspace }}/node_modules/.cache/turbo - key: ${{ runner.os }}-turbo-build-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: ${{ runner.os }}-turbo- - - run: pnpm install -rw --frozen-lockfile - - run: pnpm build + - run: pnpm install --global vercel@latest + - run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + - run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + - run: | + vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} | \ + xargs -I {} echo "DEPLOYMENT_URL={}" >> "${GITHUB_OUTPUT}" + id: deployment diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9dd92ce..e208245 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,39 +5,40 @@ on: branches: [master] workflow_dispatch: +concurrency: ${{ github.workflow }}-${{ github.ref }} + permissions: contents: write pull-requests: write - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: true jobs: build: - name: Create PR or Deploy to Pages + name: Create PR or Deploy to Vercel Production runs-on: ubuntu-latest - outputs: - hasChangesets: ${{ steps.changesets.outputs.hasChangesets }} + environment: + name: production + url: ${{ steps.deployment.outputs.DEPLOYMENT_URL }} + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ github.actor }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} steps: - - uses: actions/checkout@v4 - - name: Setup pnpm + - uses: actions/checkout@v4.1.7 + - name: Set up pnpm uses: pnpm/action-setup@v4.0.0 - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Set up Node.js + uses: actions/setup-node@v4.0.2 with: node-version-file: package.json cache: "pnpm" - - name: Setup Pages - id: pages - uses: actions/configure-pages@v5 - - run: pnpm install -rw --frozen-lockfile - - run: pnpm build - env: - BASE_URL: ${{ steps.pages.outputs.base_url }} - NODE_ENV: production + - run: pnpm install --global vercel@latest + - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + - run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + - run: | + vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} | \ + xargs -I {} echo "DEPLOYMENT_URL={}" >> "${GITHUB_OUTPUT}" + id: deployment - name: Create Version PR or Deploy to Pages id: changesets uses: changesets/action@v1.4.7 @@ -48,20 +49,3 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_ENV: production - - name: Upload artifact - if: steps.changesets.outputs.hasChangesets == 'false' - uses: actions/upload-pages-artifact@v3 - with: - path: ./release - - deploy: - if: needs.build.outputs.hasChangesets == 'false' - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - needs: build - runs-on: ubuntu-latest - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43ccdff..58491a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,21 +10,18 @@ jobs: test: name: Run Tests and Generate Coverage Report runs-on: ubuntu-latest + env: + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ github.actor }} steps: - - uses: actions/checkout@v4 - - name: Setup pnpm + - uses: actions/checkout@v4.1.7 + - name: Set up pnpm uses: pnpm/action-setup@v4.0.0 - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Set up Node.js + uses: actions/setup-node@v4.0.2 with: node-version-file: package.json cache: "pnpm" - - name: Cache Turborepo Tasks - uses: actions/cache@v4 - with: - path: ${{ github.workspace }}/node_modules/.cache/turbo - key: ${{ runner.os }}-turbo-test-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: ${{ runner.os }}-turbo- - run: pnpm install -rw --frozen-lockfile - run: pnpm lint - run: pnpm cov diff --git a/.gitignore b/.gitignore index fd28ee2..1a1ca47 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,6 @@ release/ # Turborepo remote cache config .turbo + +# Vercel build output +.vercel diff --git a/turbo.json b/turbo.json index fcd3107..5082e4c 100644 --- a/turbo.json +++ b/turbo.json @@ -3,11 +3,11 @@ "tasks": { "build": { "dependsOn": ["^build"], - "outputs": ["../../release/**"], + "outputs": ["dist/**"], "env": ["BASE_URL"] }, - "test": { "dependsOn": ["^build"], "outputs": [] }, - "cov": { "dependsOn": ["^build"], "outputs": [] }, + "test": { "dependsOn": ["^build"], "inputs": ["$TURBO_DEFAULT$", "tests"] }, + "cov": { "dependsOn": ["^build"], "inputs": ["$TURBO_DEFAULT$", "tests"] }, "lint": { "outputs": [] }, "fmt": { "outputs": [], "cache": false } }, diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..d1f3e40 --- /dev/null +++ b/vercel.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://openapi.vercel.sh/vercel.json", + "version": 2, + "public": false, + "installCommand": "pnpm install --frozen-lockfile", + "buildCommand": "pnpm run build", + "outputDirectory": "./release", + "git": { + "deploymentEnabled": false + }, + "github": { + "enabled": false + } +}