forked from galasa-dev/managers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-locally.sh
executable file
·186 lines (158 loc) · 5.86 KB
/
build-locally.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
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
#! /usr/bin/env bash
#-----------------------------------------------------------------------------------------
#
# Objectives: Build this repository code locally.
#
# Environment variable over-rides:
# LOGS_DIR - Optional. Where logs are placed. Defaults to creating a temporary directory.
# SOURCE_MAVEN - Optional. Where a maven repository is from which the build will draw artifacts.
# DEBUG - Optional. Defaults to 0 (off)
#
#-----------------------------------------------------------------------------------------
# Where is this script executing from ?
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null ;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
# echo "Running from directory ${BASEDIR}"
export ORIGINAL_DIR=$(pwd)
# cd "${BASEDIR}"
cd "${BASEDIR}/.."
WORKSPACE_DIR=$(pwd)
#-----------------------------------------------------------------------------------------
#
# Set Colors
#
#-----------------------------------------------------------------------------------------
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)
#-----------------------------------------------------------------------------------------
#
# Headers and Logging
#
#-----------------------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@"
}
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@"
}
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@"
}
debug() { printf "${white}%s${reset}\n" "$@"
}
info() { printf "${white}➜ %s${reset}\n" "$@"
}
success() { printf "${green}✔ %s${reset}\n" "$@"
}
error() { printf "${red}✖ %s${reset}\n" "$@"
}
warn() { printf "${tan}➜ %s${reset}\n" "$@"
}
bold() { printf "${bold}%s${reset}\n" "$@"
}
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@"
}
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function usage {
info "Syntax: build-locally.sh [OPTIONS]"
cat << EOF
Options are:
-c | --clean : Do a clean build. One of the --clean or --delta flags are mandatory.
-d | --delta : Do a delta build. One of the --clean or --delta flags are mandatory.
EOF
}
#-----------------------------------------------------------------------------------------
# Process parameters
#-----------------------------------------------------------------------------------------
exportbuild_type=""
while [ "$1" != "" ]; do
case $1 in
-c | --clean ) export build_type="clean"
;;
-d | --delta ) export build_type="delta"
;;
-h | --help ) usage
exit
;;
* ) error "Unexpected argument $1"
usage
exit 1
esac
shift
done
if [[ "${build_type}" == "" ]]; then
error "Need to use either the --clean or --delta parameter."
usage
exit 1
fi
#-----------------------------------------------------------------------------------------
# Main logic.
#-----------------------------------------------------------------------------------------
source_dir="galasa-managers-parent"
project=$(basename ${BASEDIR})
h1 "Building ${project}"
# Debug or not debug ? Override using the DEBUG flag.
if [[ -z ${DEBUG} ]]; then
export DEBUG=0
# export DEBUG=1
info "DEBUG defaulting to ${DEBUG}."
info "Over-ride this variable if you wish. Valid values are 0 and 1."
else
info "DEBUG set to ${DEBUG} by caller."
fi
# Over-rode SOURCE_MAVEN if you want to build from a different maven repo...
if [[ -z ${SOURCE_MAVEN} ]]; then
export SOURCE_MAVEN=https://development.galasa.dev/main/maven-repo/obr/
info "SOURCE_MAVEN repo defaulting to ${SOURCE_MAVEN}."
info "Set this environment variable if you want to over-ride this value."
else
info "SOURCE_MAVEN set to ${SOURCE_MAVEN} by caller."
fi
# Create a temporary dir.
# Note: This bash 'spell' works in OSX and Linux.
if [[ -z ${LOGS_DIR} ]]; then
export LOGS_DIR="${BASEDIR}/local-builds/logs"
info "Logs are stored in the ${LOGS_DIR} folder."
info "Over-ride this setting using the LOGS_DIR environment variable."
else
info "Logs are stored in the ${LOGS_DIR} folder."
info "Over-ridden by caller using the LOGS_DIR variable."
fi
mkdir -p ${LOGS_DIR} 2>&1 > /dev/null # Don't show output. We don't care if it already existed.
info "Using source code at ${source_dir}"
cd ${BASEDIR}/${source_dir}
if [[ "${DEBUG}" == "1" ]]; then
OPTIONAL_DEBUG_FLAG="-debug"
else
OPTIONAL_DEBUG_FLAG="-info"
fi
# auto plain rich or verbose
CONSOLE_FLAG=--console=plain
log_file=${LOGS_DIR}/logs.txt
info "Log will be placed at ${log_file}"
if [[ "${build_type}" == "clean" ]]; then
goals="clean build check publishToMavenLocal -no-build-cache --no-daemon --parallel"
else
goals="build check publishToMavenLocal --parallel"
fi
cat << EOF
Using command:
gradle \
${CONSOLE_FLAG} \
-Dorg.gradle.java.home=${JAVA_HOME} \
-PsourceMaven=${SOURCE_MAVEN} ${OPTIONAL_DEBUG_FLAG} \
${goals} \
2>&1 > ${log_file}
EOF
gradle \
${CONSOLE_FLAG} \
-Dorg.gradle.java.home=${JAVA_HOME} \
-PsourceMaven=${SOURCE_MAVEN} ${OPTIONAL_DEBUG_FLAG} \
${goals} \
2>&1 > ${log_file}
rc=$? ; if [[ "${rc}" != "0" ]]; then cat ${log_file} ; error "Failed to build ${project} see logs at ${log_file}" ; exit 1 ; fi
success "Project ${project} built - OK - log is at ${log_file}"