GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

image-tag 1.0KB

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