Skip to content

Commit 75efc33

Browse files
committed
fix: improve upstream branch detection and error handling in release process
1 parent e571f3a commit 75efc33

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,33 @@ jobs:
289289
run: |
290290
set +o pipefail
291291
292-
UPSTREAM_BRANCH_NAME="$(git status -sb | head -n 1 | awk -F '\.\.\.' '{print $2}' | cut -d ' ' -f1)"
293-
printf '%s\n' "Upstream branch name: $UPSTREAM_BRANCH_NAME"
292+
git fetch --no-tags origin '+refs/heads/*:refs/remotes/origin/*' || true
294293
295-
set -o pipefail
294+
# prefer Git's symbolic upstream if present
295+
UPSTREAM_BRANCH_NAME="$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || true)"
296296
297+
# fallback when no upstream is configured (e.g. detached head / no tracking)
297298
if [ -z "$UPSTREAM_BRANCH_NAME" ]; then
298-
printf >&2 '%s\n' "::error::Unable to determine upstream branch name!"
299-
exit 1
299+
# GITHUB_REF_NAME should be set by Actions (branch name)
300+
UPSTREAM_BRANCH_NAME="origin/${GITHUB_REF_NAME:-${GITHUB_REF##*/}}"
300301
fi
301302
302-
git fetch "${UPSTREAM_BRANCH_NAME%%/*}"
303+
printf '%s\n' "Upstream branch name: $UPSTREAM_BRANCH_NAME"
304+
305+
# now fetch & compare SHAs
306+
git fetch "${UPSTREAM_BRANCH_NAME%%/*}" || true
303307
304-
if ! UPSTREAM_SHA="$(git rev-parse "$UPSTREAM_BRANCH_NAME")"; then
305-
printf >&2 '%s\n' "::error::Unable to determine upstream branch sha!"
306-
exit 1
308+
if ! UPSTREAM_SHA="$(git rev-parse "$UPSTREAM_BRANCH_NAME" 2>/dev/null)"; then
309+
printf >&2 '%s\n' "::error::Unable to determine upstream branch sha!"
310+
exit 1
307311
fi
308312
309313
HEAD_SHA="$(git rev-parse HEAD)"
310314
311315
if [ "$HEAD_SHA" != "$UPSTREAM_SHA" ]; then
312-
printf >&2 '%s\n' "[HEAD SHA] $HEAD_SHA != $UPSTREAM_SHA [UPSTREAM SHA]"
313-
printf >&2 '%s\n' "::error::Upstream has changed, aborting release..."
314-
exit 1
316+
printf >&2 '%s\n' "[HEAD SHA] $HEAD_SHA != $UPSTREAM_SHA [UPSTREAM SHA]"
317+
printf >&2 '%s\n' "::error::Upstream has changed, aborting release..."
318+
exit 1
315319
fi
316320
317321
printf '%s\n' "Verified upstream branch has not changed, continuing with release..."

0 commit comments

Comments
 (0)