-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (124 loc) · 5.17 KB
/
Copy pathdocs.yml
File metadata and controls
127 lines (124 loc) · 5.17 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
name: Docs
# The playground runs the checkout's own generator (lib/ wrapper + a wasm build
# of src/), so every push and PR builds the site. Production only updates for a
# release commit or a docs-only change; other pushes upload a preview version.
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
name: Build and deploy
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
# the deploy gate diffs the pushed range
fetch-depth: 0
- name: Setup bun
uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: Setup Node
uses: actions/setup-node@v7
with:
node-version: 22
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-wasip1-threads
- name: Cache cargo
uses: actions/cache@v6
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.napi-rs
.cargo-cache
target/
# same key as the CI matrix entry so both workflows share the cache
key: wasm32-wasip1-threads-cargo-ubuntu-latest
- name: Install dependencies
run: bun ci
- name: Build wasm engine
run: bun run build --target wasm32-wasip1-threads
# `napi build` regenerates the committed entry files; the site aliases lib/.
- name: Restore committed entry files
run: git checkout -- native.js browser.js index.d.ts
- name: Decide deploy target
id: gate
env:
BEFORE: ${{ github.event.before }}
run: |
set -eu
# wrangler caps version tags at 25 characters
echo "short=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "production=false" >> "$GITHUB_OUTPUT"; echo "pull request: preview only"; exit 0
fi
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "production=true" >> "$GITHUB_OUTPUT"; echo "manual run"; exit 0
fi
# HEAD only, same as the publish job in CI.yml: a release commit that is
# not the push HEAD reaches neither npm nor production.
if git log -1 --pretty=%B | grep -q '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$'; then
echo "production=true" >> "$GITHUB_OUTPUT"; echo "release commit"; exit 0
fi
# a force-push or new branch has no usable `before`
if [ -n "$BEFORE" ] && ! echo "$BEFORE" | grep -q '^0*$' && git cat-file -e "$BEFORE" 2>/dev/null; then
if ! git diff --name-only "$BEFORE" HEAD | grep -qv '^\(website/\|\.github/workflows/docs\.yml\|bun\.lock\|bunfig\.toml\|stackblitz/\)'; then
echo "production=true" >> "$GITHUB_OUTPUT"; echo "docs-only change"; exit 0
fi
fi
echo "production=false" >> "$GITHUB_OUTPUT"; echo "unreleased generator change: preview only"
- name: Build site
working-directory: website
run: bun run build
env:
# previews label the engine with the commit they run
ENGINE_VERSION_SUFFIX: ${{ steps.gate.outputs.production != 'true' && format('+{0}', steps.gate.outputs.short) || '' }}
- name: Type-check
working-directory: website
run: bun run check
- name: Install Playwright browser
working-directory: website
run: bunx playwright install --with-deps chromium
- name: Test
working-directory: website
run: bun run test
- name: Deploy to production
if: steps.gate.outputs.production == 'true'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
workingDirectory: website
command: deploy
- name: Upload preview version (main)
if: github.event_name == 'push' && steps.gate.outputs.production == 'false'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
workingDirectory: website
command: versions upload --tag main-${{ steps.gate.outputs.short }} --message "main@${{ steps.gate.outputs.short }}"
- name: Upload preview version (PR)
if: github.event_name == 'pull_request'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
workingDirectory: website
command: versions upload --tag pr-${{ github.event.pull_request.number }} --message "PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"