Skip to content

Commit 2a65292

Browse files
authored
Merge pull request #36 from boneskull/boneskull/allow-sha1-version
fix: use git_ref verbatim in event of tag determination failure
2 parents 9dac5c4 + eb1ca24 commit 2a65292

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/find-current-git-tag.sh

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ helpFunction() {
66
echo -e "\t-p GitHub repository to clone, format: owner/repo"
77
echo -e "\t-f Reference of repository to clone"
88
exit 1
9-
}
9+
} >&2
1010

1111
while getopts "p:f:" opt; do
1212
case "$opt" in
@@ -17,17 +17,18 @@ while getopts "p:f:" opt; do
1717
done
1818

1919
if [ -z "$github_repository" ] || [ -z "$git_ref" ]; then
20-
echo "some parameters are empty"
20+
echo >&2 "some parameters are empty"
2121
helpFunction
2222
fi
2323

24-
echo "Cloning repository $github_repository at ref $git_ref"
25-
git clone --bare --single-branch --branch "$git_ref" "https://github.com/$github_repository" bare_pr_preview
26-
27-
cd bare_pr_preview || exit 1
28-
29-
action_version=$(git describe --tags --match "v*.*.*" \
30-
|| git describe --tags \
31-
|| git rev-parse HEAD)
32-
33-
echo "action_version=$action_version" >> "$GITHUB_ENV"
24+
echo >&2 "Determining preview action version"
25+
echo >&2 "Cloning repository $github_repository at ref $git_ref"
26+
if git clone --bare --single-branch --branch "$git_ref" "https://github.com/$github_repository" bare_pr_preview; then
27+
echo >&2 "Finding most specific tag matching tag $git_ref"
28+
action_version=$(git describe --tags --match "v*.*.*" || git describe --tags || git rev-parse HEAD)
29+
echo >&2 "Found $action_version"
30+
echo "action_version=$action_version" >>"$GITHUB_ENV"
31+
else
32+
echo >&2 "Clone failed; using truncated ref as action version"
33+
echo "action_version=${git_ref:0:9}" >>"$GITHUB_ENV"
34+
fi

0 commit comments

Comments
 (0)