forked from huksley/serverless-java-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmk-git-json
More file actions
executable file
·37 lines (33 loc) · 1.45 KB
/
mk-git-json
File metadata and controls
executable file
·37 lines (33 loc) · 1.45 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
#!/bin/bash
#
# Creates git.json with repository and deployment information
# NOTE: CodePipeline strips .git directory, so only git information available is commit.id from CODEBUILD_RESOLVED_SOURCE_VERSION env var
#
DST=${1:-src/main/resources}
if [ -d .git ]; then
git log -1 --pretty=format:'{%n"commit.id": "%H",%n"commit.id.abbrev": "%h",%n"commit.user.name": "%an",%n"commit.user.email": "%ae",%n"commit.info":"%D",%n"commit.message": "%s",%n"commit.date": "%ai"%n}%n' | sed -E -e "s/^\* //g;s/^\| //g" > $DST/git.json
else
if [ "$CODEBUILD_RESOLVED_SOURCE_VERSION" != "" ]; then
echo "{ \"commit.id\": \"$CODEBUILD_RESOLVED_SOURCE_VERSION\" }" > $DST/git.json
else
echo "{ \"empty\": true }" > $DST/git.json
fi
fi
NOW=`date +%Y-%m-%dT%H:%M:%S%z`
HST=`hostname -f`
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
platform='freebsd'
fi
if [[ "$platform" == "unknown" ]]; then
# Probably MacOS X
sed -i bak -E -e "s/^{/{ \"build.time\": \"$NOW\", \"build.user\": \"$USER\", \"build.host\": \"$HST\", /g" $DST/git.json
elif [[ "$platform" == "freebsd" ]]; then
# Validate proper -i call
sed -i -E -e "s/^{/{ \"build.time\": \"$NOW\", \"build.user\": \"$USER\", \"build.host\": \"$HST\", /g" $DST/git.json
else
sed -i -E -e "s/^\{/\{ \"build.time\": \"$NOW\", \"build.user\": \"$USER\", \"build.host\": \"$HST\", /g" $DST/git.json
fi