Skip to content

Commit 048f50e

Browse files
committed
Make documentation workflow fork-friendly with dynamic branch detection
This commit makes the Sphinx documentation build workflow work seamlessly on forks that may not have all release branches available. Changes: 1. Added python/scripts/get_doc_branches.sh script that dynamically detects available branches (current, master, release-*) in the repository 2. Updated python_sphinx_docs.yml to use the script instead of hardcoded branch lists, removing the need for manual edits when testing on forks 3. Clarified comment to distinguish between manual release branch creation and automatic branch detection Benefits: - Workflow automatically adapts to available branches in any fork - No manual edits needed for testing in development forks - Gracefully handles missing release branches - Automatically includes new release branches as they're added The script checks for remote branches to ensure it works properly with both the main repository (which has all branches) and forks (which may only have a subset).
1 parent 38fb045 commit 048f50e

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

.github/workflows/python_sphinx_docs.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,20 @@ jobs:
4747
mkdir gh-pages
4848
touch gh-pages/.nojekyll
4949
cd sphinx_docs
50-
# To add a new relase to this build system:
50+
# To add a new release to this build system:
5151
# - add the respective branch <your-new-release> on this repository, replace the slashes "/" by dashes "-"
5252
# (slashes mess with the navigation html created by sphinx-versioned)
5353
# - take a snapshot of https://raw.githubusercontent.com/OPM/opm-common/<your-new-release>/python/docstrings_common.json,
5454
# https://raw.githubusercontent.com/OPM/opm-simulators/<your-new-release>/python/docstrings_simulators.json and
5555
# https://raw.githubusercontent.com/OPM/opm-simulators/<your-new-release>/dune.module and put them
5656
# in the python folder on that branch
57-
# - add the respective branch <your-new-release> in the command below
58-
if [ "${{ github.ref_name }}" == "master" ]; then
59-
poetry run sphinx-versioned -m master -b "master release-2025.04" --force --git-root ../../
60-
else
61-
poetry run sphinx-versioned -m master -b "${{ github.ref_name }} master release-2025.04" --force --git-root ../../
62-
fi
57+
# Once created, the script below will automatically detect and include the new release branch
58+
59+
# Dynamically determine which branches to build documentation for
60+
# This allows the workflow to work on forks that may not have all release branches
61+
BRANCHES=$(../scripts/get_doc_branches.sh "${{ github.ref_name }}")
62+
echo "Building documentation for branches: $BRANCHES"
63+
poetry run sphinx-versioned -m master -b "$BRANCHES" --force --git-root ../../
6364
- name: Copy documentation to gh-pages
6465
run: |
6566
cp -r python/sphinx_docs/docs/_build/* python/gh-pages

python/scripts/get_doc_branches.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# Script to dynamically determine which branches to build documentation for
3+
# This makes the workflow work on forks that may not have all release branches
4+
#
5+
# Usage: get_doc_branches.sh <current_branch_name>
6+
#
7+
# Returns: Space-separated list of branches for sphinx-versioned
8+
9+
set -e
10+
11+
CURRENT_BRANCH="$1"
12+
13+
if [ -z "$CURRENT_BRANCH" ]; then
14+
echo "Error: Current branch name must be provided as first argument" >&2
15+
exit 1
16+
fi
17+
18+
# Initialize branch list with current branch
19+
BRANCHES="$CURRENT_BRANCH"
20+
21+
# Add master if it exists and isn't already in the list
22+
if git ls-remote --heads origin master >/dev/null 2>&1; then
23+
if [ "$CURRENT_BRANCH" != "master" ]; then
24+
BRANCHES="$BRANCHES master"
25+
fi
26+
fi
27+
28+
# Add all release branches that exist
29+
# Note: We check for remote branches to handle forks properly
30+
for branch in $(git ls-remote --heads origin | grep -E 'refs/heads/release-' | sed 's/.*refs\/heads\///'); do
31+
# Skip if already in list (shouldn't happen with release branches, but be safe)
32+
if [[ ! " $BRANCHES " =~ " $branch " ]]; then
33+
BRANCHES="$BRANCHES $branch"
34+
fi
35+
done
36+
37+
# Output the branch list
38+
echo "$BRANCHES"

0 commit comments

Comments
 (0)