Skip to content

Commit 6f41ffc

Browse files
committed
Updated branch detection
1 parent 9cf2767 commit 6f41ffc

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ If you submitted a detailed HTML report of the coverage to the action, replace t
3434
- `coverage` (required): Coverage percentage (for example `83` or `83%`).
3535
- `report` (optional): Path to an HTML report file to publish as `report.html`.
3636
- `branch` (optional): Source branch override. Recommended for tag-triggered workflows where multiple branches may contain the same tag commit.
37+
Also recommended for very large or restricted repos to avoid scanning all remote branches during tag-triggered branch resolution.
3738

3839
## Examples
3940

action.yml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,27 @@ runs:
8989
local b="$1"
9090
git check-ref-format --branch "$b" >/dev/null 2>&1
9191
}
92+
ensure_tag_resolution_refs() {
93+
# Only tag-triggered auto-mapping needs full remote-branch refs.
94+
if git rev-parse --is-shallow-repository >/dev/null 2>&1 && [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then
95+
# Fully unshallow if possible so --contains works reliably.
96+
git fetch --prune --tags --unshallow origin || git fetch --prune --tags --depth=1000 origin
97+
else
98+
git fetch --prune --tags origin
99+
fi
100+
if ! git fetch origin +refs/heads/*:refs/remotes/origin/* --prune; then
101+
echo "Failed to fetch remote branches needed for tag-triggered branch resolution." >&2
102+
echo "Set input 'branch' to the intended source branch." >&2
103+
exit 1
104+
fi
105+
}
92106
93-
# --- Ensure we have enough history + refs ---
107+
# --- Ensure 'origin' exists ---
94108
# Ensure 'origin' exists but never rewrite an existing remote URL/config.
95109
if ! git remote get-url origin >/dev/null 2>&1; then
96110
git remote add origin "${GITHUB_SERVER_URL:-https://github.com}/${GITHUB_REPOSITORY}.git"
97111
fi
98112
99-
if git rev-parse --is-shallow-repository >/dev/null 2>&1 && [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then
100-
# Fully unshallow if possible so --contains works reliably
101-
git fetch --prune --tags --unshallow origin || git fetch --prune --tags --depth=1000 origin
102-
else
103-
git fetch --prune --tags origin
104-
fi
105-
# Fetch all remote heads so we can query them locally
106-
git fetch origin +refs/heads/*:refs/remotes/origin/* --prune
107-
108113
# Explicit override: useful for tag workflows where multiple branches may contain the tag.
109114
BRANCH="${INPUT_BRANCH:-}"
110115
BRANCH="$(echo "$BRANCH" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
@@ -113,7 +118,7 @@ runs:
113118
echo "Invalid explicit branch input: '$BRANCH'" >&2
114119
exit 1
115120
fi
116-
if ! git show-ref --verify --quiet "refs/remotes/origin/$BRANCH"; then
121+
if ! git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
117122
echo "Explicit branch '$BRANCH' was not found on origin." >&2
118123
exit 1
119124
fi
@@ -133,6 +138,7 @@ runs:
133138
134139
# --- Tag path: map tag -> containing branch ---
135140
if [[ -z "$BRANCH" ]] && { [[ "${GITHUB_REF_TYPE:-}" == "tag" ]] || [[ "${GITHUB_REF:-}" == refs/tags/* ]]; }; then
141+
ensure_tag_resolution_refs
136142
TAG="${GITHUB_REF_NAME:-${GITHUB_REF#refs/tags/}}"
137143
TAG_REF="tags/$TAG"
138144
TAG_SHA="$(git rev-list -n1 "$TAG_REF")"

0 commit comments

Comments
 (0)