Skip to content

Commit

Permalink
Use a hopefully smarter method to get our current branch in a detache…
Browse files Browse the repository at this point in the history
…d checkout
  • Loading branch information
autarch committed Dec 4, 2020
1 parent 05ebb1e commit 7b95832
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.1.7 2020-12-04

* Fixed a bug where we could not figure out what Docker image version to
use. The method we used to use stopped working at some point, so I had to
find a new creative way to find the corresponding branch in a detached git
checkout.


## 0.1.6 2020-04-19

* Fixed a bug that caused macOS builds to fail semi-randomly (after the first
Expand Down
15 changes: 11 additions & 4 deletions templates/helpers/steps/set-image-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ jobs:
echo "Setting image version from tag - $tag"
image_version=$tag
else
# Our checkout is in a detached head state, and this is the
# only way I've found to get the branch name in that case.
refs=$( git describe --all )
branch=$( echo "$refs" | sed 's/^remotes\/origin\///' )
# Our checkout is in a detached head state, so we need to
# figure out what branch it corresponds to in the remote.
# Get all the remote branch names.
remote_heads="$( git ls-remote --heads origin )"
# Get the commit SHA for our local checkout.
local_head_ref="$( git rev-parse HEAD )"
# Find the first match in our remote heads for our local checkout.
our_head="$( echo "$remote_heads" | grep $local_head_ref | head -1 )"
# Extract branch name from the heads info.
branch=$( echo "$our_head" | cut -d / -f 3 )
echo "Setting image version from branch name - $branch"
image_version=$branch
fi
Expand Down

0 comments on commit 7b95832

Please sign in to comment.