-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathtest_submodule_updated.sh
More file actions
executable file
·125 lines (103 loc) · 3.76 KB
/
test_submodule_updated.sh
File metadata and controls
executable file
·125 lines (103 loc) · 3.76 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
#!/bin/bash
# Submodules not checking for
declare -ar exclusion_list=( "blt" "integratedTests" "uberenv" )
echo "Submodules that are excluded from sync test : ${exclusion_list[@]}"
# Do not pull large files
git lfs uninstall &> /dev/null
# Pull submodule to get .git files.
#git submodule update --init integratedTests
git submodule update --init src/cmake/blt
git submodule update --init src/coreComponents/LvArray
git submodule update --init src/coreComponents/constitutive/PVTPackage
git submodule update --init src/coreComponents/fileIO/coupling/hdf5_interface
git submodule update --init src/coreComponents/constitutive/HPCReact
# Initialize PR submodule hashes
declare -ar pr_hashes_array=( $(git submodule status | awk '{print $1}') )
# Initialize submodule paths
declare -ar paths_array=( $(git submodule status | awk '{print $2}') )
# Initialize differences between PR and origin/develop branches
declare -ar diff_array=( $(git diff --name-only origin/develop) )
# Initialize main branches for submodules
declare -Ar main_branches=(
["blt"]="origin/develop"
["LvArray"]="origin/develop"
["integratedTests"]="origin/develop"
["hdf5_interface"]="origin/master"
["PVTPackage"]="origin/develop"
["HPCReact"]="origin/main"
)
length=${#paths_array[@]}
# Returns exit code 0 if the hash for every submodule in the PR is equal
# to the hash of each submodule's main branch (develop or master).
# Note: For LvArray submodule only, checks if the PR hash is in the
# main branch's commit history.
# Note: See "exclusion_list" for submodules that are exempted.
exit_code=0
unsync_submodules=()
for (( i=0; i<$length; i++))
do
# Just the submodule name
module_name="$(basename ${paths_array[$i]})"
# Check if submodule is excluded from check
excluded=0
for ex in "${exclusion_list[@]}"
do
if [ "$module_name" = "$ex" ]
then
excluded=1
fi
done
if [ $excluded -eq 1 ]
then
continue
fi
# Check hashes if not excluded
# Submodule's main branch
main_branch="${main_branches[$module_name]}"
# Submodule main hash
main_hash="$( git -C ${paths_array[$i]} rev-parse $main_branch )"
# PR hash with prefixed character removed
pr_hash="$( echo ${pr_hashes_array[$i]} | tr -cd [:alnum:] )"
if [ $module_name == "LvArray" ]
then
lv_array_commits="$(git -C ${paths_array[$i]} log $main_branch --pretty=%H)"
if grep -q "$pr_hash" <<< "$lv_array_commits"
then
echo "Submodule LvArray's main branch $main_branch contains"\
"PR branch's latest commit : $pr_hash"
else
echo "Submodule LvArray's main branch $main_branch does not contain"\
"PR branch's latest commit : $pr_hash"
echo "---- PR branch has latest hash $pr_hash"
echo "---- $module_name/$main_branch has latest hash $main_hash"
unsync_submodules+=( "$module_name" )
exit_code=1
fi
elif [ $pr_hash == $main_hash ]
then
echo "PR branch and $main_branch have the same hashes for submodule"\
"$module_name : $pr_hash"
else
echo "PR branch and $main_branch have different hashes for submodule"\
"$module_name:"
echo "---- PR branch has hash $pr_hash"
echo "---- $module_name/$main_branch has hash $main_hash"
unsync_submodules+=( "$module_name" )
exit_code=1
fi
done
echo $'\n'
if [ $exit_code -eq 1 ]
then
echo "This PR has the following submodules"\
"that are out of sync with master or develop : ${unsync_submodules[@]}"
echo "FAILURE : Please make sure your branch"\
"is up to date with develop."\
"Merge any submodule changes into the submodule's develop or"\
"master branch before merging this PR with the main GEOSX repository."
else
echo "SUCCESS : PR submodules are up to date!"
fi
# Renable git lfs
git lfs install &> /dev/null
exit $exit_code