This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test-locally.sh
executable file
·198 lines (166 loc) · 6.42 KB
/
test-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
187
188
189
190
191
192
193
194
195
196
197
198
#! /usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
#-----------------------------------------------------------------------------------------
#
# Objectives: Build this repository code locally.
#
#-----------------------------------------------------------------------------------------
# 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 "${white}[${green}✔${white}] ${green}%s${reset}\n" "$@" ; }
error() { printf "${white}[${red}✖${white}] ${red}%s${reset}\n" "$@" ; }
warn() { printf "${white}[${tan}➜${white}] ${tan}%s${reset}\n" "$@" ; }
bold() { printf "${bold}%s${reset}\n" "$@" ; }
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ; }
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function clean_temp_folder() {
rm -fr $BASEDIR/temp
mkdir -p $BASEDIR/temp
LOGS_DIR=$BASEDIR/temp
}
function setup_source_folder() {
rm -fr $BASEDIR/temp/src
mkdir -p $BASEDIR/temp/src
mkdir -p $BASEDIR/temp/src/dev/galasa/examples/module1
cat << EOF > $BASEDIR/temp/src/dev/galasa/examples/module1/build.gradle
# A test module mock-up.
version = "0.0.1-SNAPSHOT" // trailing comment
# trailing content
EOF
cat << EOF > $BASEDIR/temp/src/dev/galasa/examples/module1/settings.gradle
# initial content
rootProject.name = "dev.galasa.examples/module1"
# trailing content
EOF
mkdir -p $BASEDIR/temp/src/dev/galasa/examples/module2
cat << EOF > $BASEDIR/temp/src/dev/galasa/examples/module2/build.gradle
# A test module mock-up.
version = "0.0.2-SNAPSHOT" // trailing comment
# trailing content
EOF
cat << EOF > $BASEDIR/temp/src/dev/galasa/examples/module2/settings.gradle
# initial content
rootProject.name = "dev.galasa.examples/module2"
# trailing content
EOF
}
function check_versions_have_suffix() {
suffix=$1
if [[ "$suffix" == "" ]]; then
info "Checking that the versions of the code are not using a suffix"
else
info "Checking that the versions of the code are using the $suffix suffix"
fi
cat << EOF > $BASEDIR/temp/versions-list-expected.txt
[$GALASABLD versioning list --sourcefolderpath $BASEDIR/temp/src]
dev.galasa.examples/module1 0.0.1$suffix
dev.galasa.examples/module2 0.0.2$suffix
EOF
diff $BASEDIR/temp/versions-list-expected.txt $BASEDIR/temp/versions-list-got.txt >> /dev/null
rc=$? ; if [[ "$rc" != "0" ]]; then error "Output from listing versions is not what we expected." ; exit 1 ; fi
success "The list of versions is what we expected."
}
function clear_version_suffixes() {
info "Removing the suffixes"
cmd="$GALASABLD versioning suffix remove --sourcefolderpath $BASEDIR/temp/src "
info "Command is $cmd"
$cmd > $BASEDIR/temp/versions-removed.txt
rc=$? ; if [[ "$rc" != "0" ]]; then error "Could not remove the version suffixes of the code. rc=$?" ; exit 1 ; fi
success "Version suffixes of modules removed OK."
}
function gather_version_list() {
info "Listing the suffixes"
cmd="$GALASABLD versioning list --sourcefolderpath $BASEDIR/temp/src "
info "Command is $cmd"
$cmd > $BASEDIR/temp/versions-list-got.txt
rc=$? ; if [[ "$rc" != "0" ]]; then error "Could not set the versions of the code. rc=$?" ; exit 1 ; fi
success "Versions of modules set OK."
}
function set_version_suffixes() {
desired_suffix=$1
info "Setting the suffixes prefixes to $desired_suffix"
cmd="$GALASABLD versioning suffix set --sourcefolderpath $BASEDIR/temp/src --suffix $desired_suffix"
info "Command is $cmd"
$cmd > $BASEDIR/temp/versions-set.txt
rc=$? ; if [[ "$rc" != "0" ]]; then error "Could not set the version suffixes to $desired_suffix. rc=$?" ; exit 1 ; fi
success "Version suffixes of modules set to $desired_suffix OK."
}
function test_versions_manipulation() {
h2 "Testing manipulations of versions"
setup_source_folder
gather_version_list
check_versions_have_suffix "-SNAPSHOT"
info "Removing the suffixes on versions"
clear_version_suffixes
gather_version_list
check_versions_have_suffix ""
info "Setting the suffixes on versions"
set_version_suffixes "-alpha"
gather_version_list
check_versions_have_suffix "-alpha"
success "Tested the galasabld versioning commands as best we can"
}
function calculate_galasabld_executable {
h2 "Calculate the name of the galasabld executable for this machine/os"
raw_os=$(uname -s) # eg: "Darwin"
os=""
case $raw_os in
Darwin*)
os="darwin"
;;
Windows*)
os="windows"
;;
Linux*)
os="linux"
;;
*)
error "Failed to recognise which operating system is in use. $raw_os"
exit 1
esac
architecture=$(uname -m)
printf "${architecture}"
if [ $architecture == "x86_64" ]; then
architecture="amd64"
fi
export GALASABLD=${BASEDIR}/bin/galasabld-${os}-${architecture}
info "galasabld binary is ${GALASABLD}"
success "OK"
}
calculate_galasabld_executable
clean_temp_folder
test_versions_manipulation