Skip to content

Commit b282450

Browse files
author
Lisa Julia Nebel
committed
Change build system such that it can build for more branches than master and do not push to a gh-pages branch if the branch starts with 'release'
1 parent 4a22cf9 commit b282450

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

.github/workflows/python_sphinx_docs.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ jobs:
1919
uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0 # Fetch all history for all tags and branches
22+
- name: Create tmp directories for master
23+
run: |
24+
mkdir python/master-tmp
2225
- name: Get docstrings_common.json from master branch of opm-common
2326
run: |
24-
curl -L -o python/docstrings_common.json https://raw.githubusercontent.com/OPM/opm-common/master/python/docstrings_common.json
27+
curl -L -o python/master-tmp/docstrings_common.json https://raw.githubusercontent.com/OPM/opm-common/master/python/docstrings_common.json
2528
- name: Get docstrings_common.json from master branch of opm-simulators
2629
run: |
27-
curl -L -o python/docstrings_simulators.json https://raw.githubusercontent.com/OPM/opm-simulators/master/python/docstrings_simulators.json
30+
curl -L -o python/master-tmp/docstrings_simulators.json https://raw.githubusercontent.com/OPM/opm-simulators/master/python/docstrings_simulators.json
2831
- name: Get dune.module from master branch of opm-simulators, this is needed for the call to extract_opm_simulators_release in python/sphinx_docs/docs/conf.py.
2932
run: |
30-
curl -L -o dune.module https://raw.githubusercontent.com/OPM/opm-simulators/master/dune.module
33+
curl -L -o python/master-tmp/dune.module https://raw.githubusercontent.com/OPM/opm-simulators/master/dune.module
3134
- name: Set up Python
3235
uses: actions/setup-python@v5
3336
with:
@@ -44,18 +47,18 @@ jobs:
4447
mkdir gh-pages
4548
touch gh-pages/.nojekyll
4649
cd sphinx_docs
47-
# Currently we build only docs for the HEAD of the master branch
48-
# Later we can add release tags to the list to get the docs for the releases
49-
# For example: -b "master, release/2024.04/final" will build the docs for
50-
# the master branch and the release/2024.04/final tag
51-
# For the releases, we create snapshots of the docstrings_common.json and docstrings_simulators.json
52-
# and take the ones tracked by git, only for the master, we take the current ones we fetched
53-
# in steps 2 and 3 of this workflow
54-
50+
# To add a new relase to this build system:
51+
# - add the respective branch <your-new-release> on this repository, replace the slashes "/" by dashes "-"
52+
# (slashes mess with the navigation html created by sphinx-versioned)
53+
# - take a snapshot of https://raw.githubusercontent.com/OPM/opm-common/<your-new-release>/python/docstrings_common.json,
54+
# https://raw.githubusercontent.com/OPM/opm-simulators/<your-new-release>/python/docstrings_simulators.json and
55+
# https://raw.githubusercontent.com/OPM/opm-simulators/<your-new-release>/dune.module and put them
56+
# in the python folder on that branch
57+
# - add the respective branch <your-new-release> in the command below
5558
if [ "${{ github.ref_name }}" == "master" ]; then
56-
poetry run sphinx-versioned -m master -b "master" --force --git-root ../../
59+
poetry run sphinx-versioned -m master -b "master release-2025.04" --force --git-root ../../
5760
else
58-
poetry run sphinx-versioned -m master -b "master ${{ github.ref_name }}" --force --git-root ../../
61+
poetry run sphinx-versioned -m master -b "${{ github.ref_name }} master release-2025.04" --force --git-root ../../
5962
fi
6063
- name: Copy documentation to gh-pages
6164
run: |
@@ -68,7 +71,7 @@ jobs:
6871
branch: gh-pages
6972
folder: python/gh-pages
7073
- name: Deploy documentation for other branches (on forks)
71-
if: github.event_name == 'push' && github.ref != 'refs/heads/master'
74+
if: github.event_name == 'push' && github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/heads/release')
7275
uses: OPM/github-pages-deploy-action@releases/v4
7376
with:
7477
branch: gh-pages-${{ github.ref_name }}

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Files necessary to build the documentation locally, but these are tracked by other github repositories
2-
/dune.module
3-
python/docstrings_common.json
4-
python/docstrings_simulators.json
2+
python/master-tmp
53

64
# Python sphinx build
75
python/sphinx_docs/docs/_build*

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ See also the script [opmdoc-download-files](https://github.com/OPM/opm-python-do
1111

1212
## Building the documentation online on your fork
1313
- Turn on github actions at `https://github.com/<your-github-username>/opm-python-documentation/actions`
14+
- Add the docstrings_common.json and docstrings_simulators.json file you want to test to the python folder
1415
- Push any changes to a branch of your fork, this should trigger a build of the documentation, where the built documentation is pushed to the branch `gh-pages-<name-of-your-branch>`
1516
- Then you can turn on github pages for your fork at `https://github.com/<your-github-username>/opm-python-documentation/settings/pages`
1617
- Select the branch `gh-pages-<name-of-your-branch>` as the source for your github page

python/sphinx_docs/docs/conf.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
# Configuration file for the Sphinx documentation builder.
22

3+
import os
4+
import subprocess
5+
36
project = "OPM Python Documentation"
47
copyright = "2024 Equinor ASA"
58
author = "Håkon Hægland"
69

10+
def get_git_branch():
11+
try:
12+
return subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("utf-8").strip()
13+
except Exception:
14+
return "unknown"
15+
716
# Function to extract release version from dune.module file
8-
def extract_opm_simulators_release():
9-
version_file_path = '../../../dune.module'
10-
with open(version_file_path, 'r') as file:
11-
for line in file:
12-
if line.startswith('Version:'):
13-
version_string = line.split(':')[1].strip()
14-
return version_string
15-
return "unknown" # Fallback version
17+
def extract_opm_simulators_release(version_file_path):
18+
try:
19+
with open(version_file_path, 'r') as file:
20+
for line in file:
21+
if line.startswith('Version:'):
22+
version_string = line.split(':')[1].strip()
23+
return version_string
24+
except Exception:
25+
return "unknown" # Fallback version
1626

17-
release = extract_opm_simulators_release()
27+
branch = get_git_branch()
28+
print(branch)
29+
if branch == "master":
30+
prefix = "../../master-tmp"
31+
else:
32+
prefix = "../../"
33+
release = extract_opm_simulators_release(os.path.join(prefix, "dune.module"))
1834

1935
# -- General configuration ---------------------------------------------------
20-
import os
2136
import sys
2237

2338
# For regular Python packages, the path to the package is usually added to sys.path
@@ -35,9 +50,10 @@ def extract_opm_simulators_release():
3550
sys.path.insert(0, os.path.abspath("../src"))
3651
# Our sphinx extension that will use the docstrings.json file to generate documentation
3752
extensions = ["opm_python_docs.sphinx_ext_docstrings"]
53+
3854
# Path to docstrings.json
39-
opm_simulators_docstrings_path = os.path.abspath('../../docstrings_simulators.json')
40-
opm_common_docstrings_path = os.path.abspath('../../docstrings_common.json')
55+
opm_simulators_docstrings_path = os.path.abspath(os.path.join(prefix, "docstrings_simulators.json"))
56+
opm_common_docstrings_path = os.path.abspath(os.path.join(prefix, "docstrings_common.json"))
4157

4258
templates_path = ["_templates"]
4359
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

0 commit comments

Comments
 (0)