forked from phase-rs/phase
-
Notifications
You must be signed in to change notification settings - Fork 0
284 lines (249 loc) · 12.7 KB
/
Copy pathdeploy.yml
File metadata and controls
284 lines (249 loc) · 12.7 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: Deploy Staging (GitHub Pages)
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
workflow_dispatch:
concurrency:
group: deploy-pages
cancel-in-progress: true
permissions:
contents: read
pages: write
id-token: write
jobs:
build-and-deploy:
name: Build & Deploy Staging
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 30
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
targets: wasm32-unknown-unknown
cache-shared-key: rust-wasm
- uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@0.2.114
- name: Cache binaryen
id: binaryen-cache
uses: actions/cache@v4
with:
path: binaryen-version_123
key: binaryen-123-x86_64-linux
- name: Install binaryen
if: steps.binaryen-cache.outputs.cache-hit != 'true'
run: curl -L https://github.com/WebAssembly/binaryen/releases/download/version_123/binaryen-version_123-x86_64-linux.tar.gz | tar xz
- name: Add binaryen to PATH
run: echo "$PWD/binaryen-version_123/bin" >> $GITHUB_PATH
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: client/pnpm-lock.yaml
- name: Set cache keys
id: cache-keys
run: echo "week=$(date +%Y-W%V)" >> "$GITHUB_OUTPUT"
- name: Cache MTGJSON data
id: mtgjson-cache
uses: actions/cache@v4
with:
path: data/mtgjson
key: mtgjson-${{ steps.cache-keys.outputs.week }}
restore-keys: mtgjson-
- name: Download MTGJSON data
if: steps.mtgjson-cache.outputs.cache-hit != 'true'
run: |
mkdir -p data/mtgjson
curl -fSL -o data/mtgjson/AtomicCards.json "https://mtgjson.com/api/v5/AtomicCards.json"
- name: Generate card data and coverage (from source)
# Single source of truth: scripts/gen-card-data.sh produces all 7
# public JSON files (card-data, card-data-meta, card-names, coverage-data,
# coverage-summary, decks, set-list). The deploy must use the same
# generator the local dev workflow does — no YAML reimplementation.
run: |
mkdir -p data
./scripts/gen-card-data.sh
# gen-card-data.sh mirrors card-data.json + coverage-data.json into
# data/ itself, so downstream steps (validate, hash, badges) can
# read from data/ without the workflow knowing the layout.
- name: Download draft set data
# fetch-draft-sets.sh needs SetList.json (produced by gen-card-data.sh).
# Per-set files land in data/mtgjson/sets/ which is covered by the
# mtgjson cache — subsequent runs skip already-downloaded sets.
run: ./scripts/fetch-draft-sets.sh
- name: Generate draft pools
# Reads data/mtgjson/sets/*.json → writes client/public/draft-pools.json.
# Included in data-files.json manifest so it's uploaded to R2 and
# stripped from the Pages dist automatically.
run: cargo run --release --bin draft-pool-gen
- name: Validate card-data against engine schema
# Deploy gate — parse the freshly produced card-data through the same
# `CardDatabase::from_export` path the WASM uses at runtime. Catches
# "this commit's engine cannot read this commit's card-data" before R2
# ever sees a broken file. Pairs with the content-addressed copy below.
run: cargo run --release --bin card-data-validate -- data/card-data.json
- name: Compute content-addressed card-data filename
id: card-data-hash
# Pin each WASM bundle to the exact card-data it was built against by
# publishing card-data at `card-data-<hash>.json` (immutable URL with
# long cache) and baking that URL into the JS bundle via Vite's
# `__CARD_DATA_URL__` define. New deploys publish a new hash; old WASM
# bundles in browser caches keep resolving their own old hashed URL.
# WASM/card-data schema drift across deploys becomes structurally
# impossible.
run: |
HASH=$(sha256sum data/card-data.json | awk '{print substr($1, 1, 16)}')
echo "hash=$HASH" >> "$GITHUB_OUTPUT"
echo "filename=card-data-$HASH.json" >> "$GITHUB_OUTPUT"
cp data/card-data.json "data/card-data-$HASH.json"
cp "data/card-data-$HASH.json" "client/public/card-data-$HASH.json"
echo "Content-addressed card-data: card-data-$HASH.json"
- name: Generate Scryfall data
run: |
./scripts/gen-scryfall-images.sh
./scripts/gen-scryfall-sets.sh
./scripts/gen-scryfall-printings.sh
- name: Generate coverage badge endpoints
run: |
cargo run --release --bin coverage-report -- data/ --write-stats data/coverage-stats.json > /dev/null
./scripts/gen-badge-endpoints.sh data/coverage-stats.json data/badges
- name: Run semantic audit
# Produces data/semantic-audit.json with structured findings for cards
# that parse without `Unimplemented` markers but disagree semantically
# with their Oracle text. Consumed by docs/AI-CONTRIBUTOR.md's pre-flight
# gate so autonomous LLM contributors can distinguish "actually
# supported" from "parses, but parses wrong."
# Pass data/ explicitly — the binary's default lookup is
# `client/public/card-data.json`, but gen-card-data.sh mirrors to data/
# in both workflows so this is the portable path.
run: cargo semantic-audit data/
- name: Stamp shared card_data_hash on coverage + audit JSONs
# Both files are uploaded to R2 as separate PUTs with no transactional
# guarantee. Embedding the same card_data_hash in both lets downstream
# consumers (notably AI contributors per docs/AI-CONTRIBUTOR.md) verify
# they're reading a consistent snapshot before trusting the gate.
env:
CARD_DATA_HASH: ${{ steps.card-data-hash.outputs.hash }}
run: |
jq --arg h "$CARD_DATA_HASH" '. + {card_data_hash: $h}' data/semantic-audit.json > client/public/semantic-audit.json
jq --arg h "$CARD_DATA_HASH" '. + {card_data_hash: $h}' client/public/coverage-data.json > client/public/coverage-data.json.tmp
mv client/public/coverage-data.json.tmp client/public/coverage-data.json
- name: Upload data to R2 (staging)
# Single source of truth: data-files.json at the repo root lists every
# shared JSON the frontend fetches. Add a filename there and it is
# automatically picked up by vite.config.ts (defines), this upload
# loop, and the verify step below.
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CARD_DATA_FILENAME: ${{ steps.card-data-hash.outputs.filename }}
run: |
# Content-addressed card-data: immutable, year-long cache. Each WASM
# bundle is baked with its own hashed URL, so old browser caches
# keep resolving the old hash after this deploy publishes a new one.
npx wrangler r2 object put "phase-rs-data/staging/$CARD_DATA_FILENAME" --file "client/public/$CARD_DATA_FILENAME" --remote --content-type application/json --cache-control "public, max-age=31536000, immutable"
# Mutable shared JSONs. Loop over the manifest.
while IFS= read -r f; do
if [ ! -f "client/public/$f" ]; then
echo "::error::Expected data file client/public/$f was not generated"
exit 1
fi
npx wrangler r2 object put "phase-rs-data/staging/$f" --file "client/public/$f" --remote --content-type application/json --cache-control "public, max-age=60, must-revalidate"
done < <(jq -r '.[]' data-files.json)
for f in data/badges/*.json; do
name=$(basename "$f")
npx wrangler r2 object put "phase-rs-data/badges/$name" --file "$f" --remote --content-type application/json --cache-control "public, max-age=60, must-revalidate"
done
- name: Verify R2 uploads landed
# Wrangler v4 silently writes to a local emulator unless --remote is
# passed. Fail the deploy if any file the frontend will fetch is not
# actually reachable. Reads from data-files.json — same source as upload.
env:
CARD_DATA_FILENAME: ${{ steps.card-data-hash.outputs.filename }}
run: |
BASE="https://pub-fc5b5c2c6e774356ae3e730bb0326394.r2.dev/staging"
fail=0
check() {
local f="$1"
local status
status=$(curl -s -o /dev/null -w "%{http_code}" "$BASE/$f")
if [ "$status" != "200" ]; then
echo "::error::R2 upload verification failed: $BASE/$f returned $status"
fail=1
else
echo "Verified $BASE/$f ($status)"
fi
}
check "$CARD_DATA_FILENAME"
while IFS= read -r f; do check "$f"; done < <(jq -r '.[]' data-files.json)
[ "$fail" = "0" ]
- name: Build WASM
run: ./scripts/build-wasm.sh release
- name: Use preview icons
run: |
cp client/public/preview-icons/favicon.ico client/public/favicon.ico
cp client/public/preview-icons/favicon-16x16.png client/public/favicon-16x16.png
cp client/public/preview-icons/favicon-32x32.png client/public/favicon-32x32.png
cp client/public/preview-icons/logo.png client/public/logo.png
cp client/public/preview-icons/icons/icon-192.png client/public/icons/icon-192.png
cp client/public/preview-icons/icons/icon-512.png client/public/icons/icon-512.png
cp client/public/preview-icons/icons/apple-touch-icon.png client/public/icons/apple-touch-icon.png
- name: Build frontend
env:
# Standardized data URL config — see vite.config.ts. DATA_BASE_URL is
# the directory holding every shared JSON; each `__*_URL__` resolves
# to a filename under it. CARD_DATA_URL is the one exception, pinned
# to the content-addressed copy so the WASM bundle is locked to the
# exact card-data it was built against.
DATA_BASE_URL: "https://pub-fc5b5c2c6e774356ae3e730bb0326394.r2.dev/staging"
CARD_DATA_URL: "https://pub-fc5b5c2c6e774356ae3e730bb0326394.r2.dev/staging/${{ steps.card-data-hash.outputs.filename }}"
AUDIO_BASE_URL: "https://pub-fc5b5c2c6e774356ae3e730bb0326394.r2.dev/audio"
run: |
cd client
pnpm install --frozen-lockfile
pnpm build
- name: Remove R2-hosted data files from dist (Pages ships only the shell)
# Single source of truth: data-files.json lists every JSON the frontend
# fetches from R2. The same manifest drives the R2 upload loop above —
# this step is its inverse, stripping those files from the Pages
# bundle so we never double-ship bytes. Adding a new data file is
# now one line in data-files.json and nothing else.
#
# Separately handled:
# - card-data.json (non-manifest; kept in public/ for Tauri + server
# bundles + local dev, but never deployed to Pages)
# - card-data-<16hex>.json[.br] (content-addressed, lives on R2;
# glob matches only 16-hex suffixes, cannot match the 4-char
# `meta` suffix). This replaces the previous `find -regex` which
# used GNU find's default "emacs" regex flavor where `?` is a
# literal — so `\(\.br\)?` matched nothing and the 80 MiB hashed
# file slipped through, exceeding Pages' 25 MiB per-file cap.
shell: bash
run: |
shopt -s nullglob
while IFS= read -r f; do
rm -f "client/dist/$f" "client/dist/$f.br"
done < <(jq -r '.[]' data-files.json)
rm -f client/dist/card-data.json client/dist/card-data.json.br \
client/dist/card-data-????????????????.json \
client/dist/card-data-????????????????.json.br
- name: SPA fallback for GitHub Pages
run: cp client/dist/index.html client/dist/404.html
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: client/dist
- name: Deploy to GitHub Pages
id: deploy
uses: actions/deploy-pages@v4