Merge companion-website: deploy the LFS surface meshes #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Publish the companion site (web/) to GitHub Pages. | |
| # | |
| # The site has no build step: it is plain ES modules with an import map | |
| # and a vendored copy of three.js, so "building" is really just staging. | |
| # The one piece of assembly is the database. | |
| # | |
| # web/js/data.js asks for `../data/polyhedra/...` relative to itself, | |
| # which resolves to `web/data/polyhedra/`. That directory is NOT in git | |
| # -- the database lives at the repository's own `data/polyhedra/` and is | |
| # copied into place here. Locally, web/serve.py routes the same URL to | |
| # the same directory instead of copying. Either way a page requests one | |
| # URL and gets one answer, in development and in production alike, and | |
| # the database is never duplicated in the repository. | |
| # | |
| # Checkout must pull LFS: the 448 catalogue thumbnails in web/thumbs/ are | |
| # LFS objects, and without them every tile in the grid is a pointer file. | |
| name: Deploy companion site | |
| on: | |
| push: | |
| branches: [master] | |
| paths: | |
| - 'web/**' | |
| - 'data/polyhedra/**' | |
| - 'data/surfaces/**' | |
| - 'tools/site_seo.py' | |
| - 'tests/test_web.py' | |
| - '.github/workflows/pages.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Let a running deploy finish rather than cancelling it midway; a | |
| # half-published site is worse than a slightly stale one. | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # LFS is fetched by hand, for the paths this site actually serves. | |
| # `lfs: true` on checkout pulls every object in the repository, and | |
| # docs/images/ is ~200 MB of generator figures the site never | |
| # serves -- against a 1 GB/month bandwidth allowance that is a few | |
| # deploys and no more. | |
| # | |
| # BOTH paths are needed and only one used to be listed. The meshes | |
| # are LFS too (see .gitattributes), so the site deployed 466 | |
| # 130-byte pointer files where the geometry should be, every | |
| # surface failed to parse, and the viewer showed nothing. The | |
| # thumbnails were fine, so the catalogue looked healthy and only | |
| # the 3-D view was empty -- and the build stayed green, because the | |
| # check below counted mesh FILES rather than looking inside them. | |
| - name: Fetch the tiles and the meshes | |
| run: git lfs pull --include="web/thumbs/**,web/surfaces/**" | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| # The catalog pages, sitemap and head metadata are derived from the | |
| # two databases. Regenerating before the gate means a database | |
| # change that reached master without a re-run still deploys a | |
| # correct site, and the gate then checks the result rather than | |
| # whatever happened to be committed. | |
| - name: Refresh the generated metadata | |
| run: python tools/site_seo.py | |
| - name: Gate the site | |
| run: python tests/test_web.py | |
| - name: Stage the databases | |
| run: | | |
| mkdir -p web/data | |
| cp -r data/polyhedra web/data/polyhedra | |
| cp -r data/surfaces web/data/surfaces | |
| - name: Check the staged tree | |
| run: | | |
| test -f web/data/polyhedra/index.json | |
| test -f web/data/surfaces/index.json | |
| echo "thumbnails: $(find web/thumbs -name '*.png' | wc -l)" | |
| echo "solids: $(find web/data/polyhedra/solids -name '*.json' | wc -l)" | |
| echo "surfaces: $(find web/data/surfaces/surfaces -name '*.json' | wc -l)" | |
| echo "meshes: $(ls web/surfaces/*.json 2>/dev/null | wc -l)" | |
| echo "payload: $(du -sh web | cut -f1)" | |
| # An unresolved LFS pointer deploys perfectly happily -- it is | |
| # a small text file, and a web server will serve it with a 200. | |
| # The failure is therefore silent: broken tiles, or a viewer | |
| # with no geometry, on a green build. | |
| # | |
| # Checked by CONTENT, not by size. The previous version looked | |
| # for files under 1 kB, which is a proxy for "pointer" that | |
| # misses the question entirely -- and it only looked at the | |
| # thumbnails, which is how 466 pointer meshes shipped. | |
| ptr=$(grep -rl --include='*.png' --include='*.json' '^version https://git-lfs.github.com/spec/v1' web/thumbs web/surfaces 2>/dev/null | wc -l) | |
| if [ "$ptr" -ne 0 ]; then | |
| echo "::error::$ptr file(s) are unresolved LFS pointers" | |
| grep -rl --include='*.png' --include='*.json' '^version https://git-lfs.github.com/spec/v1' web/thumbs web/surfaces 2>/dev/null | head -5 | |
| exit 1 | |
| fi | |
| - uses: actions/configure-pages@v5 | |
| - uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: web | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - id: deployment | |
| uses: actions/deploy-pages@v4 |