#!/usr/bin/env bash # Print the ref a build is named after: -, plus -dirty when # the tree has uncommitted changes. Slashes and anything else awkward in a # docker tag or S3 prefix become dashes; a detached HEAD contributes no # branch. Callers may set BUILD_REF instead, so a push computes the ref once # and hands it to the build it runs. set -euo pipefail ref=$(git rev-parse --short=12 HEAD) branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" != HEAD ]; then ref="$(printf '%s' "$branch" | tr -c 'A-Za-z0-9_.-' '-')-$ref" fi if [ -n "$(git status --porcelain)" ]; then ref="$ref-dirty" echo "working tree is dirty; ref is $ref" >&2 fi printf '%s\n' "$ref"