From 3ef78d3db3aac364d9071afd49b2cd01863beaf4 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 5 Apr 2016 18:57:50 -0600 Subject: [PATCH] Allow git repo as argument to build script This will help build server perform builds with copy of repo in a folder outside the original git repo folder. Also testing signed commits on GitHub. --- build.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build.bash b/build.bash index 6aa49ad7..7c3bce07 100755 --- a/build.bash +++ b/build.bash @@ -4,16 +4,20 @@ # # Usage: # -# $ ./build.bash [output_filename] +# $ ./build.bash [output_filename] [git_repo] # # Outputs compiled program in current directory. # Default file name is 'ecaddy'. +# Default git repo is current directory. +# Builds always take place from current directory. set -euo pipefail : ${output_filename:="${1:-}"} : ${output_filename:="ecaddy"} +: ${git_repo:="${2:-}"} + pkg=main ldflags=() @@ -25,28 +29,28 @@ ldflags+=("-X" "\"${name}=${value}\"") # Current tag, if HEAD is on a tag name="${pkg}.gitTag" set +e -value="$(git describe --exact-match HEAD 2>/dev/null)" +value="$(git -C "${git_repo}" describe --exact-match HEAD 2>/dev/null)" set -e ldflags+=("-X" "\"${name}=${value}\"") # Nearest tag on branch name="${pkg}.gitNearestTag" -value="$(git describe --abbrev=0 --tags HEAD)" +value="$(git -C "${git_repo}" describe --abbrev=0 --tags HEAD)" ldflags+=("-X" "\"${name}=${value}\"") # Commit SHA name="${pkg}.gitCommit" -value="$(git rev-parse --short HEAD)" +value="$(git -C "${git_repo}" rev-parse --short HEAD)" ldflags+=("-X" "\"${name}=${value}\"") # Summary of uncommitted changes name="${pkg}.gitShortStat" -value="$(git diff-index --shortstat HEAD)" +value="$(git -C "${git_repo}" diff-index --shortstat HEAD)" ldflags+=("-X" "\"${name}=${value}\"") # List of modified files name="${pkg}.gitFilesModified" -value="$(git diff-index --name-only HEAD)" +value="$(git -C "${git_repo}" diff-index --name-only HEAD)" ldflags+=("-X" "\"${name}=${value}\"") go build -ldflags "${ldflags[*]}" -o "${output_filename}"