1010
1111# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1212permissions :
13- contents : read
13+ contents : write
1414 pages : write
1515 id-token : write
1616
@@ -104,6 +104,7 @@ jobs:
104104 environment : deploy
105105 outputs :
106106 npm_tag : ${{ steps.determine_npm_tag.outputs.npm_tag }}
107+ version : ${{ steps.get_tag.outputs.tag }}
107108 steps :
108109 - name : Checkout sources
109110 uses : actions/checkout@v5
@@ -157,10 +158,8 @@ jobs:
157158 deploy-typedoc :
158159 needs :
159160 - upload-release
160- if : needs.upload-release.outputs.npm_tag == 'latest'
161161 environment :
162162 name : github-pages
163- url : ${{ steps.deployment.outputs.page_url }}
164163 runs-on : ubuntu-22.04
165164 steps :
166165 - name : Checkout
@@ -172,14 +171,52 @@ jobs:
172171 path : typedoc
173172 name : typedoc-build
174173
175- - name : Setup Pages
176- uses : actions/configure-pages@v5
174+ # Clone old `gh-pages` branch so we can later build a list of
175+ # available documentation versions.
176+ - name : Clone old gh-pages content
177+ run : |
178+ # Make a local work folder
179+ mkdir -p gh-pages
177180
178- - name : Upload GH pages artifact
179- uses : actions/upload-pages-artifact@v3
180- with :
181- path : ' ./typedoc'
181+ # Copy its content into local `gh-pages` folder
182+ git clone --branch gh-pages --depth 1 https://github.com/Concordium/concordium-node-sdk-js old-gh-pages
183+ cp -r old-gh-pages/* gh-pages/
184+
185+ # Put new docs into a versioned subfolder
186+ - name : Generate versioned subfolder
187+ run : |
188+ VERSION=${{ needs.upload-release.outputs.version }}
189+ mkdir -p gh-pages/$VERSION
190+ cp -r typedoc/* gh-pages/$VERSION
191+
192+ # Update the "latest" subfolder content with the newest doc version.
193+ - name : Update `latest` subfolder content
194+ if : needs.upload-release.outputs.npm_tag == 'latest'
195+ run : |
196+ mkdir -p gh-pages/latest
197+ rm -rf gh-pages/latest/*
198+ cp -r typedoc/* gh-pages/latest
182199
183- - name : Deploy to GitHub Pages
184- id : deployment
185- uses : actions/deploy-pages@v4
200+ # Generate list of available documentation versions.
201+ # This needs to be done after the `gh-pages` branch has been fetched with the old docs.
202+ - name : Generate docs index
203+ run : |
204+ echo "<!DOCTYPE html>" > gh-pages/index.html
205+ echo "<html lang=\"en\"><head><meta charset=\"utf-8\"><title>Documentation Versions</title></head><body>" >> gh-pages/index.html
206+ echo "<h1>Available Documentation Versions</h1><ul>" >> gh-pages/index.html
207+
208+ # Loop over all directories in gh-pages/
209+ for d in gh-pages/*/ ; do
210+ version=$(basename "$d")
211+ echo "<li><a href=\"./$version/\">$version</a></li>" >> gh-pages/index.html
212+ done
213+
214+ echo "</ul>" >> gh-pages/index.html
215+ echo "</body></html>" >> gh-pages/index.html
216+
217+ - name : Deploy
218+ uses : peaceiris/actions-gh-pages@v4
219+ with :
220+ github_token : ${{ secrets.GITHUB_TOKEN }}
221+ publish_dir : ./gh-pages
222+ keep_files : true
0 commit comments