CI/CD for cleanlab docs
In the cleanlab repository, we've configured GitHub Actions to perform the following automatically:
-
When a commit is pushed to the
masterbranch, a new version of themasterdocs will be built and deployed to thecleanlab-docsrepository. -
When a release is published, a new version of the docs with the corresponding release tag will be built and deployed as a new folder in the
cleanlab-docsrepository. Redirection to thestableversion of the docs will be changed to this newly released one, accessible via a link on the docs' site sidebar. All the older versions will remain available in thecleanlab-docsrepo, accessible by manually entering the subdirectory in the URL. -
When a user manually runs the workflow, one of the above will happen depending on the user's selection to run from a
branchortag.
If you'd like to build our docs locally or remotely yourself, or want to know more about the steps taken in the GitHub Pages workflow, read on!
Build the cleanlab docs locally
pip install -r docs/requirements.txt
-
Build the docs with
sphinx-multiversion:- If you're building from a branch (usually the
masterbranch):
sphinx-multiversion docs/source docs/build -D smv_branch_whitelist=YOUR_BRANCH_NAME -D smv_tag_whitelist=None- If you're building from a tag (usually the tag of the stable release):
sphinx-multiversion docs/source docs/build -D smv_branch_whitelist=None -D smv_tag_whitelist=YOUR_TAG_NAMENote: If you have more than one branch or tag, run the above command again changing only the
YOUR_BRANCH_NAMEorYOUR_TAG_NAMEplaceholder. - If you're building from a branch (usually the
-
[Optional] To show dynamic versioning and version warning banners:
-
Copy the
docs/_templates/versioning.jsfile to thedocs/builddirectory. -
In the copied
versioning.jsfile:-
find
placeholder_version_numberand replace it with the latest release tag name, and -
find
placeholder_commit_hashand replace it with themasterbranch commit hash.
-
-
-
[Optional] To redirect site visits from the port address to the stable version of the docs:
-
Copy the
docs/_templates/redirect-to-stable.htmlfile to thedocs/builddirectory and rename it asindex.html. -
In this
index.htmlfile, findstable_urland replace it with./YOUR_LATEST_RELEASE_TAG_NAME/index.html. Note the single period,., before the subdirectory.
-
-
[Optional] To redirect site visits from the subdirectory
PORT_ADDRESS/stableto the stable version of the docs:-
Create a folder called
stableindocs/build/stable -
Copy the
docs/_templates/redirect-to-stable.htmlfile to thedocs/builddirectory and rename it asindex.html. -
In this
index.htmlfile, findstable_urland replace it with../YOUR_LATEST_RELEASE_TAG_NAME/index.html. Note the double period,.., before the subdirectory.
-
-
The docs for each branch and/or tag can be found in the
docs/builddirectory, open any of theindex.htmlin your browser to view the docs:
docs
│
└───build
│ | index.html (redirects to stable release of the docs)
| | versioning.js (for dynamic versioning and version warning banner)
| |
│ └───YOUR_BRANCH_NAME (e.g. master)
│ │ index.html
│ │ ...
│ │
│ └───YOUR_TAG_NAME_1 (e.g. your stable release tag name)
│ │ index.html
│ │ ...
│ │
│ └───YOUR_TAG_NAME_2 (e.g. an old release tag name)
│ │ index.html
│ │ ...
│ │
│ └───stable
│ │ index.html (redirects to stable release of the docs)
│ │
│ └───...
│
└───...
│ ...
Build the cleanlab docs remotely on GitHub
-
Fork the
cleanlabrepository. -
Create a new repository named
cleanlab-docsand a new branch namedmaster. -
In the
cleanlab-docsrepo, configure GitHub Pages; under the Source section, select themasterbranch and/(root)folder. Take note of the URL where your site is published. -
Generate SSH deploy key and add them to your repos as such:
- In the
cleanlab-docsrepo, go to Settings > Deploy Keys > Add deploy key and add your public key with the Allow write access - In the
cleanlabrepo, go to Settings > Secrets > New repository secrets and add your private key namedACTIONS_DEPLOY_KEY
- In the
-
In the
cleanlabrepo, check that you have the GitHub Pages workflow under the repo's Actions tab. This should be created automatically from.github\workflows\gh-pages.yaml. This workflow can be activated by any of the 3 triggers below:- A push to the
masterbranch in thecleanlabrepo. - Publish of a new release in the
cleanlabrepo. - Manually run from the Run workflow option and select either the
masterbranch or one of the release tag.
- A push to the
-
Activate the workflow with any of the 3 triggers listed above and wait for it to complete.
-
Navigate to the URL where your GitHub Pages site is published in step 3. The default URL should have the format https://repository_owner.github.io/cleanlab-docs/.
Behind-the-scenes of the GitHub Pages workflow
We've configured GitHub Actions to run the GitHub Pages workflow (gh-pages.yaml) to build and deploy our docs' static files. Here's a breakdown of what this workflow does in the background:
Spin up and configure the CI/CD server
-
Spin up a Ubuntu server.
-
Install Pandoc, a document converter required by
nbsphinxto generate static sites from notebooks (.ipynb). -
Check-out the
cleanlabrepository. -
Setup Python and cache dependencies.
-
Install dependencies for the docs from
docs/requirements.txt.
Build the docs' static site files
- Run Sphinx with the
sphinx-multiversionwrapper to build the doc's static site files. These files will be outputted to thedocs/builddirectory.
Generate the versioning.js file used to store the latest release tag name and commit hash
-
Get the latest release tag name and insert it in the
versioning.jsfile. Theindex.htmlof each doc version will read this as a variable and display it beside the stable hyperlink. -
Insert the latest commit hash in the
versioning.jsfile. Theindex.htmlof each doc version will read this as a variable and display it beside the developer hyperlink. -
Copy the
versioning.jsfile to thedocs/buildfolder.
If the workflow is triggered by a new release, generate the redirecting HTML which redirects site visits to the stable version
-
Insert the repository owner name in the
redirect-to-stable.htmlfile AKA the redirecting HTML. -
Create a copy of the
redirect-to-stable.htmlfile todocs/buildthen insert the stable release docs'sindex.htmlfile path prefixed with. -
Create a copy of the
redirect-to-stable.htmlfile todocs/build/stablethen insert the stable release docs'sindex.htmlfile path prefixed with..
Deploy the static files
- Deploy
docs/buildfolder to thecleanlab/cleanlab-docsrepo'smaster branch.