From 5cf38409fbb85458a53ce4cba93ec02dfddb7082 Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 11 Dec 2024 19:28:01 +0000 Subject: [PATCH] Fix GHA when opam-rt uses a diverging API --- .github/scripts/main/main.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/scripts/main/main.sh b/.github/scripts/main/main.sh index f91a66d6195..0240fcab9df 100644 --- a/.github/scripts/main/main.sh +++ b/.github/scripts/main/main.sh @@ -84,16 +84,18 @@ if [ "$OPAM_TEST" = "1" ]; then fi cd $CACHE/opam-rt git fetch origin - if git ls-remote --exit-code origin $BRANCH ; then - if git branch | grep -q $BRANCH; then - git checkout $BRANCH - git reset --hard origin/$BRANCH - else - git checkout -b $BRANCH origin/$BRANCH - fi + if git ls-remote --exit-code origin "$BRANCH"; then + OPAM_RT_BRANCH=$BRANCH + elif [ "$GITHUB_EVENT_NAME" = pull_request ] && git ls-remote --exit-code origin "$GITHUB_BASE_REF"; then + OPAM_RT_BRANCH=$GITHUB_BASE_REF + else + OPAM_RT_BRANCH=master + fi + if git branch | grep -q "$OPAM_RT_BRANCH"; then + git checkout "$OPAM_RT_BRANCH" + git reset --hard "origin/$OPAM_RT_BRANCH" else - git checkout master - git reset --hard origin/master + git checkout -b "$OPAM_RT_BRANCH" "origin/$OPAM_RT_BRANCH" fi test -d _opam || opam switch create . --no-install --formula '"ocaml-system"'