|
1 | | -name: Build Book |
| 1 | +name: CI & Book Publication |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
7 | 16 |
|
8 | 17 | jobs: |
9 | | - build: |
10 | | - if: ${{ github.repository_owner == 'pluralitybook' }} |
| 18 | + verify: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 23 | + |
| 24 | + - name: Setup Vite+ |
| 25 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 26 | + with: |
| 27 | + node-version: '24' |
| 28 | + cache: true |
| 29 | + run-install: false |
| 30 | + |
| 31 | + - name: Install dependencies (frozen) |
| 32 | + run: vp install --frozen-lockfile |
| 33 | + - name: Verify |
| 34 | + run: vp run check |
| 35 | + |
| 36 | + docs: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: verify |
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 42 | + |
| 43 | + - name: Setup Vite+ |
| 44 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 45 | + with: |
| 46 | + node-version: '24' |
| 47 | + cache: true |
| 48 | + run-install: false |
| 49 | + |
| 50 | + - name: Install dependencies (frozen) |
| 51 | + run: vp install --frozen-lockfile |
| 52 | + |
| 53 | + - name: Build docs |
| 54 | + run: vp run docs:build |
| 55 | + |
| 56 | + - name: Configure Pages |
| 57 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'pluralitybook' |
| 58 | + uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b |
| 59 | + |
| 60 | + # NOTE: This artifact is used for GitHub Pages deployment. The repository Pages source |
| 61 | + # must be switched from "gh-pages" branch to "GitHub Actions" only after this workflow goes green. |
| 62 | + - name: Upload Pages artifact |
| 63 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'pluralitybook' |
| 64 | + uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa |
| 65 | + with: |
| 66 | + path: docs/.vitepress/dist |
| 67 | + manifest: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: verify |
| 70 | + steps: |
| 71 | + - name: Checkout |
| 72 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 73 | + |
| 74 | + - name: Setup Vite+ |
| 75 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 76 | + with: |
| 77 | + node-version: '24' |
| 78 | + cache: true |
| 79 | + run-install: false |
| 80 | + |
| 81 | + - name: Install dependencies (frozen) |
| 82 | + run: vp install --frozen-lockfile |
| 83 | + |
| 84 | + - name: Derive Variables |
| 85 | + run: | |
| 86 | + echo "BOOK_DATE=$(git log -1 --format=%cs)" >> $GITHUB_ENV |
| 87 | + echo "SOURCE_REVISION=${{ github.sha }}" >> $GITHUB_ENV |
| 88 | +
|
| 89 | + - name: Assemble book & manifest |
| 90 | + run: vp run book:assemble |
| 91 | + |
| 92 | + - name: Upload Manifest and Manuscripts |
| 93 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 |
| 94 | + with: |
| 95 | + name: manifest-manuscripts |
| 96 | + path: | |
| 97 | + dist/publication/manifest.json |
| 98 | + dist/publication/en/Plurality-english.md |
| 99 | + dist/publication/zh-TW/Plurality-traditional-mandarin.md |
| 100 | +
|
| 101 | + legacy: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + needs: manifest |
| 104 | + strategy: |
| 105 | + matrix: |
| 106 | + locale: [en, zh-TW] |
| 107 | + steps: |
| 108 | + - name: Checkout |
| 109 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 110 | + |
| 111 | + - name: Setup Vite+ |
| 112 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 113 | + with: |
| 114 | + node-version: '24' |
| 115 | + cache: true |
| 116 | + run-install: false |
| 117 | + |
| 118 | + - name: Install dependencies (frozen) |
| 119 | + run: vp install --frozen-lockfile |
| 120 | + |
| 121 | + - name: Derive Variables |
| 122 | + run: | |
| 123 | + echo "BOOK_DATE=$(git log -1 --format=%cs)" >> $GITHUB_ENV |
| 124 | + echo "SOURCE_REVISION=${{ github.sha }}" >> $GITHUB_ENV |
| 125 | +
|
| 126 | + - name: Render legacy output |
| 127 | + run: vp run book:legacy:${{ matrix.locale }} |
| 128 | + |
| 129 | + - name: Upload legacy artifact |
| 130 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 |
| 131 | + with: |
| 132 | + name: legacy-${{ matrix.locale }} |
| 133 | + path: dist/publication/legacy |
| 134 | + |
| 135 | + legacy-validation: |
| 136 | + runs-on: ubuntu-latest |
| 137 | + needs: [manifest, legacy] |
| 138 | + steps: |
| 139 | + - name: Checkout |
| 140 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 141 | + |
| 142 | + - name: Setup Vite+ |
| 143 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 144 | + with: |
| 145 | + node-version: '24' |
| 146 | + cache: true |
| 147 | + run-install: false |
| 148 | + |
| 149 | + - name: Install dependencies (frozen) |
| 150 | + run: vp install --frozen-lockfile |
| 151 | + |
| 152 | + - name: Download manifest and manuscripts |
| 153 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 154 | + with: |
| 155 | + name: manifest-manuscripts |
| 156 | + path: dist/publication |
| 157 | + |
| 158 | + - name: Download legacy artifacts |
| 159 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 160 | + with: |
| 161 | + pattern: legacy-* |
| 162 | + path: dist/publication/legacy |
| 163 | + merge-multiple: true |
| 164 | + |
| 165 | + - name: Validate legacy outputs |
| 166 | + env: |
| 167 | + EXPECTED_SOURCE_REVISION: ${{ github.sha }} |
| 168 | + run: vp run book:legacy:validate |
| 169 | + |
| 170 | + candidate: |
| 171 | + runs-on: ubuntu-latest |
| 172 | + needs: manifest |
| 173 | + strategy: |
| 174 | + matrix: |
| 175 | + locale: [en, zh-TW] |
| 176 | + steps: |
| 177 | + - name: Checkout |
| 178 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 179 | + |
| 180 | + - name: Setup Vite+ |
| 181 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 182 | + with: |
| 183 | + node-version: '24' |
| 184 | + cache: true |
| 185 | + run-install: false |
| 186 | + - name: Install fonts |
| 187 | + run: | |
| 188 | + sudo apt-get update |
| 189 | + sudo apt-get install -y fonts-noto-cjk fonts-noto-color-emoji |
| 190 | +
|
| 191 | + - name: Install dependencies (frozen) |
| 192 | + run: vp install --frozen-lockfile |
| 193 | + |
| 194 | + - name: Derive Variables |
| 195 | + run: | |
| 196 | + echo "BOOK_DATE=$(git log -1 --format=%cs)" >> $GITHUB_ENV |
| 197 | + echo "SOURCE_REVISION=${{ github.sha }}" >> $GITHUB_ENV |
| 198 | +
|
| 199 | + - name: Render candidate output |
| 200 | + run: vp run book:candidate:${{ matrix.locale }} |
| 201 | + |
| 202 | + - name: Upload candidate artifact |
| 203 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 |
| 204 | + with: |
| 205 | + name: candidate-${{ matrix.locale }} |
| 206 | + path: dist/publication/candidate |
| 207 | + |
| 208 | + candidate-validation: |
| 209 | + runs-on: ubuntu-latest |
| 210 | + needs: [manifest, candidate] |
| 211 | + steps: |
| 212 | + - name: Checkout |
| 213 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 214 | + |
| 215 | + - name: Setup Vite+ |
| 216 | + uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb |
| 217 | + with: |
| 218 | + node-version: '24' |
| 219 | + cache: true |
| 220 | + run-install: false |
| 221 | + - name: Install dependencies (frozen) |
| 222 | + run: vp install --frozen-lockfile |
| 223 | + |
| 224 | + - name: Download manifest and manuscripts |
| 225 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 226 | + with: |
| 227 | + name: manifest-manuscripts |
| 228 | + path: dist/publication |
| 229 | + |
| 230 | + - name: Download candidate artifacts |
| 231 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 232 | + with: |
| 233 | + pattern: candidate-* |
| 234 | + path: dist/publication/candidate |
| 235 | + merge-multiple: true |
| 236 | + |
| 237 | + - name: Validate candidate outputs |
| 238 | + env: |
| 239 | + EXPECTED_SOURCE_REVISION: ${{ github.sha }} |
| 240 | + run: vp run book:candidate:validate |
| 241 | + |
| 242 | + # NOTE: The GitHub Pages build/deployment source must be switched from the legacy "gh-pages" branch |
| 243 | + # to "GitHub Actions" in the repository settings ONLY after this workflow has run successfully and is green. |
| 244 | + # DO NOT mutate live Pages settings or push directly. |
| 245 | + deploy-pages: |
| 246 | + runs-on: ubuntu-latest |
| 247 | + needs: docs |
| 248 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'pluralitybook' |
| 249 | + permissions: |
| 250 | + pages: write |
| 251 | + id-token: write |
| 252 | + steps: |
| 253 | + - name: Deploy to GitHub Pages |
| 254 | + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e |
| 255 | + |
| 256 | + release: |
11 | 257 | runs-on: ubuntu-latest |
| 258 | + needs: [legacy-validation, docs] |
| 259 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'pluralitybook' |
12 | 260 | permissions: |
13 | 261 | contents: write |
14 | | - packages: write |
15 | | - steps: |
16 | | - - uses: actions/checkout@v2 |
17 | | - - name: Rebuild the plurality.net website |
18 | | - env: |
19 | | - REBUILD_WEBHOOK: ${{ secrets.REBUILD_WEBHOOK }} |
20 | | - run: | |
21 | | - curl -X POST -d {} "$REBUILD_WEBHOOK" |
22 | | - - name: Generate book files |
23 | | - run: | |
24 | | - # Install necessary dependencies (e.g., Perl, Docker) |
25 | | - perl scripts/make-book.pl |
26 | | - - name: Generate book files (zh-tw) |
27 | | - run: | |
28 | | - perl scripts/make-book-zh-tw.pl |
29 | | - - uses: ncipollo/release-action@v1 |
30 | | - with: |
31 | | - artifacts: "*.pdf,*.epub" |
32 | | - tag: latest |
33 | | - allowUpdates: true |
| 262 | + steps: |
| 263 | + - name: Checkout |
| 264 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 |
| 265 | + |
| 266 | + - name: Download manifest and manuscripts |
| 267 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 268 | + with: |
| 269 | + name: manifest-manuscripts |
| 270 | + path: dist/publication |
| 271 | + |
| 272 | + - name: Download legacy artifacts |
| 273 | + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 274 | + with: |
| 275 | + pattern: legacy-* |
| 276 | + path: dist/publication/legacy |
| 277 | + merge-multiple: true |
| 278 | + |
| 279 | + - name: Create or Update GitHub Release |
| 280 | + uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd |
| 281 | + with: |
| 282 | + allowUpdates: true |
| 283 | + removeArtifacts: false |
| 284 | + replacesArtifacts: true |
| 285 | + artifactErrorsFailBuild: true |
| 286 | + tag: latest |
| 287 | + name: "Latest Book Release" |
| 288 | + artifacts: "dist/publication/manifest.json,dist/publication/legacy/Plurality-english.pdf,dist/publication/legacy/Plurality-english.epub,dist/publication/legacy/Plurality-traditional-mandarin.pdf,dist/publication/legacy/Plurality-traditional-mandarin.epub" |
| 289 | + |
| 290 | + webhook: |
| 291 | + runs-on: ubuntu-latest |
| 292 | + needs: [release, deploy-pages] |
| 293 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'pluralitybook' |
| 294 | + steps: |
| 295 | + - name: Send Rebuild Webhook |
| 296 | + env: |
| 297 | + REBUILD_WEBHOOK: ${{ secrets.REBUILD_WEBHOOK }} |
| 298 | + run: | |
| 299 | + curl --fail-with-body --retry 3 --retry-all-errors -X POST \ |
| 300 | + -H "Content-Type: application/json" \ |
| 301 | + -d "{\"revision\":\"${{ github.sha }}\",\"manifest_release_url\":\"https://github.com/${{ github.repository }}/releases/download/latest/manifest.json\",\"release_url\":\"https://github.com/${{ github.repository }}/releases/tag/latest\"}" \ |
| 302 | + "$REBUILD_WEBHOOK" |
0 commit comments