Skip to content

Commit 9c9ad94

Browse files
committed
Detect action version in internal PR
1 parent 40162a7 commit 9c9ad94

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

lib/find-current-git-tag.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
help() {
46
echo ""
57
echo "Usage: $0 -p github_repository -f git_ref"
@@ -21,12 +23,26 @@ if [ -z "$github_repository" ] || [ -z "$git_ref" ]; then
2123
help
2224
fi
2325

24-
echo >&2 "Determining Git tag for $github_repository/$git_ref"
25-
26-
echo >&2 "Cloning repository $github_repository at ref $git_ref"
27-
git clone --bare "https://github.com/$github_repository" bare_pr_preview
28-
29-
cd bare_pr_preview || exit 1
26+
echo >&2 "Determining Git tag for $github_repository@$git_ref"
27+
28+
case $git_ref in
29+
refs/pull/*)
30+
# If the ref is a github virtual pull request merge, this is not a valid git ref
31+
# Although this script is meant to be portable, action_ref being a PR merge can only happen for PRs to the action repo - in which case it is already checked out
32+
echo >&2 "Assuming that's *this* repository..."
33+
if eval "$(git rev-parse --is-shallow-repository)"; then
34+
git fetch --prune --unshallow
35+
fi
36+
git_ref=HEAD
37+
;;
38+
*)
39+
echo >&2 "Cloning repository $github_repository"
40+
clone_dir="$(mktemp -d)"
41+
trap 'rm -rf "$clone_dir"' EXIT
42+
git clone --bare "https://github.com/$github_repository" "$clone_dir"
43+
cd "$clone_dir"
44+
;;
45+
esac
3046

3147
action_version=$(git describe --tags --match "v*.*.*" "$git_ref" || git describe --tags "$git_ref" || git rev-parse HEAD)
3248

0 commit comments

Comments
 (0)