Deploy documentation on own fork on separate branch #57
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 Python Sphinx Docs and push to gh-pages | |
on: | |
push: | |
branches: | |
- '**' | |
paths: | |
- 'python/**' | |
- '.github/workflows/python_sphinx_docs.yml' | |
pull_request_target: | |
types: closed | |
branches: master | |
paths: | |
- 'python/**' | |
- '.github/workflows/python_sphinx_docs.yml' | |
repository_dispatch: | |
types: [docstrings_common_updated] | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
continue-on-error: true | |
with: | |
fetch-depth: 0 # Fetch all history for all tags and branches | |
- name: Get docstrings_common.json from opm-common | |
continue-on-error: true | |
run: | | |
curl -L -o python/docstrings_common.json https://raw.githubusercontent.com/${{ github.repository_owner }}/opm-common/master/python/docstrings_common.json | |
- name: Set up Python | |
continue-on-error: true | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Install poetry | |
continue-on-error: true | |
uses: OPM/actions-poetry@master | |
- name: Install python dependencies | |
continue-on-error: true | |
run: | | |
cd python/sphinx_docs | |
poetry install | |
- name: Build documentation | |
continue-on-error: true | |
run: | | |
cd python | |
mkdir gh-pages | |
touch gh-pages/.nojekyll | |
cd sphinx_docs | |
# Currently we build only docs for the HEAD of the master branch | |
# Later we can add release tags to the list to get the docs for the releases | |
# For example: -b "master, release/2024.04/final" will build the docs for | |
# the master branch and the release/2024.04/final tag | |
# If this is a build for master, then the build the documentation for the master branch | |
if [ "${{ github.ref }}" == "refs/heads/master" ]; then | |
branch=master | |
else | |
branch=${{ github.ref }} | |
fi | |
poetry run sphinx-versioned -m master -b "${branch}" --force --git-root ../../ | |
- name: Copy documentation to gh-pages | |
continue-on-error: true | |
run: | | |
cp -r python/sphinx_docs/docs/_build/* python/gh-pages/ | |
- name: Deploy documentation for PR merge to master or push to master | |
if: github.ref == 'refs/heads/master' | |
continue-on-error: true | |
uses: OPM/github-pages-deploy-action@dev | |
with: | |
branch: gh-pages | |
folder: python/gh-pages | |
- name: Deploy documentation for PRs and other branches | |
if: github.event_name == 'push' && github.ref != 'refs/heads/master' | |
continue-on-error: true | |
uses: OPM/github-pages-deploy-action@dev | |
with: | |
branch: gh-pages | |
folder: python/gh-pages-${{ github.ref }} |