forked from salesforce/rules_spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_workspace_status
executable file
·165 lines (138 loc) · 4.46 KB
/
get_workspace_status
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#
# Copyright (c) 2017-2021, salesforce.com, inc.
# All rights reserved.
# Licensed under the BSD 3-Clause license.
# For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
#
# This script is executed with every 'bazel build' command if .bazelrc (or included file)
# has these settings:
# build --stamp
# build --workspace_status_command tools/buildstamp/get_workspace_status
# Which enables Bazel *stamping* for every build.
# This script writes Git data to::
# bazel-out/volatile-status.txt
# bazel-out/stable-status.txt
# If anything in stable-status.txt changes, it will trigger a rebuild of any target that
# has stamp=1 as an attribute (such as the Spring Boot rule).
# Changes to volatile-status.txt do not trigger rebuilds of those targets.
#
# More information:
# Bazel stamping: https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
# Spring Boot git.properties: //tools/springboot/write_gitinfo_properties.sh
# Spring Boot info actuator endpoint: ttps://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints
# First, make sure the current working directory is the Bazel workspace root.
# (assumes you do not have nested workspaces!)
while [[ ! -f WORKSPACE ]]; do cd .. ; done
if [[ ! -f WORKSPACE ]]; then
echo "No WORKSPACE found"
exit 1
fi
# ********************************
# ********************************
# TEST FOR FULL STAMPING
# ********************************
# ********************************
# if IS_RELEASE_BUILD=true or the file full_stamp.txt exists, full stamping is enabled
if [ "$IS_RELEASE_BUILD" = true ]; then
echo "IS_RELEASE_BUILD environment variable set: $IS_RELEASE_BUILD"
else
if [[ ! -f full_stamp.txt ]]; then
echo "full_stamp.txt file was not detected"
exit 0
fi
echo "full_stamp.txt file detected"
fi
echo "Full Bazel build stamping enabled. Adding Git properties to stamp. See //tools/buildstamp for details."
# ********************************
# GIT
# ********************************
# This data is then later consumed by the //tools/springboot rule (perhaps other rules as well) to write
# a git.properties file into the Spring Boot jar, which is then surfaced in the Spring Boot
# actuator info endpoint.
# BUILD ENVIRONMENT PROPERTIES
# git.build.user.email
git_email=$(git config --get user.email)
if [[ $? == 0 ]];
then
echo "git.build.user.email $git_email"
fi
# git.build.host
git_build_host=$(hostname)
echo "git.build.host $git_build_host"
# git.build.time
git_build_time=$(date -u '+%Y-%m-%d @ %H\:%M\:%S -0000')
if [[ $? == 0 ]];
then
echo "git.build.time $git_build_time"
fi
# BRANCH PROPERTIES
# git.branch
git_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $? == 0 ]];
then
echo "STABLE_git.branch $git_branch"
fi
# dirty? (modified files in branch when built)
git diff-index --quiet HEAD --
if [[ $? == 0 ]];
then
git_status="false"
else
git_status="true"
fi
echo "STABLE_git.dirty $git_status"
# git.remote.origin.url
git_remote_url=$(git config --get remote.origin.url)
if [[ $? == 0 ]];
then
echo "STABLE_git.remote.origin.url $git_remote_url"
fi
# LAST COMMIT PROPERTIES
# git.commit.user.email (email of last commit author)
git_commit_email=$(git log -1 --pretty=format:'%ae')
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.user.email $git_commit_email"
fi
# git.commit.user.name
git_commit_author=$(git log -1 --pretty=format:'%an')
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.user.name $git_commit_author"
fi
# git.commit.id.sha
git_commit_id=$(git log -1 --pretty=format:'%H')
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.id.sha $git_commit_id"
fi
# git.commit.id.abbrev
git_commit_id_short=$(git log -1 --pretty=format:'%h')
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.id.abbrev $git_commit_id_short"
fi
# git.commit.time
git_commit_time=$(git log -1 --pretty=format:'%ai')
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.time $git_commit_time"
fi
# git.commit.message.short (just going with commit 'status' here)
git_commit_msg=$(git log -1 --pretty=format:'%s')
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.message.short $git_commit_msg"
fi
# git.commit.id.describe
git_commit_describe=$(git describe)
if [[ $? == 0 ]];
then
echo "STABLE_git.commit.id.describe $git_commit_describe"
fi
# git.closest.tag.name
git_closest_tag=$(git describe --abbrev=0)
if [[ $? == 0 ]];
then
echo "STABLE_git.closest.tag.name $git_closest_tag"
fi