fix docs preview #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Docs Preview (Pages) | ||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
pull-requests: write | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v5 | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y doxygen graphviz | ||
python3 -m pip install --upgrade pip | ||
python3 -m pip install mkdocs mkdocs-material pymdown-extensions | ||
- name: Build docs (Makefile) | ||
run: make clean document | ||
- name: Upload Pages artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: site | ||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
steps: | ||
- id: deployment | ||
uses: actions/deploy-pages@v4 | ||
with: | ||
preview: true | ||
- name: Add preview URL to summary | ||
env: | ||
PAGE_URL: ${{ steps.deployment.outputs.page_url }} | ||
run: echo "Preview: $PAGE_URL" >> "$GITHUB_STEP_SUMMARY" | ||
- name: Comment preview URL on PR | ||
uses: actions/github-script@v7 | ||
env: | ||
PAGE_URL: ${{ steps.deployment.outputs.page_url }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const pr_number = context.payload.pull_request.number; | ||
const url = process.env.PAGE_URL; | ||
const marker = '<!-- pages-preview-url -->'; | ||
const body = `${marker}\nPreview: ${url}`; | ||
const { data: comments } = await github.rest.issues.listComments({ owner, repo, issue_number: pr_number }); | ||
const prev = comments.find(c => (c.body || '').includes(marker)); | ||
if (prev) { | ||
await github.rest.issues.updateComment({ owner, repo, comment_id: prev.id, body }); | ||
} else { | ||
await github.rest.issues.createComment({ owner, repo, issue_number: pr_number, body }); | ||
} | ||