Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 7b95832

Browse files
committed
Use a hopefully smarter method to get our current branch in a detached checkout
1 parent 05ebb1e commit 7b95832

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Changes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.1.7 2020-12-04
2+
3+
* Fixed a bug where we could not figure out what Docker image version to
4+
use. The method we used to use stopped working at some point, so I had to
5+
find a new creative way to find the corresponding branch in a detached git
6+
checkout.
7+
8+
19
## 0.1.6 2020-04-19
210

311
* Fixed a bug that caused macOS builds to fail semi-randomly (after the first

templates/helpers/steps/set-image-version.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ jobs:
2020
echo "Setting image version from tag - $tag"
2121
image_version=$tag
2222
else
23-
# Our checkout is in a detached head state, and this is the
24-
# only way I've found to get the branch name in that case.
25-
refs=$( git describe --all )
26-
branch=$( echo "$refs" | sed 's/^remotes\/origin\///' )
23+
# Our checkout is in a detached head state, so we need to
24+
# figure out what branch it corresponds to in the remote.
25+
26+
# Get all the remote branch names.
27+
remote_heads="$( git ls-remote --heads origin )"
28+
# Get the commit SHA for our local checkout.
29+
local_head_ref="$( git rev-parse HEAD )"
30+
# Find the first match in our remote heads for our local checkout.
31+
our_head="$( echo "$remote_heads" | grep $local_head_ref | head -1 )"
32+
# Extract branch name from the heads info.
33+
branch=$( echo "$our_head" | cut -d / -f 3 )
2734
echo "Setting image version from branch name - $branch"
2835
image_version=$branch
2936
fi

0 commit comments

Comments
 (0)