forked from OCamlPro/alt-ergo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(doc): Versioned documentation pages
This patch overhauls documentation generation to support separate documentation pages for each Alt-ergo version on the GitHub pages website. We generate one version for the `next` and `main` branch, and one version for each tag of the form `v*.*.*`. The version selector from Sphinx is used to allow users to change the version (it appears in the lower-right corner of the page). We also keep a `latest` version that points to the latest tag that was built (using a symbolic link). The default page redirects to the `latest` version. As part of this overhaul of the documentation workflow, the OCaml documentation built by `odoc` is now also versioned and added to the `API` sub-directory of the Sphinx documentation (with a placeholder to prevent Sphinx from complaining). Fixes OCamlPro#693
- Loading branch information
1 parent
50c2baa
commit dbfa7a7
Showing
11 changed files
with
135 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,17 @@ name: Documentation | |
# - deploy_docs only run on the next branch when code is pushed. It retrieve | ||
# the ocaml and sphinx documentation and deploy them on the gh-pages branch | ||
|
||
on: [push, pull_request] | ||
on: | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
branches: | ||
- next | ||
- main | ||
pull_request: | ||
|
||
env: | ||
OCAML_DEFAULT_VERSION: 4.10.0 | ||
OCAML_DEFAULT_VERSION: 4.14.1 | ||
# Add OPAMYES=true to the environment, this is usefill to replace `-y` option | ||
# in any opam call | ||
OPAMYES: true | ||
|
@@ -44,62 +51,58 @@ jobs: | |
uses: ocaml/setup-ocaml@v3 | ||
with: | ||
ocaml-compiler: ${{ env.OCAML_DEFAULT_VERSION }} | ||
dune-cache: true | ||
# https://github.com/ocaml/dune/issues/7720 | ||
dune-cache: false | ||
|
||
- name: Retrieve annotated tags for dune | ||
run: git fetch --tags --force | ||
|
||
|
||
# Install dependencies if the cache is not retrieved | ||
# odoc is installed as deps with { with-doc } in opam files | ||
- name: opam install deps | ||
run: opam exec -- make deps | ||
# if: steps.cache-opam.outputs.cache-hit != 'true' | ||
|
||
# Try to upgrade installed packages and fix dependencies if needed, | ||
# when the cache is retrieved | ||
# - run: opam upgrade --fixup | ||
# if: steps.cache-opam.outputs.cache-hit == 'true' | ||
- name: Perform version substitution | ||
run: opam exec -- dune subst | ||
|
||
# Make the documentation | ||
- name: Make OCaml documentation | ||
run: opam exec -- make odoc | ||
run: opam exec -- dune build @doc | ||
|
||
# Create and upload an artifact `ocaml_doc` that contains the ocaml | ||
# documentation in html format. | ||
# This is only done if this workflow is triggered in a PR or on the | ||
# following branches : next, main | ||
- name: Upload ocaml documentation | ||
uses: actions/upload-artifact@v4 | ||
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/next' || github.ref == 'refs/heads/main' | ||
with: | ||
name: ocaml_doc | ||
path: _build/default/_doc/_html/ | ||
|
||
|
||
# On PR, or push on next/main, build the sphinx general documentation | ||
# If this build fails, the documentation workflow stops | ||
# If it succeeds, an artifact is made with the generated documentation | ||
# This artifact is used in the deploying job | ||
sphinx_docs: | ||
name: Sphinx documentation | ||
|
||
# We only run this if the ocaml documentation build is successful | ||
needs: ocaml_docs | ||
|
||
# Sphinx documentation is only builded if a PR is open or when it's | ||
# pushed on next or main | ||
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/next' || github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
version-name: ${{ steps.version-name.outputs.target }} | ||
|
||
steps: | ||
# Checkout the code of the current branch | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Determine version name | ||
id: version-name | ||
run: | | ||
echo "target=${GITHUB_REF#*/*/}" >> $GITHUB_OUTPUT | ||
# Build the sphinx documentation | ||
# and automatically print any error or warning | ||
- name: Build sphinx documentation | ||
uses: ammaraskar/sphinx-action@master | ||
with: | ||
docs-folder: "docs/sphinx_docs/" | ||
build-command: "sphinx-build -b html . _build" | ||
build-command: | | ||
sphinx-build -b html -A current_version=${{ steps.version-name.outputs.target }} . _build | ||
# Create and upload an artifact `sphinx_doc` that contains the sphinx | ||
# documentation in html format. | ||
|
@@ -109,45 +112,76 @@ jobs: | |
name: sphinx_doc | ||
path: docs/sphinx_docs/_build | ||
|
||
|
||
# For every push on main, retrieve ocaml and sphinx documentation | ||
# and publish them on gh-pages branch | ||
deploy_docs: | ||
name: Deploy documentation | ||
permissions: | ||
contents: write | ||
|
||
if: github.ref == 'refs/heads/main' | ||
if: ${{ github.event_name == 'push' }} | ||
|
||
needs: | ||
- ocaml_docs | ||
- sphinx_docs | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
# Retrieve ocaml documentation artifact | ||
- name: Download ocaml documentation | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ocaml_doc | ||
path: _build/odoc/dev | ||
|
||
# Retrieve sphinx documentation artifact | ||
- name: Download sphinx documentation | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: sphinx_doc | ||
path: _build | ||
path: _build/${{ needs.sphinx_docs.outputs.version-name }} | ||
|
||
- name: Add files to bypass nojekyll | ||
run: | | ||
touch _build/.nojekyll | ||
touch _build/odoc/.nojekyll | ||
touch _build/odoc/dev/.nojekyll | ||
- name: Download ocaml documentation | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ocaml_doc | ||
path: _build/${{ needs.sphinx_docs.outputs.version-name }}/API | ||
|
||
# Deploy files contain in _build directory on gh-pages branch | ||
- name: deploy-doc | ||
uses: JamesIves/[email protected] | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: gh-pages | ||
FOLDER: _build | ||
CLEAN: false | ||
|
||
update_versions: | ||
name: Update documentation versions | ||
permissions: | ||
contents: write | ||
|
||
needs: deploy_docs | ||
runs-on: ubuntu-latest | ||
|
||
if: ${{ github.event_name == 'push' }} | ||
|
||
steps: | ||
- name: Checkout documentation | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: gh-pages | ||
|
||
- name: Update latest version | ||
if: startsWith(github.ref, 'refs/tags/') | ||
run: | | ||
ln -nsf ${{ needs.sphinx_docs.outputs.version-name }} latest | ||
- name: Write versions to JSON file | ||
run: | | ||
rm -f versions.json | ||
echo -n '[' >versions.json | ||
PREFIX='' | ||
for version in $(ls -d */ | sort -n); do | ||
echo -n "$PREFIX" >>versions.json | ||
PREFIX=',' | ||
echo -n '{"url": "/alt-ergo/'$version'", "slug": "'${version%/}'"}' >>versions.json | ||
done | ||
echo -n ']' >>versions.json | ||
- name: Push new versions | ||
run: | | ||
git config user.name github-actions | ||
git config user.email [email protected] | ||
git add versions.json | ||
git commit -m 'Update versions.json' || exit 0 | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
|
||
# API documentation | ||
|
||
Here, you can find the different version of the Alt-Ergo's API documentation : | ||
|
||
* [dev](https://ocamlpro.github.io/alt-ergo/odoc/dev/index.html) | ||
* [2.4.0](https://ocamlpro.github.io/alt-ergo/odoc/2.4.0/index.html) | ||
This is a placeholder to resolve references. It is replaced with the OCaml | ||
documentation when publishing the documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.rst-versions .rst-other-versions .rtd-current-item { | ||
font-weight: 700; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function renderVersions(versions) { | ||
return ` | ||
<dl> | ||
<dt>Versions</dt>${ versions.active.map((version) => ` | ||
<dd ${ version.slug == versions.current.slug ? 'class="rtd-current-item"' : '' }> | ||
<a href="${ version.url }">${ version.slug }</a> | ||
</dd> | ||
`).join("\n")} | ||
</dl> | ||
`; | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
$.getJSON('/alt-ergo/versions.json', (active) => { | ||
const versions = { | ||
"active": active, | ||
"current": JSON.parse(document.getElementById('CURRENT_VERSION').innerHTML), | ||
}; | ||
|
||
document.body.insertAdjacentHTML("beforeend", ` | ||
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="Versions"> | ||
<span class="rst-current-version" data-toggle="rst-current-version"> | ||
<span class="fa fa-book"> Current version</span> | ||
${ versions.current.slug } | ||
<span class="fa fa-caret-down"></span> | ||
</span> | ||
<div class="rst-other-versions"> | ||
${renderVersions(versions)} | ||
</div> | ||
</div> | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script type="application/json" id="CURRENT_VERSION">{"slug": "{{ current_version|default("dev", true) }}"}</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters