mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-25 17:56:34 +08:00
da08c94a8c
Without -ldflags, the verison information needs to be updated manually, which is never done between releases, so development builds appear indiscernable from stable builds using `caddy -version`. This is part of a set of changes intended to relieve the burden of always updating version information manually and distributing binaries that look stable but actually may not be. A stable build is defined as one which is produced at a git tag with a clean working directory (no uncommitted changes). A dev build is anything else. With this build script, `caddy -version` will now reveal whether it is a development build and, if so, the base version, the latest commit, the date and time of build, and the names of files with changes as well as how many changes were made. The output of `caddy -version` for stable builds remains the same.
56 lines
1.0 KiB
Bash
Executable File
56 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Caddy build script. Automates proper versioning.
|
|
#
|
|
# Usage:
|
|
#
|
|
# $ ./build.bash [output_filename]
|
|
#
|
|
# Outputs compiled program in current directory.
|
|
# Default file name is 'ecaddy'.
|
|
#
|
|
set -e
|
|
|
|
output="$1"
|
|
if [ -z "$output" ]; then
|
|
output="ecaddy"
|
|
fi
|
|
|
|
pkg=main
|
|
|
|
# Timestamp of build
|
|
builddate_id=$pkg.buildDate
|
|
builddate=`date -u`
|
|
|
|
# Current tag, if HEAD is on a tag
|
|
tag_id=$pkg.gitTag
|
|
set +e
|
|
tag=`git describe --exact-match HEAD 2> /dev/null`
|
|
set -e
|
|
|
|
# Nearest tag on branch
|
|
lasttag_id=$pkg.gitNearestTag
|
|
lasttag=`git describe --abbrev=0 --tags HEAD`
|
|
|
|
# Commit SHA
|
|
commit_id=$pkg.gitCommit
|
|
commit=`git rev-parse --short HEAD`
|
|
|
|
# Summary of uncommited changes
|
|
shortstat_id=$pkg.gitShortStat
|
|
shortstat=`git diff-index --shortstat HEAD`
|
|
|
|
# List of modified files
|
|
files_id=$pkg.gitFilesModified
|
|
files=`git diff-index --name-only HEAD`
|
|
|
|
|
|
go build -ldflags "
|
|
-X \"$builddate_id=$builddate\"
|
|
-X \"$tag_id=$tag\"
|
|
-X \"$lasttag_id=$lasttag\"
|
|
-X \"$commit_id=$commit\"
|
|
-X \"$shortstat_id=$shortstat\"
|
|
-X \"$files_id=$files\"
|
|
" -o "$output"
|