Skip to content

Commit abdf479

Browse files
keep multiple versions of github pages
1 parent d44d0bb commit abdf479

1 file changed

Lines changed: 31 additions & 39 deletions

File tree

.github/workflows/docs.yaml

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ on:
1111
workflow_dispatch:
1212

1313
permissions:
14-
contents: read
15-
pages: write
16-
id-token: write
14+
contents: write
1715

1816
jobs:
1917
pre:
@@ -32,7 +30,7 @@ jobs:
3230
3331
case $branch in
3432
famedly-release/v*)
35-
# strip 'release-' from the name for release branches.
33+
# strip 'famedly-release/' from the name for release branches.
3634
branch="${branch#famedly-release/v}"
3735
;;
3836
master)
@@ -47,7 +45,7 @@ jobs:
4745
branch-version: ${{ steps.vars.outputs.branch-version }}
4846

4947
################################################################################
50-
build:
48+
pages-docs:
5149
name: GitHub Pages
5250
runs-on: ubuntu-latest
5351
needs:
@@ -72,10 +70,6 @@ jobs:
7270
cargo install mdbook-linkcheck mdbook-mermaid
7371
cargo install mdbook --no-default-features --features search --vers "${{ env.MDBOOK_VERSION }}" --locked
7472
75-
- name: Setup Pages
76-
id: pages
77-
uses: actions/configure-pages@v5
78-
7973
- name: Set version of docs
8074
run: echo 'window.SYNAPSE_VERSION = "${{ needs.pre.outputs.branch-version }}";' > ./docs/website_files/version.js
8175

@@ -106,38 +100,36 @@ jobs:
106100
yq < schema/synapse-config.schema.yaml \
107101
> book/schema/synapse-config.schema.json
108102
109-
- name: Restructure for versioning
103+
# Deploy to the target directory without wiping other versions.
104+
# We use a git worktree so we can merge into gh-pages incrementally,
105+
# equivalent to what peaceiris/actions-gh-pages (action used by element/synapse)
106+
# does with destination_dir.
107+
- name: Deploy to gh-pages
110108
run: |
111-
# Create a clean output directory
112-
mkdir -p _site/${{ needs.pre.outputs.branch-version }}
109+
git config user.name "github-actions[bot]"
110+
git config user.email "github-actions[bot]@users.noreply.github.com"
113111
114-
# Move the built book (and schemas) into the versioned subdirectory
115-
mv book/* _site/${{ needs.pre.outputs.branch-version }}/
112+
VERSION="${{ needs.pre.outputs.branch-version }}"
116113
117-
# Create a root index.html that redirects to the versioned docs
118-
# This ensures https://famedly.github.io/synapse/ still works
119-
if [ "${{ needs.pre.outputs.branch-version }}" = "latest" ]; then
120-
echo '<!DOCTYPE html><meta http-equiv="refresh" content="0; url=latest/index.html">' > _site/index.html
114+
# Set up a worktree pointing at the gh-pages branch (create it if absent).
115+
git fetch origin gh-pages || true
116+
if git show-ref --verify --quiet refs/remotes/origin/gh-pages; then
117+
git worktree add gh-pages-dir origin/gh-pages
118+
else
119+
git worktree add --orphan -b gh-pages gh-pages-dir
121120
fi
122121
123-
- name: Upload artifact
124-
uses: actions/upload-pages-artifact@v3
125-
with:
126-
path: ./_site
127-
128-
deploy:
129-
if: ${{ github.ref == 'refs/heads/master' }}
130-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
131-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
132-
concurrency:
133-
group: "pages"
134-
cancel-in-progress: false
135-
environment:
136-
name: github-pages
137-
url: ${{ steps.deployment.outputs.page_url }}
138-
runs-on: ubuntu-latest
139-
needs: build
140-
steps:
141-
- name: Deploy to GitHub Pages
142-
id: deployment
143-
uses: actions/deploy-pages@v4
122+
# Replace only this version's directory, preserving all others.
123+
rm -rf gh-pages-dir/$VERSION
124+
cp -r book gh-pages-dir/$VERSION
125+
126+
# Ensure a root redirect to latest exists.
127+
if [ ! -f gh-pages-dir/index.html ]; then
128+
echo '<!DOCTYPE html><meta http-equiv="refresh" content="0; url=latest/index.html">' \
129+
> gh-pages-dir/index.html
130+
fi
131+
132+
cd gh-pages-dir
133+
git add .
134+
git diff --staged --quiet || git commit -m "docs: deploy $VERSION"
135+
git push origin HEAD:gh-pages

0 commit comments

Comments
 (0)