forked from hmrc/address-lookup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateVersionFile.sh
executable file
·70 lines (54 loc) · 2.09 KB
/
generateVersionFile.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh -e
# Creates the project_version.properties and/or project_version.txt to provide traceability from built artefacts back to source code.
if [ "$1" = "-f" ]; then
FORCE=y
shift
else
FORCE=
fi
if [ -z "$3" ]; then
echo "Usage: $0 rootProjectDir projectDir filename-base [main|gen]"
echo "Example: $0 . dev/agent agent"
exit 1
fi
rootProjectDir=$1
projectDir=$2
filename=$3
point=${4:-main}
mainDir="${projectDir}/src/$point"
resourcesDir="${mainDir}/resources"
webappDir="${projectDir}/src/$point/webapp"
resourcesFile="${resourcesDir}/${filename}_version.properties"
webappFile="${webappDir}/${filename}_version.txt"
[ -n "$FORCE" ] && rm -f $resourcesFile $webappFile
[ ! -d $resourcesDir -o -f $resourcesFile ] && [ ! -d $webappDir -o -f $webappFile ] && exit 0 # no further action needed
echo "Writing $resourcesFile $webappFile ..."
appendVersionTextFile()
{
mkdir -p $resourcesDir
echo "$1" >> $resourcesFile
if [ -d $webappDir ]; then
echo "$1" >> $webappFile
fi
}
appendVersionTextFile "version.buildDir = ${projectDir}"
appendVersionTextFile "version.buildTag = ${BUILD_TAG:-DEVELOPER BUILD}"
appendVersionTextFile "version.buildUrl = ${BUILD_URL}"
gitVersionTxt="${rootProjectDir}/gitVersion.txt"
if [ -f $gitVersionTxt ]; then
for line in $(cat $gitVersionTxt); do
appendVersionTextFile "version.$line"
done
elif [ -d ${rootProjectDir}/.git -o -d ${rootProjectDir}/../.git ]; then
appendVersionTextFile "version.commit = $(git rev-parse HEAD | sed 's/:/_/g')"
appendVersionTextFile "version.branch = $(git remote)/$(git rev-parse --abbrev-ref HEAD)"
appendVersionTextFile "version.timestamp = $(date --iso-8601=seconds)"
elif [ -d ${rootProjectDir}/.hg -o ${rootProjectDir}/../.hg ]; then
appendVersionTextFile "version.commit = $(hg tip --template '{node}\n')"
appendVersionTextFile "version.branch = origin/$(hg bookmark | fgrep '*' | sed 's/^\s*\*\s*//' | sed 's/\s.*$//')"
appendVersionTextFile "version.timestamp = $(date --iso-8601=seconds)"
else
pwd
echo "Failed: not a versioned workspace."
exit 1
fi