mirror of
https://github.com/tiennm99/thptqg.git
synced 2026-10-13 10:16:05 +00:00
build: produce the whole site from one Vite build
The four build variants existed only because the app could not resolve its own dataset. Now that it can, vite.config.js is a single build with an absolute base and no VARIANT switching, and the workflow compiles Rust once, installs Node dependencies once, and builds the site once — it previously built the same Rust crate twice and ran two separate pnpm installs. Because base is absolute, the emitted index.html references /thptqg/assets/... regardless of where it is served from, so the same file works as an entry point at any depth. scripts/assemble-site.js copies it to each dataset path and to the two legacy nested URLs, giving a real static file at every published route. That is what removes the need for an SPA 404-fallback redirect, which would otherwise have rewritten URLs and interfered with the ?q= deep links. Generated databases move to a gitignored .build/public, which Vite consumes as its publicDir. build-db.js gzips without -k, and the assemble step then refuses to finish if any uncompressed database artefact reached the output — .db, .db-journal, .db-wal or .db-shm. Previously a raw 100+ MB database was written into the source tree and deleted afterwards by an rm in the workflow, so shipping one was a missing cleanup step away. Both build scripts import DATASET_IDS from src/datasets.js rather than repeating the dataset list in workflow shell, so the four ids are declared in exactly one place across the frontend, the database build and the assembly. Verified by running the full pipeline locally and serving the artifact over HTTP: all nine routes return 200, every entry point is byte-identical, asset references are absolute, and the databases are fetchable. The guard was tested by injecting a raw .db and .db-journal into the build, which failed the assembly as intended.
This commit is contained in:
1 parent
003e7c8afd
commit
a5904a5d78
7 files changed
+151
-78
No files matched your search
@@ -24,57 +24,29 @@ jobs:
|
||||
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: |
|
||||
2016/tools/xlsxread
|
||||
2017/tools/xlsxread
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
package_json_file: 2017/package.json
|
||||
workspaces: parser
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '24'
|
||||
cache: 'pnpm'
|
||||
cache-dependency-path: |
|
||||
2016/pnpm-lock.yaml
|
||||
2017/pnpm-lock.yaml
|
||||
cache: 'npm'
|
||||
cache-dependency-path: package-lock.json
|
||||
|
||||
- name: Build 2016 site
|
||||
working-directory: '2016'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cargo build --release --manifest-path tools/xlsxread/Cargo.toml
|
||||
./tools/xlsxread/target/release/xlsxread build \
|
||||
--schema tools/xlsxread/configs/thptqg2016-data.toml \
|
||||
--input data --output public/thptqg2016.db
|
||||
pnpm install --frozen-lockfile
|
||||
gzip -k -9 public/thptqg2016.db
|
||||
pnpm build
|
||||
rm -f dist/thptqg2016.db
|
||||
- run: npm ci
|
||||
|
||||
- name: Build 2017 site variants
|
||||
working-directory: '2017'
|
||||
# One parser binary builds every dataset; build-db.js reads the dataset
|
||||
# list from src/datasets.js and gzips each database in place, leaving no
|
||||
# uncompressed file behind.
|
||||
- name: Build databases
|
||||
run: |
|
||||
set -euo pipefail
|
||||
cargo build --release --manifest-path tools/xlsxread/Cargo.toml
|
||||
./tools/xlsxread/target/release/xlsxread build --schema tools/xlsxread/configs/thptqg2017-data.toml --input data --output public/thptqg2017.db
|
||||
./tools/xlsxread/target/release/xlsxread build --schema tools/xlsxread/configs/thptqg2017-data-old.toml --input data-old --output public-old/thptqg2017.db
|
||||
./tools/xlsxread/target/release/xlsxread build --schema tools/xlsxread/configs/thptqg2017-data-old2.toml --input data-old2 --output public-old2/thptqg2017.db
|
||||
pnpm install --frozen-lockfile
|
||||
gzip -kf -9 public/thptqg2017.db
|
||||
gzip -kf -9 public-old/thptqg2017.db
|
||||
gzip -kf -9 public-old2/thptqg2017.db
|
||||
pnpm build:all
|
||||
rm -f dist/thptqg2017.db dist/old/thptqg2017.db dist/old2/thptqg2017.db
|
||||
npm run build:rust
|
||||
npm run build:db
|
||||
|
||||
- name: Assemble site
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p _site
|
||||
cp index.html _site/
|
||||
cp -r 2016/dist _site/2016
|
||||
cp -r 2017/dist _site/2017
|
||||
# One Vite build produces every page. scripts/assemble-site.js copies the
|
||||
# emitted index.html to each dataset path (and the legacy nested URLs),
|
||||
# then fails the job if any uncompressed database reached the artifact.
|
||||
- name: Build and assemble site
|
||||
run: npm run build:site
|
||||
|
||||
- uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
|
||||
Reference in new issue
Block a user