forked from fluxcd/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage-tag
executable file
·39 lines (32 loc) · 1.05 KB
/
image-tag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
OUTPUT=--quiet
if [ "${1:-}" = '--show-diff' ]; then
OUTPUT=
fi
# If a tagged version, just print that tag
HEAD_TAGS=$(git tag --points-at HEAD)
if [ -n "${HEAD_TAGS}" ] ; then
# remove helm- prefix from helm-op release name
if echo "${HEAD_TAGS}" | grep -Eq "helm-[0-9]+(\.[0-9]+)*(-[a-z]+)?$"; then
HEAD_TAGS=$(echo "$HEAD_TAGS" | cut -c 6-)
fi
echo ${HEAD_TAGS}
exit 0
fi
WORKING_SUFFIX=$(if ! git diff --exit-code ${OUTPUT} HEAD >&2; \
then echo "-wip"; \
else echo ""; \
fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
# replace spaces with dash
BRANCH_PREFIX=${BRANCH_PREFIX// /-}
# next, replace slashes with dash
BRANCH_PREFIX=${BRANCH_PREFIX//[\/\\]/-}
# now, clean out anything that's not alphanumeric or an dash
BRANCH_PREFIX=${BRANCH_PREFIX//[^a-zA-Z0-9-]/}
# finally, lowercase with TR
BRANCH_PREFIX=`echo -n $BRANCH_PREFIX | tr A-Z a-z`
echo "$BRANCH_PREFIX-$(git rev-parse --short HEAD)$WORKING_SUFFIX"