Skip to content

Commit e265b52

Browse files
authored
Merge pull request #21 from hakonhagland/fix_race_cond
Fix gh-pages deploy race condition
2 parents bdc67a3 + a248ec7 commit e265b52

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

.github/workflows/python_sphinx_docs.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ on:
44
push:
55
branches:
66
- '**'
7-
pull_request_target:
8-
types: closed
9-
branches: master
7+
# Use pull_request (not pull_request_target) to build-test docs on PRs targeting master.
8+
# When a PR is merged, only the 'push' event triggers deployment to gh-pages.
9+
# Using pull_request_target here previously caused a race condition: merging a PR fired
10+
# both 'push' and 'pull_request_target' simultaneously, producing two concurrent runs
11+
# that both tried to force-push to gh-pages. The loser would fail with:
12+
# "cannot lock ref 'refs/heads/gh-pages': is at <new-sha> but expected <old-sha>"
13+
# See: https://github.com/OPM/opm-python-documentation/actions/runs/21938360885
14+
pull_request:
15+
branches: [master]
1016
repository_dispatch:
1117
types: [docstrings_common_updated, docstrings_simulators_updated]
1218
permissions:
@@ -64,7 +70,11 @@ jobs:
6470
6571
# Dynamically determine which branches to build documentation for
6672
# 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 }}")
73+
# For pull_request events, github.ref_name is the merge ref (e.g. "21/merge"),
74+
# not a real branch. Use github.base_ref (the PR target branch, e.g. "master")
75+
# instead, falling back to github.ref_name for push/dispatch events where
76+
# github.base_ref is empty.
77+
BRANCHES=$(../scripts/get_doc_branches.sh "${{ github.base_ref || github.ref_name }}")
6878
echo "Building documentation for branches: $BRANCHES"
6979
poetry run sphinx-versioned -m master -b "$BRANCHES" --force --git-root ../../
7080
- name: Copy documentation to gh-pages

0 commit comments

Comments
 (0)