Add GitHub Actions workflow for building docs (#1) #11
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
name: Build and Deploy Docs | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build_docs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
pip install -U sphinx sphinx-rtd-theme sphinxcontrib-napoleon psutil | |
- name: Build Documentation | |
run: | | |
sphinx-build -b html docs/source public/ | |
if [ ! -d "public" ]; then | |
echo "Error: Documentation build failed. 'public/' directory not found." | |
exit 1 | |
fi | |
- name: Deploy to GitHub Pages | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "actions@github.com" | |
git reset --hard | |
git clean -fdx | |
if git ls-remote --exit-code origin gh-pages; then | |
git fetch origin gh-pages | |
git checkout gh-pages | |
else | |
git checkout --orphan gh-pages | |
fi | |
if [ -d "public" ]; then | |
echo "public directory exists. Proceeding with deployment." | |
find . -maxdepth 1 ! -name '.git' ! -name '.' ! -name 'public' -exec rm -rf {} + | |
cp -r public/* . | |
touch .nojekyll | |
ls -la . | |
git add . | |
git commit -m "Deploy updated documentation to GitHub Pages from commit $GITHUB_SHA" | |
git push origin gh-pages --force | |
else | |
echo "Error: 'public/' directory does not exist during deployment." | |
exit 1 | |
fi | |