-
Notifications
You must be signed in to change notification settings - Fork 208
130 lines (110 loc) · 3.87 KB
/
Copy pathdocs.yaml
File metadata and controls
130 lines (110 loc) · 3.87 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Docs
on:
push:
branches:
- main
paths:
- "docs/**"
- ".github/workflows/docs.yaml"
pull_request:
paths:
- "docs/**"
- ".github/workflows/docs.yaml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
defaults:
run:
working-directory: docs
jobs:
build:
name: Build & check docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Cache Bun install
uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('docs/bun.lockb') }}
restore-keys: |
${{ runner.os }}-bun-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Lint / format / typecheck / link-check
run: bun run build:check
- name: Next.js build (+ pagefind index)
run: bun run build
deploy:
name: Deploy to Vercel
needs: build
runs-on: ubuntu-latest
# Skip deploy for PRs opened from forks: GitHub Actions does not expose
# repo secrets to fork PRs, so `vercel pull` would fail. The `build` job
# above still verifies the docs compile on every PR (including forks).
if: >-
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository)
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
IS_PROD: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: 'lts/*'
# Vercel detects docs/bun.lockb and shells out to `bun install`
# during `vercel build`, so Bun must be on PATH in this job too.
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel environment (production)
if: env.IS_PROD == 'true'
run: vercel pull --yes --environment=production --token=$VERCEL_TOKEN
- name: Pull Vercel environment (preview)
if: env.IS_PROD != 'true'
run: vercel pull --yes --environment=preview --token=$VERCEL_TOKEN
- name: Build (Vercel)
run: |
if [ "$IS_PROD" = "true" ]; then
vercel build --prod --token=$VERCEL_TOKEN
else
vercel build --token=$VERCEL_TOKEN
fi
- name: Deploy (Vercel)
id: deploy
# `set -o pipefail` so a non-zero exit from `vercel deploy` is not
# masked by the success of `tail` in the pipeline.
# `--archive=tgz` is required because the built site has >15000 files,
# which exceeds Vercel's default upload limit.
run: |
set -o pipefail
if [ "$IS_PROD" = "true" ]; then
URL=$(vercel deploy --prebuilt --prod --archive=tgz --token=$VERCEL_TOKEN | tail -n 1)
else
URL=$(vercel deploy --prebuilt --archive=tgz --token=$VERCEL_TOKEN | tail -n 1)
fi
echo "url=$URL" >> "$GITHUB_OUTPUT"
echo "Deployed: $URL"
- name: Comment preview URL on PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: vercel-docs-preview
message: |
📖 **Docs preview**: ${{ steps.deploy.outputs.url }}
Built from commit `${{ github.event.pull_request.head.sha }}` by [docs.yaml](../actions/runs/${{ github.run_id }}).