From 217d12b15de8a01b3e737e89fb972f66b99294de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 13 Feb 2026 12:52:09 +0100 Subject: [PATCH 1/2] Fix gh-pages deploy race condition Replace pull_request_target with pull_request to prevent duplicate workflow runs when merging PRs to master. Previously, merging a PR fired both 'push' and 'pull_request_target' simultaneously, causing two runs to race for the gh-pages force-push. The loser failed with a "cannot lock ref" error. With pull_request, only the push event deploys on merge, while PRs still get build-tested. --- .github/workflows/python_sphinx_docs.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python_sphinx_docs.yml b/.github/workflows/python_sphinx_docs.yml index 46dc786..a76b7b4 100644 --- a/.github/workflows/python_sphinx_docs.yml +++ b/.github/workflows/python_sphinx_docs.yml @@ -4,9 +4,15 @@ on: push: branches: - '**' - pull_request_target: - types: closed - branches: master + # Use pull_request (not pull_request_target) to build-test docs on PRs targeting master. + # When a PR is merged, only the 'push' event triggers deployment to gh-pages. + # Using pull_request_target here previously caused a race condition: merging a PR fired + # both 'push' and 'pull_request_target' simultaneously, producing two concurrent runs + # that both tried to force-push to gh-pages. The loser would fail with: + # "cannot lock ref 'refs/heads/gh-pages': is at but expected " + # See: https://github.com/OPM/opm-python-documentation/actions/runs/21938360885 + pull_request: + branches: [master] repository_dispatch: types: [docstrings_common_updated, docstrings_simulators_updated] permissions: From a248ec7ed70d2d1b0a7e0a6da784345cae522ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 13 Feb 2026 13:02:42 +0100 Subject: [PATCH 2/2] Fix branch name for pull_request events For pull_request events, github.ref_name resolves to the merge ref (e.g. "21/merge") instead of a real branch name. This caused sphinx-versioned to fail with: error: pathspec '21/merge' did not match any file(s) Use github.base_ref (the PR target branch) for pull_request events, falling back to github.ref_name for push events. --- .github/workflows/python_sphinx_docs.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python_sphinx_docs.yml b/.github/workflows/python_sphinx_docs.yml index a76b7b4..306e82b 100644 --- a/.github/workflows/python_sphinx_docs.yml +++ b/.github/workflows/python_sphinx_docs.yml @@ -70,7 +70,11 @@ jobs: # Dynamically determine which branches to build documentation for # This allows the workflow to work on forks that may not have all release branches - BRANCHES=$(../scripts/get_doc_branches.sh "${{ github.ref_name }}") + # For pull_request events, github.ref_name is the merge ref (e.g. "21/merge"), + # not a real branch. Use github.base_ref (the PR target branch, e.g. "master") + # instead, falling back to github.ref_name for push/dispatch events where + # github.base_ref is empty. + BRANCHES=$(../scripts/get_doc_branches.sh "${{ github.base_ref || github.ref_name }}") echo "Building documentation for branches: $BRANCHES" poetry run sphinx-versioned -m master -b "$BRANCHES" --force --git-root ../../ - name: Copy documentation to gh-pages