|
11 | 11 | workflow_dispatch: |
12 | 12 |
|
13 | 13 | permissions: |
14 | | - contents: read |
15 | | - pages: write |
16 | | - id-token: write |
| 14 | + contents: write |
17 | 15 |
|
18 | 16 | jobs: |
19 | 17 | pre: |
|
32 | 30 |
|
33 | 31 | case $branch in |
34 | 32 | famedly-release/v*) |
35 | | - # strip 'release-' from the name for release branches. |
| 33 | + # strip 'famedly-release/' from the name for release branches. |
36 | 34 | branch="${branch#famedly-release/v}" |
37 | 35 | ;; |
38 | 36 | master) |
|
47 | 45 | branch-version: ${{ steps.vars.outputs.branch-version }} |
48 | 46 |
|
49 | 47 | ################################################################################ |
50 | | - build: |
| 48 | + pages-docs: |
51 | 49 | name: GitHub Pages |
52 | 50 | runs-on: ubuntu-latest |
53 | 51 | needs: |
|
72 | 70 | cargo install mdbook-linkcheck mdbook-mermaid |
73 | 71 | cargo install mdbook --no-default-features --features search --vers "${{ env.MDBOOK_VERSION }}" --locked |
74 | 72 |
|
75 | | - - name: Setup Pages |
76 | | - id: pages |
77 | | - uses: actions/configure-pages@v5 |
78 | | - |
79 | 73 | - name: Set version of docs |
80 | 74 | run: echo 'window.SYNAPSE_VERSION = "${{ needs.pre.outputs.branch-version }}";' > ./docs/website_files/version.js |
81 | 75 |
|
@@ -106,38 +100,36 @@ jobs: |
106 | 100 | yq < schema/synapse-config.schema.yaml \ |
107 | 101 | > book/schema/synapse-config.schema.json |
108 | 102 |
|
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 |
110 | 108 | 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" |
113 | 111 |
|
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 }}" |
116 | 113 |
|
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 |
121 | 120 | fi |
122 | 121 |
|
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