-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (70 loc) · 2.39 KB
/
Copy pathdeploy-website.yml
File metadata and controls
73 lines (70 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Deploy website
on:
push:
branches: [main]
paths:
- "js/website/**"
- "js/core/**"
- "js/react/**"
- "crates/browser/**"
pull_request:
paths:
- "js/website/**"
- "js/core/**"
- "js/react/**"
- "crates/browser/**"
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v7
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Deploy to Vercel
id: deploy
run: |
set -o pipefail
args=()
if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/main" ]; then
args+=(--prod)
fi
output=$(./bin/deploy-website "${args[@]}" 2>&1 | tee /dev/stderr) || exit $?
url=$(echo "$output" | grep -o 'https://[^ ]*\.vercel\.app' | tail -1)
if [ -z "$url" ]; then
echo "::error::deploy-website succeeded but no Vercel URL was found in its output" >&2
exit 1
fi
echo "url=$url" >> "$GITHUB_OUTPUT"
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
- name: Comment preview URL on PR
if: github.event_name == 'pull_request' && steps.deploy.outputs.url
uses: actions/github-script@v9
with:
script: |
const body = `🔗 **Preview:** ${{ steps.deploy.outputs.url }}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.startsWith('🔗 **Preview:**'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}