mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-25 17:56:34 +08:00
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.
This commit is contained in:
parent
9ec1c17846
commit
3ef78d3db3
16
build.bash
16
build.bash
|
@ -4,16 +4,20 @@
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
#
|
#
|
||||||
# $ ./build.bash [output_filename]
|
# $ ./build.bash [output_filename] [git_repo]
|
||||||
#
|
#
|
||||||
# Outputs compiled program in current directory.
|
# Outputs compiled program in current directory.
|
||||||
# Default file name is 'ecaddy'.
|
# Default file name is 'ecaddy'.
|
||||||
|
# Default git repo is current directory.
|
||||||
|
# Builds always take place from current directory.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: ${output_filename:="${1:-}"}
|
: ${output_filename:="${1:-}"}
|
||||||
: ${output_filename:="ecaddy"}
|
: ${output_filename:="ecaddy"}
|
||||||
|
|
||||||
|
: ${git_repo:="${2:-}"}
|
||||||
|
|
||||||
pkg=main
|
pkg=main
|
||||||
ldflags=()
|
ldflags=()
|
||||||
|
|
||||||
|
@ -25,28 +29,28 @@ ldflags+=("-X" "\"${name}=${value}\"")
|
||||||
# Current tag, if HEAD is on a tag
|
# Current tag, if HEAD is on a tag
|
||||||
name="${pkg}.gitTag"
|
name="${pkg}.gitTag"
|
||||||
set +e
|
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
|
set -e
|
||||||
ldflags+=("-X" "\"${name}=${value}\"")
|
ldflags+=("-X" "\"${name}=${value}\"")
|
||||||
|
|
||||||
# Nearest tag on branch
|
# Nearest tag on branch
|
||||||
name="${pkg}.gitNearestTag"
|
name="${pkg}.gitNearestTag"
|
||||||
value="$(git describe --abbrev=0 --tags HEAD)"
|
value="$(git -C "${git_repo}" describe --abbrev=0 --tags HEAD)"
|
||||||
ldflags+=("-X" "\"${name}=${value}\"")
|
ldflags+=("-X" "\"${name}=${value}\"")
|
||||||
|
|
||||||
# Commit SHA
|
# Commit SHA
|
||||||
name="${pkg}.gitCommit"
|
name="${pkg}.gitCommit"
|
||||||
value="$(git rev-parse --short HEAD)"
|
value="$(git -C "${git_repo}" rev-parse --short HEAD)"
|
||||||
ldflags+=("-X" "\"${name}=${value}\"")
|
ldflags+=("-X" "\"${name}=${value}\"")
|
||||||
|
|
||||||
# Summary of uncommitted changes
|
# Summary of uncommitted changes
|
||||||
name="${pkg}.gitShortStat"
|
name="${pkg}.gitShortStat"
|
||||||
value="$(git diff-index --shortstat HEAD)"
|
value="$(git -C "${git_repo}" diff-index --shortstat HEAD)"
|
||||||
ldflags+=("-X" "\"${name}=${value}\"")
|
ldflags+=("-X" "\"${name}=${value}\"")
|
||||||
|
|
||||||
# List of modified files
|
# List of modified files
|
||||||
name="${pkg}.gitFilesModified"
|
name="${pkg}.gitFilesModified"
|
||||||
value="$(git diff-index --name-only HEAD)"
|
value="$(git -C "${git_repo}" diff-index --name-only HEAD)"
|
||||||
ldflags+=("-X" "\"${name}=${value}\"")
|
ldflags+=("-X" "\"${name}=${value}\"")
|
||||||
|
|
||||||
go build -ldflags "${ldflags[*]}" -o "${output_filename}"
|
go build -ldflags "${ldflags[*]}" -o "${output_filename}"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user