Skip to content

Commit 7b70402

Browse files
committed
fix(monorepo): resolve branch refs to origin/ for nx affected
After checkout, branch names like 'develop' only exist as remote refs (origin/develop). Add a resolve_ref helper that falls back to origin/<ref> when the ref is not directly resolvable locally.
1 parent 15c67db commit 7b70402

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

.github/workflows/deploy-npm.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,25 @@ jobs:
7878
INPUT_BASE_VERSION: ${{ inputs.base_version }}
7979
INPUT_HEAD_VERSION: ${{ inputs.head_version }}
8080
run: |
81+
# Resolve a ref to a locally available git reference.
82+
# Branch names from inputs (e.g. "develop") only exist as remote refs
83+
# (origin/develop) after checkout, so we need to resolve them.
84+
resolve_ref() {
85+
local ref="$1"
86+
# Already resolvable locally (tag, SHA, HEAD~N, etc.)
87+
if git rev-parse --verify "$ref" >/dev/null 2>&1; then
88+
echo "$ref"
89+
# Try as a remote branch
90+
elif git rev-parse --verify "origin/$ref" >/dev/null 2>&1; then
91+
echo "origin/$ref"
92+
else
93+
echo "$ref"
94+
fi
95+
}
96+
8197
if [ -n "$INPUT_BASE_VERSION" ] && [ -n "$INPUT_HEAD_VERSION" ]; then
82-
BASE_VERSION="$INPUT_BASE_VERSION"
83-
HEAD_VERSION="$INPUT_HEAD_VERSION"
98+
BASE_VERSION=$(resolve_ref "$INPUT_BASE_VERSION")
99+
HEAD_VERSION=$(resolve_ref "$INPUT_HEAD_VERSION")
84100
else
85101
TAGS=$(git tag -l "v3*" --sort=-version:refname)
86102
HEAD_VERSION=$(echo "$TAGS" | head -n 1)

0 commit comments

Comments
 (0)