|
| 1 | +# Deploy multilingual docs to GitHub Pages. |
| 2 | +# |
| 3 | +# This workflow replaces GitHub's default Jekyll deployment so we can: |
| 4 | +# 1. Build the multilingual WASM browser bundle from source. |
| 5 | +# 2. Copy the resulting .wasm + JS glue into assets/wasm/. |
| 6 | +# 3. Build the Jekyll site with the bundled artifacts in place. |
| 7 | +# 4. Deploy _site/ to GitHub Pages. |
| 8 | +# |
| 9 | +# Trigger: every push to main, or manually via workflow_dispatch. |
| 10 | + |
| 11 | +name: Build and deploy docs |
| 12 | + |
| 13 | +on: |
| 14 | + push: |
| 15 | + branches: [main] |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +# Required for the deploy-pages action. |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + pages: write |
| 22 | + id-token: write |
| 23 | + |
| 24 | +# Cancel in-progress runs on the same branch so pushes don't queue up. |
| 25 | +concurrency: |
| 26 | + group: pages-${{ github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + # ── Job 1: Build WASM ──────────────────────────────────────────────────── |
| 31 | + build-wasm: |
| 32 | + name: Build WASM browser bundle |
| 33 | + runs-on: ubuntu-latest |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout multilingual source |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + repository: johnsamuelwrites/multilingual |
| 40 | + path: multilingual-src |
| 41 | + |
| 42 | + - name: Set up Rust toolchain |
| 43 | + uses: dtolnay/rust-toolchain@stable |
| 44 | + with: |
| 45 | + targets: wasm32-unknown-unknown |
| 46 | + |
| 47 | + - name: Cache Rust build artefacts |
| 48 | + uses: actions/cache@v4 |
| 49 | + with: |
| 50 | + path: | |
| 51 | + ~/.cargo/registry |
| 52 | + ~/.cargo/git |
| 53 | + multilingual-src/target |
| 54 | + key: ${{ runner.os }}-cargo-${{ hashFiles('multilingual-src/**/Cargo.lock') }} |
| 55 | + restore-keys: ${{ runner.os }}-cargo- |
| 56 | + |
| 57 | + - name: Install wasm-pack |
| 58 | + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh |
| 59 | + |
| 60 | + - name: Build WASM browser package |
| 61 | + working-directory: multilingual-src |
| 62 | + run: | |
| 63 | + # build_wasm.sh produces wasm/pkg/ with multilingual.js + |
| 64 | + # multilingual_bg.wasm (wasm-pack / wasm-bindgen output). |
| 65 | + # Fall back to wasm-pack directly if the script is absent. |
| 66 | + if [ -f build_wasm.sh ]; then |
| 67 | + bash build_wasm.sh --target web |
| 68 | + else |
| 69 | + wasm-pack build --target web --out-dir wasm/pkg \ |
| 70 | + --out-name multilingual |
| 71 | + fi |
| 72 | +
|
| 73 | + # Install the WebAssembly Binary Toolkit so we can generate the WAT |
| 74 | + # (text format) alongside the binary for display in the docs. |
| 75 | + - name: Install wabt (wasm2wat) |
| 76 | + run: | |
| 77 | + sudo apt-get install -y wabt |
| 78 | +
|
| 79 | + - name: Generate WAT text format |
| 80 | + working-directory: multilingual-src/wasm/pkg |
| 81 | + run: | |
| 82 | + # Convert every .wasm binary to its human-readable .wat counterpart. |
| 83 | + for f in *.wasm; do |
| 84 | + wasm2wat "$f" -o "${f%.wasm}.wat" || true |
| 85 | + done |
| 86 | +
|
| 87 | + - name: Upload WASM artefacts |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: wasm-pkg |
| 91 | + # Includes both .wasm binaries and .wat text files. |
| 92 | + path: multilingual-src/wasm/pkg/ |
| 93 | + retention-days: 1 |
| 94 | + |
| 95 | + # ── Job 2: Build Jekyll ─────────────────────────────────────────────────── |
| 96 | + build-jekyll: |
| 97 | + name: Build Jekyll site |
| 98 | + runs-on: ubuntu-latest |
| 99 | + needs: build-wasm |
| 100 | + |
| 101 | + steps: |
| 102 | + - name: Checkout docs repo |
| 103 | + uses: actions/checkout@v4 |
| 104 | + |
| 105 | + - name: Download WASM artefacts |
| 106 | + uses: actions/download-artifact@v4 |
| 107 | + with: |
| 108 | + name: wasm-pkg |
| 109 | + path: assets/wasm/ |
| 110 | + |
| 111 | + - name: Set up Ruby |
| 112 | + uses: ruby/setup-ruby@v1 |
| 113 | + with: |
| 114 | + ruby-version: '3.3' |
| 115 | + bundler-cache: true # runs `bundle install` and caches gems |
| 116 | + |
| 117 | + - name: Configure GitHub Pages |
| 118 | + id: pages |
| 119 | + uses: actions/configure-pages@v5 |
| 120 | + |
| 121 | + # Jekyll is built with JEKYLL_ENV=production so jekyll-seo-tag, |
| 122 | + # jekyll-sitemap, etc. output canonical URLs correctly. |
| 123 | + - name: Build Jekyll site |
| 124 | + env: |
| 125 | + JEKYLL_ENV: production |
| 126 | + run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" |
| 127 | + |
| 128 | + - name: Upload Pages artefact |
| 129 | + uses: actions/upload-pages-artifact@v3 |
| 130 | + with: |
| 131 | + path: _site/ |
| 132 | + |
| 133 | + # ── Job 3: Deploy ───────────────────────────────────────────────────────── |
| 134 | + deploy: |
| 135 | + name: Deploy to GitHub Pages |
| 136 | + runs-on: ubuntu-latest |
| 137 | + needs: build-jekyll |
| 138 | + |
| 139 | + environment: |
| 140 | + name: github-pages |
| 141 | + url: ${{ steps.deploy.outputs.page_url }} |
| 142 | + |
| 143 | + steps: |
| 144 | + - name: Deploy to GitHub Pages |
| 145 | + id: deploy |
| 146 | + uses: actions/deploy-pages@v4 |
0 commit comments