|
| 1 | +name: Docs |
| 2 | + |
| 3 | +# - PR with docs changes: build a /-rooted bundle (preview) |
| 4 | +# - push to main with docs changes: build /Apollon/-rooted bundle, deploy |
| 5 | +# to GitHub Pages |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [main] |
| 10 | + paths: |
| 11 | + - "docs/**" |
| 12 | + - "library/**" |
| 13 | + - "pnpm-lock.yaml" |
| 14 | + - "pnpm-workspace.yaml" |
| 15 | + - ".github/workflows/docs.yml" |
| 16 | + pull_request: |
| 17 | + paths: |
| 18 | + - "docs/**" |
| 19 | + - "library/**" |
| 20 | + - ".github/workflows/docs.yml" |
| 21 | + workflow_dispatch: |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + pages: write |
| 26 | + id-token: write |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: docs-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref }} |
| 30 | + cancel-in-progress: true |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + name: Build Docusaurus site |
| 35 | + runs-on: ubuntu-latest |
| 36 | + timeout-minutes: 15 |
| 37 | + outputs: |
| 38 | + is-production: ${{ steps.flag.outputs.is-production }} |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 41 | + |
| 42 | + - uses: pnpm/action-setup@ac6db6d3c1f721f886538a378a2d73e85697340a # v6.0.8 |
| 43 | + |
| 44 | + - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 |
| 45 | + with: |
| 46 | + node-version-file: ".nvmrc" |
| 47 | + cache: "pnpm" |
| 48 | + |
| 49 | + - id: flag |
| 50 | + run: | |
| 51 | + if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 52 | + echo "is-production=true" >> "$GITHUB_OUTPUT" |
| 53 | + else |
| 54 | + echo "is-production=false" >> "$GITHUB_OUTPUT" |
| 55 | + fi |
| 56 | +
|
| 57 | + - run: pnpm install --frozen-lockfile |
| 58 | + |
| 59 | + # Library must be built first — the docs site imports |
| 60 | + # `@tumaet/apollon` for the live embed on the homepage. |
| 61 | + - run: pnpm --filter @tumaet/apollon run build |
| 62 | + |
| 63 | + - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5 |
| 64 | + with: |
| 65 | + path: | |
| 66 | + docs/.docusaurus |
| 67 | + docs/node_modules/.cache |
| 68 | + key: docusaurus-${{ steps.flag.outputs.is-production }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('docs/**/*.{md,mdx,ts,tsx}') }} |
| 69 | + restore-keys: | |
| 70 | + docusaurus-${{ steps.flag.outputs.is-production }}-${{ hashFiles('pnpm-lock.yaml') }}- |
| 71 | + docusaurus-${{ steps.flag.outputs.is-production }}- |
| 72 | +
|
| 73 | + - run: pnpm --filter @tumaet/apollon-docs run build |
| 74 | + env: |
| 75 | + DOCUSAURUS_BASE_URL: ${{ steps.flag.outputs.is-production == 'true' && '/Apollon/' || '/' }} |
| 76 | + |
| 77 | + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 |
| 78 | + with: |
| 79 | + name: docs-build |
| 80 | + path: docs/build |
| 81 | + retention-days: 7 |
| 82 | + if-no-files-found: error |
| 83 | + |
| 84 | + - if: steps.flag.outputs.is-production == 'true' |
| 85 | + uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3 |
| 86 | + with: |
| 87 | + path: docs/build |
| 88 | + |
| 89 | + deploy: |
| 90 | + name: Deploy to GitHub Pages |
| 91 | + needs: build |
| 92 | + if: needs.build.outputs.is-production == 'true' |
| 93 | + runs-on: ubuntu-latest |
| 94 | + environment: |
| 95 | + name: github-pages |
| 96 | + url: ${{ steps.deployment.outputs.page_url }} |
| 97 | + steps: |
| 98 | + - id: deployment |
| 99 | + uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4 |
0 commit comments