-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
98 lines (73 loc) · 2.8 KB
/
build.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
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
#!/usr/bin/env bash
#
# Copyright 2021 by Vegard IT GmbH, Germany, https://vegardit.com
# SPDX-License-Identifier: Apache-2.0
#
# Author: Sebastian Thomschke, Vegard IT GmbH
#
# https://github.com/vegardit/activemq-artemis-dynatrace-plugin
#
set -eu
#################################################
# execute script with bash if loaded with other shell interpreter
#################################################
if [ -z "${BASH_VERSINFO:-}" ]; then /usr/bin/env bash "$0" "$@"; exit; fi
set -o pipefail
#################################################
# install debug traps
#################################################
trap 'echo >&2 "$(date +%H:%M:%S) Error - exited with status $? at line $LINENO:"; pr -tn $0 | tail -n+$((LINENO - 3)) | head -n7' ERR
if [[ "${DEBUG:-}" == "1" ]]; then
if [[ $- =~ x ]]; then
# "set -x" was specified already, we only improve the PS4 in this case
PS4='+\033[90m[$?] $BASH_SOURCE:$LINENO ${FUNCNAME[0]}()\033[0m '
else
# "set -x" was not specified, we use a DEBUG trap for better debug output
set -T
__print_debug_statement() {
printf "\e[90m#[$?] $BASH_SOURCE:$1 ${FUNCNAME[1]}() %*s\e[35m$BASH_COMMAND\e[m\n" "$(( 2 * ($BASH_SUBSHELL + ${#FUNCNAME[*]} - 2) ))" >&2
}
trap '__print_debug_statement $LINENO' DEBUG
fi
fi
#################################################
# check prereqs
#################################################
if ! hash git &>/dev/null; then
echo "Error: command 'git' not found."
exit 1
fi
if ! hash zip &>/dev/null; then
echo "Error: command 'zip' not found."
exit 1
fi
if ! hash yq &>/dev/null; then
echo "Error: command 'yq' not found. Please install from https://github.com/mikefarah/yq/releases/"
exit 1
fi
#################################################
# build
#################################################
project_root=$(realpath $(dirname "$BASH_SOURCE[0]"))
echo "project_root=$project_root"
work_dir=$project_root/work
echo "work_dir=$work_dir"
# use last commit time unix epoch value as minor version
minor_version=$(git show -s --format=%ct)
#rm -rf "$work_dir"
for f in $project_root/*/plugin.yaml; do
plugin_name=$(basename $(dirname $f))
if [[ ${GITHUB_ACTIONS:-} == "true" ]]; then echo "::group::Processing [$plugin_name]..."; fi
if [[ $OSTYPE == "cygwin" || $OSTYPE == "msys" ]]; then
f=$(cygpath -w "$f")
fi
echo "Validating [$f]..."
yq e "$f">/dev/null
mkdir -p "$work_dir/$plugin_name/custom"
# suffix the version with the commit SHA
yq -j e ".version |= sub(\"-SNAPSHOT\", \"\") + \".$minor_version\"" $f >$work_dir/$plugin_name/custom/plugin.json
plugin_zip=$work_dir/$plugin_name-latest.zip
echo "Creating [$plugin_zip]..."
(cd $work_dir/$plugin_name && zip -r "$plugin_zip" ./custom/*)
if [[ ${GITHUB_ACTIONS:-} == "true" ]]; then echo "::endgroup::"; fi
done