Skip to content

Commit fbb78dc

Browse files
committed
Add per-PR preview deployments of the documentation
PRs from branches of this repository are now built and deployed to the GitHub Pages site of hoylabs/OpenDTU-OnBattery-docs-previews, at https://hoylabs.github.io/OpenDTU-OnBattery-docs-previews/pr-preview/pr-<number>/. A sticky comment with the link is posted on the PR, and the preview is removed when the PR is closed or merged. A separate repository is used because this repository's Pages site has a custom domain, so its github.io URLs redirect to opendtu-onbattery.net. Pushing there requires a PREVIEW_DEPLOY_TOKEN secret; the production deployment is untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RXjeA94Kbc5bfLxDL6GJV9
1 parent cb0834c commit fbb78dc

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

‎.github/workflows/preview.yaml‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: PR Preview
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, closed]
6+
7+
permissions:
8+
contents: read
9+
pull-requests: write # post/update the sticky comment with the preview link
10+
11+
concurrency: preview-${{ github.ref }}
12+
13+
env:
14+
# Previews are published to the GitHub Pages site of this separate repo.
15+
# It must not use a custom domain, otherwise its github.io URLs redirect.
16+
PREVIEW_REPO: hoylabs/OpenDTU-OnBattery-docs-previews
17+
18+
jobs:
19+
preview:
20+
runs-on: ubuntu-latest
21+
22+
# secrets are not available for PRs from forks, so previews are only
23+
# possible for branches of this repository.
24+
if: github.event.pull_request.head.repo.full_name == github.repository
25+
26+
steps:
27+
- uses: actions/checkout@v7
28+
with:
29+
fetch-depth: 0
30+
persist-credentials: false
31+
32+
- name: Install Python and dependencies
33+
if: github.event.action != 'closed'
34+
uses: actions/setup-python@v7
35+
with:
36+
python-version: '3.x'
37+
cache: 'pip'
38+
- if: github.event.action != 'closed'
39+
run: pip install --upgrade pip wheel setuptools
40+
- if: github.event.action != 'closed'
41+
run: pip install -r requirements.txt
42+
43+
- if: github.event.action != 'closed'
44+
run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
45+
- if: github.event.action != 'closed'
46+
uses: actions/cache@v6
47+
with:
48+
key: mkdocs-material-${{ env.cache_id }}
49+
path: .cache
50+
restore-keys: |
51+
mkdocs-material-
52+
53+
- name: Build mkdocs
54+
if: github.event.action != 'closed'
55+
run: |
56+
mkdocs build
57+
# the preview must not claim the production domain
58+
rm -f site/CNAME
59+
# keep search engines away from the previews
60+
find site -name '*.html' -exec \
61+
sed -i 's|<head>|<head><meta name="robots" content="noindex">|' {} +
62+
63+
# deploys to pr-preview/pr-<number>/ on the gh-pages branch of
64+
# PREVIEW_REPO on open/push, and removes that folder again when the PR
65+
# is closed. The PR comment is posted using the default GITHUB_TOKEN.
66+
- name: Deploy preview
67+
uses: rossjrw/pr-preview-action@v1
68+
with:
69+
source-dir: ./site/
70+
deploy-repository: ${{ env.PREVIEW_REPO }}
71+
preview-branch: gh-pages
72+
umbrella-dir: pr-preview
73+
pages-base-url: hoylabs.github.io/OpenDTU-OnBattery-docs-previews
74+
token: ${{ secrets.PREVIEW_DEPLOY_TOKEN }}

0 commit comments

Comments
 (0)