-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcs.info
More file actions
47 lines (39 loc) · 1.49 KB
/
vcs.info
File metadata and controls
47 lines (39 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- shell-script -*-
#
# dot this file to populate the Git... environment variables.
#
# This only works if you are in a git repository
# getGitVars will set the values of the Git... environment variables
function getGitVars() {
export GitAuthor=$(git log -1 --format=tformat:'%an')
export GitCommit=$(git log -1 --format=tformat:'%H')
export GitDate=$(git log -1 --date=iso --format=tformat:'%cd')
export GitTag=$(git tag -l --points-at $GitCommit)
}
getGitVars
# showGitVars prints the current values of the environment variables
function showGitVars() {
printf " Tag: %s\n" "$GitTag"
printf "Commit: %s\n" "$GitCommit"
printf "Author: %s\n" "$GitAuthor"
printf " Date: %s\n" "$GitDate"
}
# goBuildTags prints out a string suitable to be used as the value to a
# -ldflags parameter as can be given to go build or go install
function goBuildTags() {
pkg=$1
if [ -z "$pkg" ]
then
echo "no package name has been given" 1>&2
return
fi
now="$(date --utc '+%Y-%m-%d %T +0000')"
buildUser="$(id --real --user --name)"
ldfTag=$(printf "-X '$pkg.tag=%s'" "$GitTag")
ldfCommit=$(printf "-X '$pkg.commit=%s'" "$GitCommit")
ldfAuthor=$(printf "-X '$pkg.author=%s'" "$GitAuthor")
ldfDate=$(printf "-X '$pkg.date=%s'" "$GitDate")
ldfBuildDate=$(printf "-X '$pkg.buildDate=%s'" "$now")
ldfBuildUser=$(printf "-X '$pkg.buildUser=%s'" "$buildUser")
printf "%s\n" "$ldfTag $ldfCommit $ldfAuthor $ldfDate $ldfBuildDate $ldfBuildUser"
}