#!/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 an S3 # prefix become dashes; a detached HEAD contributes no branch. Callers may set # BUILD_REF instead. # # The same shape headquarters and arena name their artifacts with, on purpose: # what is deployed is one id per repo, and reading three of them in # releases.auto.tfvars.json should not mean learning three conventions. 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"