Skip to content

Commit bdc67a3

Browse files
authored
Merge pull request #19 from hakonhagland/fork-friendly-doc-workflow
Make documentation workflow fork-friendly with dynamic branch detection
2 parents 9456219 + 048f50e commit bdc67a3

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
@@ -53,19 +53,20 @@ jobs:
5353
mkdir gh-pages
5454
touch gh-pages/.nojekyll
5555
cd sphinx_docs
56-
# To add a new relase to this build system:
56+
# To add a new release to this build system:
5757
# - add the respective branch <your-new-release> on this repository, replace the slashes "/" by dashes "-"
5858
# (slashes mess with the navigation html created by sphinx-versioned)
5959
# - take a snapshot of https://raw.githubusercontent.com/OPM/opm-common/<your-new-release>/python/docstrings_common.json,
6060
# https://raw.githubusercontent.com/OPM/opm-simulators/<your-new-release>/python/docstrings_simulators.json and
6161
# https://raw.githubusercontent.com/OPM/opm-simulators/<your-new-release>/dune.module and put them
6262
# in the python folder on that branch
63-
# - add the respective branch <your-new-release> in the command below
64-
if [ "${{ github.ref_name }}" == "master" ]; then
65-
poetry run sphinx-versioned -m master -b "master release-2025.04" --force --git-root ../../
66-
else
67-
poetry run sphinx-versioned -m master -b "${{ github.ref_name }} master release-2025.04" --force --git-root ../../
68-
fi
63+
# Once created, the script below will automatically detect and include the new release branch
64+
65+
# Dynamically determine which branches to build documentation for
66+
# This allows the workflow to work on forks that may not have all release branches
67+
BRANCHES=$(../scripts/get_doc_branches.sh "${{ github.ref_name }}")
68+
echo "Building documentation for branches: $BRANCHES"
69+
poetry run sphinx-versioned -m master -b "$BRANCHES" --force --git-root ../../
6970
- name: Copy documentation to gh-pages
7071
run: |
7172
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)