From b780595c58ae14be49153887e3d162d3d9e0aa0b Mon Sep 17 00:00:00 2001 From: Goder-0 Date: Wed, 27 May 2026 21:26:59 +0900 Subject: [PATCH] Chore: add Vercel release workflows (#514) - Add a preview deployment workflow for pull requests and main updates. - Add a tag-based production release workflow. - Generate GitHub Releases from the production workflow. - Closes #514. --- .github/workflows/cd.yml | 101 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 66 ++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..24690532 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,101 @@ +name: Linkiving frontend CD + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + branches: + - main + types: + - opened + - synchronize + - reopened + +permissions: + contents: read + pull-requests: write + +concurrency: + group: frontend-cd-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + deploy-preview: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10.19.0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel preview environment + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build Vercel artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy preview to Vercel + id: deploy + shell: bash + run: | + deployment_url="$(vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }})" + echo "deployment_url=${deployment_url}" >> "$GITHUB_OUTPUT" + echo "Preview deployment: ${deployment_url}" >> "$GITHUB_STEP_SUMMARY" + + - name: Add PR preview comment + if: github.event_name == 'pull_request' + uses: actions/github-script@v7 + env: + DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment_url }} + with: + script: | + const marker = ''; + const body = `${marker}\nPreview deployment is ready.\n\n- URL: ${process.env.DEPLOYMENT_URL}\n- Commit: ${context.sha}`; + const { owner, repo } = context.repo; + const issue_number = context.issue.number; + const comments = await github.paginate(github.rest.issues.listComments, { + owner, + repo, + issue_number, + per_page: 100, + }); + const existing = comments.find((comment) => comment.user?.type === 'Bot' && comment.body?.includes(marker)); + + if (existing) { + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: existing.id, + body, + }); + return; + } + + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body, + }); diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..758fe01f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,66 @@ +name: Vercel Production Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +concurrency: + group: vercel-release-${{ github.ref }} + cancel-in-progress: false + +env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + +jobs: + deploy-production: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10.19.0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Install Vercel CLI + run: npm install --global vercel@latest + + - name: Pull Vercel production environment + run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build production artifacts + run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy production to Vercel + id: deploy + shell: bash + run: | + deployment_url="$(vercel deploy --prebuilt --archive=tgz --prod --token=${{ secrets.VERCEL_TOKEN }})" + echo "deployment_url=${deployment_url}" >> "$GITHUB_OUTPUT" + { + echo "Production release deployed." + echo + echo "- Tag: ${{ github.ref_name }}" + echo "- URL: ${deployment_url}" + } >> "$GITHUB_STEP_SUMMARY" + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + generate_release_notes: true