build: bump deps #684
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Vercel Preview Deploy | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, ready_for_review] | |
| concurrency: | |
| group: vercel-preview-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| deployments: write | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| preview: | |
| if: github.repository == 'walinejs/waline' && !github.event.pull_request.draft | |
| runs-on: ubuntu-latest | |
| env: | |
| # Configure these in GitHub repository secrets. | |
| # - VERCEL_TOKEN: Vercel Account Settings > Tokens. | |
| # - VERCEL_ORG_ID / VERCEL_PROJECT_ID: values from `.vercel/project.json` after `vercel link`, | |
| # or the Team ID / Project ID shown in Vercel dashboard settings. | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: pnpm/action-setup@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Create GitHub deployment | |
| uses: actions/github-script@v9 | |
| id: deployment | |
| with: | |
| script: | | |
| try { | |
| const deployment = await github.rest.repos.createDeployment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: context.payload.pull_request.head.sha, | |
| task: 'deploy:vercel-preview', | |
| auto_merge: false, | |
| required_contexts: [], | |
| environment: 'Preview', | |
| transient_environment: true, | |
| production_environment: false, | |
| description: 'Vercel preview deployment', | |
| }); | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: deployment.data.id, | |
| state: 'in_progress', | |
| log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | |
| description: 'Building API, client, and admin before Vercel deployment...', | |
| }); | |
| core.setOutput('id', deployment.data.id); | |
| } catch (error) { | |
| if (error.status !== 403) throw error; | |
| core.warning('The workflow token cannot create a GitHub deployment; continuing without deployment metadata.'); | |
| } | |
| - name: Upsert preview comment | |
| if: steps.deployment.outputs.id | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const marker = '<!-- waline-vercel-preview -->'; | |
| const prNumber = context.payload.pull_request.number; | |
| const commit = context.payload.pull_request.head.sha; | |
| const body = `${marker}\n### Vercel Preview\n\n⏳ Building \`@waline/api\`, \`@waline/client\`, and \`@waline/admin\`, then deploying to Vercel...\n\n- PR: #${prNumber}\n- Commit: ${commit}\n\n[View workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| per_page: 100, | |
| }); | |
| const comment = comments.find((item) => item.user.type === 'Bot' && item.body?.includes(marker)); | |
| if (comment) { | |
| await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: comment.id, body }); | |
| } else { | |
| await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body }); | |
| } | |
| - name: Build preview artifacts | |
| run: | | |
| pnpm api:build | |
| pnpm client:build | |
| pnpm admin:build | |
| rm -rf packages/server/__tests__/fixtures/vercel/client packages/server/__tests__/fixtures/vercel/admin | |
| mkdir -p packages/server/__tests__/fixtures/vercel/client packages/server/__tests__/fixtures/vercel/admin | |
| cp packages/client/dist/waline.js packages/client/dist/waline.css packages/server/__tests__/fixtures/vercel/client/ | |
| cp packages/admin/dist/admin.js packages/server/__tests__/fixtures/vercel/admin/ | |
| sed -i \ | |
| -e 's#__WALINE_PREVIEW_PR__#${{ github.event.pull_request.number }}#g' \ | |
| -e 's#__WALINE_PREVIEW_PR_URL__#${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.pull_request.number }}#g' \ | |
| -e 's#__WALINE_PREVIEW_COMMIT__#${{ github.event.pull_request.head.sha }}#g' \ | |
| -e 's#__WALINE_PREVIEW_COMMIT_URL__#${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}#g' \ | |
| packages/server/__tests__/fixtures/vercel/index.html | |
| # Pack the server from the current PR checkout and install that local tarball in the fixture. | |
| pnpm --dir packages/server pack --pack-destination ../../packages/server/__tests__/fixtures/vercel | |
| mv packages/server/__tests__/fixtures/vercel/waline-vercel-*.tgz packages/server/__tests__/fixtures/vercel/waline-vercel-current-pr.tgz | |
| printf '{"private":true,"dependencies":{"@waline/vercel":"file:./waline-vercel-current-pr.tgz"}}\n' > packages/server/__tests__/fixtures/vercel/package.json | |
| sed -i "s#require('../../..')#require('./node_modules/@waline/vercel')#" packages/server/__tests__/fixtures/vercel/index.cjs | |
| - name: Link Vercel project | |
| run: | | |
| mkdir -p packages/server/__tests__/fixtures/vercel/.vercel | |
| printf '{"orgId":"%s","projectId":"%s"}\n' "$VERCEL_ORG_ID" "$VERCEL_PROJECT_ID" > packages/server/__tests__/fixtures/vercel/.vercel/project.json | |
| - name: Deploy to Vercel | |
| id: vercel | |
| run: | | |
| set -o pipefail | |
| pnpm vercel deploy ./packages/server/__tests__/fixtures/vercel --yes --token "$VERCEL_TOKEN" | tee vercel-deploy.log | |
| url=$(awk '/https:\/\// { value=$0 } END { print value }' vercel-deploy.log) | |
| if [ -z "$url" ]; then | |
| echo "Unable to find Vercel preview URL in deploy output" >&2 | |
| exit 1 | |
| fi | |
| deployment_url=$(awk '/Inspect/ && match($0, /https:\/\/vercel.com\/[^[:space:]]+/) { value=substr($0, RSTART, RLENGTH) } END { print value }' vercel-deploy.log) | |
| echo "url=$url" >> "$GITHUB_OUTPUT" | |
| echo "deployment_url=$deployment_url" >> "$GITHUB_OUTPUT" | |
| echo "$url" | |
| - name: Mark deployment successful | |
| if: success() && steps.deployment.outputs.id | |
| uses: actions/github-script@v9 | |
| env: | |
| DEPLOYMENT_ID: ${{ steps.deployment.outputs.id }} | |
| PREVIEW_URL: ${{ steps.vercel.outputs.url }} | |
| with: | |
| script: | | |
| const targetUrl = process.env.PREVIEW_URL.startsWith('http') | |
| ? process.env.PREVIEW_URL | |
| : `https://${process.env.PREVIEW_URL}`; | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: Number(process.env.DEPLOYMENT_ID), | |
| state: 'success', | |
| environment_url: targetUrl, | |
| target_url: targetUrl, | |
| log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | |
| description: 'Vercel preview is ready.', | |
| }); | |
| - name: Update preview comment | |
| if: success() && steps.deployment.outputs.id | |
| uses: actions/github-script@v9 | |
| env: | |
| PREVIEW_URL: ${{ steps.vercel.outputs.url }} | |
| VERCEL_DEPLOYMENT_URL: ${{ steps.vercel.outputs.deployment_url }} | |
| with: | |
| script: | | |
| const marker = '<!-- waline-vercel-preview -->'; | |
| const targetUrl = process.env.PREVIEW_URL.startsWith('http') | |
| ? process.env.PREVIEW_URL | |
| : `https://${process.env.PREVIEW_URL}`; | |
| const prNumber = context.payload.pull_request.number; | |
| const commit = context.payload.pull_request.head.sha; | |
| const deploymentLine = process.env.VERCEL_DEPLOYMENT_URL | |
| ? `\n- Vercel Deployment: [Open deployment](${process.env.VERCEL_DEPLOYMENT_URL})` | |
| : ''; | |
| const body = `${marker}\n### Vercel Preview\n\n✅ Deployment is ready.\n\n- Preview: ${targetUrl}${deploymentLine}\n- PR: #${prNumber}\n- Commit: ${commit}\n- Workflow: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| per_page: 100, | |
| }); | |
| const comment = comments.find((item) => item.user.type === 'Bot' && item.body?.includes(marker)); | |
| if (comment) await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: comment.id, body }); | |
| - name: Test Vercel Preview | |
| env: | |
| VERCEL_PREVIEW_URL: ${{ steps.vercel.outputs.url }} | |
| VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }} | |
| run: node scripts/test-vercel-preview.mjs | |
| - name: Mark deployment failed | |
| if: failure() && steps.deployment.outputs.id | |
| uses: actions/github-script@v9 | |
| env: | |
| DEPLOYMENT_ID: ${{ steps.deployment.outputs.id }} | |
| with: | |
| script: | | |
| await github.rest.repos.createDeploymentStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| deployment_id: Number(process.env.DEPLOYMENT_ID), | |
| state: 'failure', | |
| log_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | |
| description: 'Vercel preview deployment failed.', | |
| }); |