| 1 |
name: Documentation |
| 2 |
on: |
| 3 |
push: |
| 4 |
branches: [master] |
| 5 |
pull_request: |
| 6 |
schedule: |
| 7 |
- cron: '0 6 * * 1' |
| 8 |
concurrency: |
| 9 |
group: ${{ github.workflow }}-${{ github.ref }} |
| 10 |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 11 |
permissions: |
| 12 |
contents: read |
| 13 |
jobs: |
| 14 |
build: |
| 15 |
name: Build |
| 16 |
runs-on: ubuntu-latest |
| 17 |
if: github.event_name != 'schedule' || github.repository == 'libmbd/libmbd' |
| 18 |
steps: |
| 19 |
- uses: actions/checkout@v6 |
| 20 |
with: |
| 21 |
fetch-depth: 0 |
| 22 |
- uses: actions/setup-python@v6 |
| 23 |
- name: Install Poetry |
| 24 |
run: | |
| 25 |
pipx install poetry |
| 26 |
pipx inject poetry poetry-dynamic-versioning |
| 27 |
- name: Build documentation |
| 28 |
run: make build_doc VIRTUAL_ENV=none |
| 29 |
- uses: actions/upload-artifact@v4 |
| 30 |
if: github.event_name == 'push' || github.event_name == 'pull_request' |
| 31 |
with: |
| 32 |
name: docs |
| 33 |
path: doc/build |
| 34 |
deploy-cloudflare: |
| 35 |
# Per-PR documentation preview on Cloudflare Pages. Production docs stay on |
| 36 |
# GitHub Pages (doc-deploy.yaml); this only runs for pull requests, so every |
| 37 |
# deploy lands on a non-production branch and Pages serves it as a preview. |
| 38 |
# Requires a Direct Upload Pages project named below and the repo secrets |
| 39 |
# CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID. Secrets aren't exposed to |
| 40 |
# PRs from forks, so previews only work for same-repo branches. |
| 41 |
name: Preview |
| 42 |
if: ${{ !cancelled() && needs.build.result == 'success' && github.event_name == 'pull_request' }} |
| 43 |
runs-on: ubuntu-latest |
| 44 |
needs: build |
| 45 |
permissions: |
| 46 |
contents: read |
| 47 |
pull-requests: write |
| 48 |
steps: |
| 49 |
- uses: actions/download-artifact@v4 |
| 50 |
with: |
| 51 |
name: docs |
| 52 |
path: doc/build |
| 53 |
- id: deploy |
| 54 |
uses: cloudflare/wrangler-action@v3 |
| 55 |
with: |
| 56 |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 57 |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 58 |
# v3 defaults to the old wrangler 3.90.0, which fails deploying with |
| 59 |
# "Cannot convert argument to a ByteString"; pin a current wrangler. |
| 60 |
wranglerVersion: '4.112.0' |
| 61 |
command: pages deploy doc/build --project-name=libmbd-docs --branch=${{ github.head_ref }} |
| 62 |
# Post (or update in place) a single PR comment with the preview links, |
| 63 |
# identified by an HTML-comment marker. URLs are passed via env, not |
| 64 |
# string-interpolated into the script, to avoid any injection. |
| 65 |
- uses: actions/github-script@v9 |
| 66 |
env: |
| 67 |
ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }} |
| 68 |
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }} |
| 69 |
with: |
| 70 |
script: | |
| 71 |
const marker = '<!-- cloudflare-preview -->'; |
| 72 |
const body = [ |
| 73 |
marker, |
| 74 |
`Documentation preview: ${process.env.ALIAS_URL}`, |
| 75 |
'', |
| 76 |
`Latest commit deploy: ${process.env.DEPLOY_URL}`, |
| 77 |
].join('\n'); |
| 78 |
const { owner, repo } = context.repo; |
| 79 |
const issue_number = context.issue.number; |
| 80 |
const comments = await github.paginate(github.rest.issues.listComments, { |
| 81 |
owner, repo, issue_number, |
| 82 |
}); |
| 83 |
const existing = comments.find((c) => c.body.includes(marker)); |
| 84 |
if (existing) { |
| 85 |
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); |
| 86 |
} else { |
| 87 |
await github.rest.issues.createComment({ owner, repo, issue_number, body }); |
| 88 |
} |