Skip to content

Commit 4b96bb0

Browse files
committed
#1 test: add PR website
1 parent e4dedd1 commit 4b96bb0

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.github/workflows/docs.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,19 @@ jobs:
5252
to: html
5353

5454
- name: Publish docs
55+
# runs when main branch is updated, or when a PR is merged into main
5556
if: github.ref == 'refs/heads/main'
5657
uses: peaceiris/actions-gh-pages@v3
5758
with:
5859
github_token: ${{ secrets.GITHUB_TOKEN }}
5960
publish_dir: ./_site
61+
62+
- name: Publish PR docs in a subdirectory
63+
# runs when a PR is opened or updated, but not when merged into main
64+
if: github.event_name == 'pull_request' && github.base_ref == 'main'
65+
uses: peaceiris/actions-gh-pages@v4
66+
with:
67+
github_token: ${{ secrets.GITHUB_TOKEN }}
68+
publish_dir: ./_site
69+
destination_dir: ${{ github.head_ref }}
70+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Remove PR website
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
GITHUB_PAT:
7+
required: false
8+
description: GitHub API access token, which might be needed for downstream ops or rendering.
9+
pull_request:
10+
types:
11+
- closed
12+
branches:
13+
- main
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
delete-subfolder:
20+
runs-on: ubuntu-latest
21+
env:
22+
BRANCH: ${{ github.event.pull_request.head.ref }}
23+
steps:
24+
- name: Checkout repository (default branch)
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
persist-credentials: true
29+
30+
- name: Ensure gh-pages exists and check it out
31+
run: |
32+
set -euo pipefail
33+
if git ls-remote --heads origin gh-pages | grep -q 'refs/heads/gh-pages'; then
34+
git fetch origin gh-pages:gh-pages
35+
git checkout gh-pages
36+
else
37+
echo "gh-pages branch not found. Nothing to do."
38+
exit 0
39+
fi
40+
shell: bash
41+
42+
- name: Remove subfolder named after merged branch (if present)
43+
run: |
44+
set -euo pipefail
45+
SUBDIR="${BRANCH}"
46+
echo "SUBDIR: ${SUBDIR}"
47+
if [ -z "$SUBDIR" ]; then
48+
echo "Branch name empty. Nothing to do."
49+
exit 0
50+
fi
51+
52+
if [ -d "$SUBDIR" ]; then
53+
git rm -r --ignore-unmatch -- "$SUBDIR"
54+
if [ -n "$(git status --porcelain)" ]; then
55+
git config user.name "github-actions[bot]"
56+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
57+
git commit -m "ci: remove gh-pages subfolder for merged branch ${BRANCH}"
58+
git push origin gh-pages
59+
else
60+
echo "No changes to commit after removal."
61+
fi
62+
else
63+
echo "Subfolder '$SUBDIR' does not exist on gh-pages. Nothing to do."
64+
fi
65+
shell: bash

0 commit comments

Comments
 (0)