-
Notifications
You must be signed in to change notification settings - Fork 3
/
get-changed-modules-pull-request.sh
executable file
·199 lines (173 loc) · 6.74 KB
/
get-changed-modules-pull-request.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
199
#!/usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
#-----------------------------------------------------------------------------------------
#
# Objectives: Get all modules that have been changed in a Pull Request.
#
#-----------------------------------------------------------------------------------------
# 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}/.."
PROJECT_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 usage {
info "Syntax: get-changed-modules-pull-request.sh [OPTIONS]"
cat << EOF
Options are:
-h | --help : Display this help text
--pr-number The number of the Pull Request
EOF
}
module_names=(\
"buildutils" \
"platform" \
"wrapping" \
"gradle" \
"maven" \
"framework" \
"extensions" \
"managers" \
"obr" \
)
#-----------------------------------------------------------------------------------------
# Process parameters
#-----------------------------------------------------------------------------------------
pr_number=""
while [ "$1" != "" ]; do
case $1 in
-h | --help ) usage
exit
;;
--pr-number ) pr_number="$2"
shift
;;
* ) error "Unexpected argument $1"
usage
exit 1
esac
shift
done
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function get_paths_changed_in_pr() {
h1 "Getting the file paths changed in Pull Request number ${pr_number}"
# Extract changed module names from changed files from GitHub CLI output
mapfile -t changed_files_in_pr < <(gh pr diff --repo galasa-dev/galasa ${pr_number} --name-only)
h2 "Files changed:"
modules_changed_in_pr=()
for changed_file in "${changed_files_in_pr[@]}"; do
echo "$changed_file"
module=$(echo "$changed_file" | cut -d'/' -f2)
modules_changed_in_pr+=("$module")
done
# Remove possible duplicates from array of changed modules
declare -A unique_module_map
unique_modules_found_in_pr=()
for module in "${modules_changed_in_pr[@]}"; do
if [[ -z "${unique_module_map[$module]}" ]]; then
unique_modules_found_in_pr+=("$module")
unique_module_map[$module]=1
fi
done
h2 "Modules changed:"
echo "${unique_modules_found_in_pr[@]}"
}
function get_changed_modules_and_set_in_environment() {
h1 "Finding changed modules and setting environment variables that can be used in the GitHub Actions workflows..."
for module in "${unique_modules_found_in_pr[@]}"; do
if [[ "$module" == "platform" ]]; then
echo "PLATFORM_CHANGED=true" >> $GITHUB_OUTPUT
# Also rebuild modules that depend on the Platform...
echo "WRAPPING_CHANGED=true" >> $GITHUB_OUTPUT
echo "GRADLE_CHANGED=true" >> $GITHUB_OUTPUT
echo "MAVEN_CHANGED=true" >> $GITHUB_OUTPUT
echo "FRAMEWORK_CHANGED=true" >> $GITHUB_OUTPUT
# echo "EXTENSIONS_CHANGED=true" >> $GITHUB_OUTPUT # Not done yet
echo "MANAGERS_CHANGED=true" >> $GITHUB_OUTPUT
echo "OBR_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "buildutils" ]]; then
echo "BUILDUTILS_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "wrapping" ]]; then
echo "WRAPPING_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "gradle" ]]; then
echo "GRADLE_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "maven" ]]; then
echo "MAVEN_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "framework" ]]; then
echo "FRAMEWORK_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "extensions" ]]; then
echo "EXTENSIONS_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "managers" ]]; then
echo "MANAGERS_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
if [[ "$module" == "obr" ]]; then
echo "OBR_CHANGED=true" >> $GITHUB_OUTPUT
continue
fi
done
}
# Set outputs to false as default value.
echo "BUILDUTILS_CHANGED=false" >> $GITHUB_OUTPUT
echo "PLATFORM_CHANGED=false" >> $GITHUB_OUTPUT
echo "WRAPPING_CHANGED=false" >> $GITHUB_OUTPUT
echo "GRADLE_CHANGED=false" >> $GITHUB_OUTPUT
echo "MAVEN_CHANGED=false" >> $GITHUB_OUTPUT
echo "FRAMEWORK_CHANGED=false" >> $GITHUB_OUTPUT
echo "EXTENSIONS_CHANGED=false" >> $GITHUB_OUTPUT
echo "MANAGERS_CHANGED=false" >> $GITHUB_OUTPUT
echo "OBR_CHANGED=false" >> $GITHUB_OUTPUT
get_paths_changed_in_pr
get_changed_modules_and_set_in_environment