name: Documentation on: push: branches: [master] pull_request: schedule: - cron: '0 6 * * 1' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} permissions: contents: read jobs: build: name: Build runs-on: ubuntu-latest if: github.event_name != 'schedule' || github.repository == 'libmbd/libmbd' steps: - uses: actions/checkout@v6 with: fetch-depth: 0 - uses: actions/setup-python@v6 - name: Install Poetry run: | pipx install poetry pipx inject poetry poetry-dynamic-versioning - name: Build documentation run: make build_doc VIRTUAL_ENV=none - uses: actions/upload-artifact@v4 if: github.event_name == 'push' || github.event_name == 'pull_request' with: name: docs path: doc/build deploy-cloudflare: # Per-PR documentation preview on Cloudflare Pages. Production docs stay on # GitHub Pages (doc-deploy.yaml); this only runs for pull requests, so every # deploy lands on a non-production branch and Pages serves it as a preview. # Requires a Direct Upload Pages project named below and the repo secrets # CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID. Secrets aren't exposed to # PRs from forks, so previews only work for same-repo branches. name: Preview if: ${{ !cancelled() && needs.build.result == 'success' && github.event_name == 'pull_request' }} runs-on: ubuntu-latest needs: build permissions: contents: read pull-requests: write steps: - uses: actions/download-artifact@v4 with: name: docs path: doc/build - id: deploy uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} # v3 defaults to the old wrangler 3.90.0, which fails deploying with # "Cannot convert argument to a ByteString"; pin a current wrangler. wranglerVersion: '4.112.0' command: pages deploy doc/build --project-name=libmbd-docs --branch=${{ github.head_ref }} # Post (or update in place) a single PR comment with the preview links, # identified by an HTML-comment marker. URLs are passed via env, not # string-interpolated into the script, to avoid any injection. - uses: actions/github-script@v9 env: ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }} DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }} with: script: | const marker = ''; const body = [ marker, `Documentation preview: ${process.env.ALIAS_URL}`, '', `Latest commit deploy: ${process.env.DEPLOY_URL}`, ].join('\n'); const { owner, repo } = context.repo; const issue_number = context.issue.number; const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number, }); const existing = comments.find((c) => c.body.includes(marker)); if (existing) { await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); } else { await github.rest.issues.createComment({ owner, repo, issue_number, body }); }