Deploy website #9
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
| name: Deploy website | |
| on: | |
| workflow_run: | |
| workflows: | |
| - Test package and web app | |
| types: | |
| - completed | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: github-pages | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| if: >- | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout tested source | |
| uses: actions/checkout@v7 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }} | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v7 | |
| with: | |
| python-version: "3.14" | |
| - name: Set up uv | |
| uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1 | |
| with: | |
| version: "0.12.8" | |
| - name: Build current wenxian wheel | |
| run: uv build --wheel | |
| - name: Assemble website and prebuilt Python environment | |
| run: | | |
| mkdir _site | |
| cp -a docs/. _site/ | |
| wheel=$(echo dist/wenxian-*.whl) | |
| python scripts/build_web_bundle.py \ | |
| "$wheel" _site/wenxian-web-packages.tar.gz | |
| - name: Validate deployed bundle | |
| run: | | |
| test -f _site/index.html | |
| test -f _site/webworker.js | |
| test -f _site/wenxian-web-packages.tar.gz | |
| bundle_bytes=$(stat -c%s _site/wenxian-web-packages.tar.gz) | |
| echo "Web bundle: $bundle_bytes bytes" | |
| test "$bundle_bytes" -lt 1000000 | |
| mkdir bundle-check | |
| tar -xzf _site/wenxian-web-packages.tar.gz -C bundle-check | |
| PYTHONPATH=bundle-check python - <<'PY' | |
| import json | |
| from importlib.metadata import version | |
| from pathlib import Path | |
| import pyiso4 | |
| import pylatexenc | |
| import unidecode | |
| import wenxian | |
| manifest = json.loads( | |
| Path("bundle-check/wenxian-web-manifest.json").read_text() | |
| ) | |
| assert manifest["format"] == 1 | |
| assert manifest["packages"]["wenxian"] == version("wenxian") | |
| assert manifest["requirements_lock"] == "web-requirements.lock" | |
| assert "requests" not in {name.lower() for name in manifest["packages"]} | |
| assert manifest["requirements"] == [ | |
| "pyiso4==0.1.6", | |
| "pylatexenc==3.0a21", | |
| "unidecode==1.4.0", | |
| ] | |
| print(json.dumps(manifest, indent=2, sort_keys=True)) | |
| PY | |
| - name: Upload website artifact | |
| uses: actions/upload-pages-artifact@v5 | |
| with: | |
| path: _site | |
| deploy: | |
| if: >- | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.workflow_run.conclusion == 'success' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy website and Python bundle together | |
| id: deployment | |
| uses: actions/deploy-pages@v5 |