#!/bin/bash # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -o errexit set -o nounset set -o pipefail topdir=$(dirname "$0")/.. cd "${topdir}" # TODO: when we start making tags, switch to git describe? if git_commit=$(git rev-parse --short "HEAD^{commit}" 2>/dev/null); then # Remove any invalid characters that might confuse "sed". git_commit=${git_commit//[^a-f0-9]/} # Check if the tree is dirty. if ! dirty_tree=$(git status --porcelain) || [[ -n "${dirty_tree}" ]]; then git_commit="${git_commit}-dirty" fi else git_commit="(none)" echo "WARNING: unable to find git commit, falling back to commitFromGit = \`${git_commit}\`" >&2 fi # TODO: Instead of using an autogenerated file, we could pass this variable # to the source through Go's -X ldflag. sed "s/@@GIT_COMMIT@@/${git_commit}/g" \ pkg/version/template.go.tmpl >pkg/version/autogenerated.go