forked from prometheus/jmx_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·217 lines (170 loc) · 5.29 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·217 lines (170 loc) · 5.29 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/usr/bin/env bash
#
# Copyright (C) The Prometheus jmx_exporter Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euo pipefail
readonly RELEASE_DIR='RELEASE'
ARTIFACTS=(
"jmx_prometheus_javaagent/target/jmx_prometheus_javaagent-{version}.jar"
"jmx_prometheus_isolator_javaagent/target/jmx_prometheus_isolator_javaagent-{version}.jar"
"jmx_prometheus_standalone/target/jmx_prometheus_standalone-{version}.jar"
)
gpg_key_id=""
log_info() {
echo "> $*"
}
log_error() {
echo "! $*" >&2
}
usage() {
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--gpg-key <key-id> GPG key ID for signing (uses default key if not specified)
-h, --help Show this help message
Description:
Build the JMX Exporter and create release artifacts in the RELEASE/ directory.
Version is automatically detected from pom.xml.
Examples:
$(basename "$0")
$(basename "$0") --gpg-key ABC123DEF
Requirements:
- mvnw in current directory
- gpg (for artifact signing)
- sha256sum (for checksums)
EOF
}
check_prerequisites() {
log_info "Checking prerequisites"
if [[ ! -f "mvnw" ]]; then
log_error "mvnw not found in current directory"
exit 1
fi
if ! command -v gpg &>/dev/null; then
log_error "GPG not found - required for artifact signing"
exit 1
fi
if ! command -v sha256sum &>/dev/null; then
log_error "sha256sum not found"
exit 1
fi
if ! command -v sed &>/dev/null; then
log_error "sed not found"
exit 1
fi
if ! command -v awk &>/dev/null; then
log_error "awk not found"
exit 1
fi
if ! command -v column &>/dev/null; then
log_error "column not found"
exit 1
fi
if [[ -n "${gpg_key_id}" ]]; then
if ! gpg --list-secret-keys "${gpg_key_id}" &>/dev/null; then
log_error "GPG secret key not found: ${gpg_key_id}"
exit 1
fi
log_info "Using GPG key: ${gpg_key_id}"
else
log_info "Using default GPG key"
fi
log_info "All prerequisites satisfied"
}
get_version() {
local version
version=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout 2>/dev/null | head -n 1)
if [[ -z "${version}" || "${version}" == *"@"* ]]; then
log_error "Could not determine version from pom.xml"
exit 1
fi
echo "${version}"
}
build_and_verify() {
log_info "Building and verifying"
./mvnw -B clean verify
log_info "Build and verification completed"
}
assemble_artifacts() {
local ver="$1"
log_info "Assembling release artifacts"
rm -rf "${RELEASE_DIR}"
mkdir -p "${RELEASE_DIR}"
local artifact_path
for template in "${ARTIFACTS[@]}"; do
artifact_path="${template//\{version\}/${ver}}"
if [[ ! -f "${artifact_path}" ]]; then
log_error "Artifact not found: ${artifact_path}"
exit 1
fi
cp "${artifact_path}" "${RELEASE_DIR}/"
log_info "Copied: ${artifact_path}"
done
log_info "Artifacts copied to ${RELEASE_DIR}/"
pushd "${RELEASE_DIR}" >/dev/null
local gpg_opts=("gpg")
if [[ -n "${gpg_key_id}" ]]; then
gpg_opts+=("--default-key" "${gpg_key_id}")
fi
local filename
for filename in *.jar; do
if [[ -f "${filename}" ]]; then
"${gpg_opts[@]}" --armor --detach-sign "${filename}"
log_info "Signed: ${filename}.asc"
sha256sum "${filename}" > "${filename}.sha256"
log_info "Checksum: ${filename}.sha256"
fi
done
popd >/dev/null
log_info "Signatures and checksums generated"
log_info "Build artifacts:"
ls -l "${RELEASE_DIR}/" | tail -n +2 | awk '{$1=$2=$3=$4=""; sub(/^[ \t]+/, ""); print}' | column -t | sed 's/^/> /'
}
main() {
while [[ $# -gt 0 ]]; do
case "$1" in
--gpg-key)
gpg_key_id="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
-*)
log_error "Unknown option: $1"
usage
exit 1
;;
*)
log_error "Unexpected argument: $1"
usage
exit 1
;;
esac
done
echo "> Prometheus JMX Exporter Build"
log_info "GPG key: ${gpg_key_id:-default}"
mkdir -p "${RELEASE_DIR}"
rm -f "${RELEASE_DIR}"/* 2>/dev/null || true
check_prerequisites
local version
version=$(get_version)
log_info "Version: ${version}"
build_and_verify
assemble_artifacts "${version}"
log_info "Build completed successfully!"
}
main "$@"