1
1
#! /bin/bash --login
2
2
3
- echo " Start at $( date) "
3
+ echo " Starting automated testing at $( date) "
4
4
5
5
my_dir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
6
6
echo " Set my_dir ${my_dir} "
@@ -13,6 +13,7 @@ usage() {
13
13
echo
14
14
echo " -t target/machine script is running on DEFAULT: $( hostname) "
15
15
echo " -h display this message and quit"
16
+ echo " -w run workflow tests on $( hostname) "
16
17
echo
17
18
exit 1
18
19
}
@@ -22,20 +23,25 @@ usage() {
22
23
23
24
export TARGET=" $( hostname) "
24
25
25
- while getopts " t:h" opt; do
26
+ TEST_WORKFLOW=0
27
+ while getopts " t:h:w" opt; do
26
28
case $opt in
27
29
t)
28
30
TARGET=$OPTARG
29
31
;;
30
32
h|\? |:)
31
33
usage
32
34
;;
35
+ w)
36
+ TEST_WORKFLOW=1
37
+ ;;
33
38
esac
34
39
done
35
40
41
+ echo " Running automated testing on $TARGET "
42
+
36
43
case ${TARGET} in
37
- hera | orion)
38
- echo " Running Automated Testing on $TARGET "
44
+ hera | orion | hercules)
39
45
source $MODULESHOME /init/sh
40
46
source $my_dir /${TARGET} .sh
41
47
module purge
@@ -49,106 +55,176 @@ case ${TARGET} in
49
55
;;
50
56
esac
51
57
58
+ # ==============================================================================
59
+ # set list of available CI tests to run on the Global Workflow
60
+ source $my_dir /ci_tests.sh
61
+
62
+ # ==============================================================================
63
+ # set things that depend on whether running workflow tests or not
64
+ gdasapp_url=" https://github.com/NOAA-EMC/GDASApp.git"
65
+ if [[ $TEST_WORKFLOW == 1 ]]; then
66
+ echo " Testing GDASApp inside the Global Workflow"
67
+
68
+ CI_LABEL=" ${GDAS_CI_HOST} -GW-RT"
69
+ OPEN_PR_LIST_DIR=$GDAS_CI_ROOT /open_pr_list_gw
70
+ PR_TEST_DIR=$GDAS_CI_ROOT /workflow/PR
71
+ BASE_REPO=global-workflow
72
+
73
+ # Default Global Workflow repo and branch if no companion PR found
74
+ workflow_url=" https://github.com/NOAA-EMC/global-workflow.git"
75
+ workflow_branch=" develop"
76
+ else
77
+ echo " Testing stand-alone GDASApp"
78
+
79
+ CI_LABEL=" ${GDAS_CI_HOST} -RT"
80
+ OPEN_PR_LIST_DIR=$GDAS_CI_ROOT /open_pr_list
81
+ PR_TEST_DIR=$GDAS_CI_ROOT /PR
82
+ BASE_REPO=GDASApp
83
+ fi
84
+
52
85
# ==============================================================================
53
86
# pull on the repo and get list of open PRs
87
+
54
88
cd $GDAS_CI_ROOT /repo
55
- CI_LABEL=" ${GDAS_CI_HOST} -RT"
56
- gh pr list --label " $CI_LABEL " --state " open" | awk ' {print $1;}' > $GDAS_CI_ROOT /open_pr_list
57
89
58
- open_pr=` cat $GDAS_CI_ROOT /open_pr_list | wc -l`
90
+ gh pr list --label " $CI_LABEL " --state " open" | awk ' {print $1;}' > $OPEN_PR_LIST_DIR
91
+
92
+ open_pr=` cat $OPEN_PR_LIST_DIR | wc -l`
59
93
if (( $open_pr == 0 )) ; then
60
94
echo " No open PRs with ${CI_LABEL} , exit."
61
- echo " Finish at $( date) "
95
+ echo " Finished automated testing at $( date) "
62
96
exit
63
97
fi
64
98
65
- open_pr_list=$( cat $GDAS_CI_ROOT /open_pr_list )
99
+ open_pr_list=$( cat $OPEN_PR_LIST_DIR )
66
100
67
101
# ==============================================================================
68
102
# clone, checkout, build, test, etc.
69
- repo_url=" https://github.com/NOAA-EMC/GDASApp.git"
70
103
# loop through all open PRs
71
104
for pr in $open_pr_list ; do
72
105
echo " "
73
- echo " Start processing Pull Request #${pr} at $( date) "
106
+ echo " Starting processing of pull request #${pr} at $( date) "
74
107
75
108
# get the branch name used for the PR
76
109
gdasapp_branch=$( gh pr view $pr --json headRefName -q " .headRefName" )
77
110
78
- # get additional branch information
79
- branch_owner=$( gh pr view $pr --repo ${repo_url } --json headRepositoryOwner --jq ' .headRepositoryOwner.login' )
80
- branch_name=$( gh pr view $pr --repo ${repo_url } --json headRepository --jq ' .headRepository.name' )
81
- pr_assignees=$( gh pr view $pr --repo ${repo_url } --json assignees --jq ' .assignees[].login' )
82
-
111
+ # get additional branch informatio
112
+ branch_owner=$( gh pr view $pr --repo ${gdasapp_url } --json headRepositoryOwner --jq ' .headRepositoryOwner.login' )
113
+ branch_name=$( gh pr view $pr --repo ${gdasapp_url } --json headRepository --jq ' .headRepository.name' )
114
+ pr_assignees=$( gh pr view $pr --repo ${gdasapp_url } --json assignees --jq ' .assignees[].login' )
115
+
83
116
# check if any assignee is authorized to run CI
84
- authorized_by= " "
117
+ rc=1
85
118
for str in ${pr_assignees[@]} ; do
86
- grep $str /scratch1/NCEPDEV/da/role.jedipara/CI/GDASApp/authorized_users
87
- rc=$?
119
+ grep $str $AUTHORIZED_USERS_FILE > /dev/null
120
+ if (( rc != 0 )) ; then
121
+ rc=$?
122
+ fi
88
123
if (( rc == 0 )) ; then
89
- authorized_by=${str}
90
- echo " FOUND MATCH $str , rc $rc "
91
- break
124
+ echo " Authorized user $str assigned to this PR"
92
125
fi
93
126
done
94
127
95
128
# Authorized to run CI
96
129
if (( rc == 0 )) ; then
97
- echo " Run CI "
130
+ echo " CI authorized. Running CI... "
98
131
99
132
# update PR label
100
133
gh pr edit $pr --remove-label $CI_LABEL --add-label ${CI_LABEL} -Running
101
-
102
- # construct the fork URL
103
- gdasapp_url=" https://github.com/$branch_owner /${branch_name} .git"
104
-
134
+
105
135
echo " GDASApp URL: $gdasapp_url "
106
136
echo " GDASApp branch Name: $gdasapp_branch "
107
- echo " CI authorized by $authorized_by at $( date) "
137
+
138
+ if [[ $TEST_WORKFLOW == 1 ]]; then
139
+ # check for a companion PR in the global-workflow
140
+ companion_pr_exists=$( gh pr list --repo ${workflow_url} --head ${gdasapp_branch} --state open)
141
+
142
+ if [ -n " $companion_pr_exists " ]; then
143
+ # get the PR number
144
+ companion_pr=$( echo " $companion_pr_exists " | awk ' {print $1;}' )
145
+
146
+ # extract the necessary info
147
+ branch_owner=$( gh pr view $companion_pr --repo $workflow_url --json headRepositoryOwner --jq ' .headRepositoryOwner.login' )
148
+ branch_name=$( gh pr view $companion_pr --repo $workflow_url --json headRepository --jq ' .headRepository.name' )
149
+
150
+ # Construct fork URL. Update workflow branch name
151
+ workflow_url=" https://github.com/$branch_owner /$branch_name .git"
152
+ workflow_branch=$gdasapp_branch
153
+ fi
154
+
155
+ echo " Found companion Global Workflow PR #${companion_pr} !"
156
+ echo " Global Workflow URL: $workflow_url "
157
+ echo " Global Workflow branch name: $workflow_branch "
158
+ fi
108
159
109
- # create PR specific directory
110
- if [ -d $GDAS_CI_ROOT /PR /$pr ]; then
111
- rm -rf $GDAS_CI_ROOT /PR /$pr
160
+ # create PR specific directory
161
+ if [ -d $PR_TEST_DIR /$pr ]; then
162
+ rm -rf $PR_TEST_DIR /$pr
112
163
fi
113
- mkdir -p $GDAS_CI_ROOT /PR /$pr
114
- cd $GDAS_CI_ROOT /PR/ $pr
164
+ mkdir -p $PR_TEST_DIR /$pr
165
+ cd $PR_TEST_DIR / $pr
115
166
pwd
116
167
117
168
# clone copy of repo
118
- git clone --recursive --jobs 8 --branch $gdasapp_branch $gdasapp_url
119
- cd GDASApp
169
+ if [[ $TEST_WORKFLOW == 1 ]]; then
170
+ echo " Cloning Global Workflow branch $workflow_branch from $workflow_url at $( date) "
171
+ git clone --recursive --jobs 8 --branch $workflow_branch $workflow_url
172
+ cd global-workflow/sorc/gdas.cd
173
+ else
174
+ echo " Cloning GDASApp branch $workflow_branch at $( date) "
175
+ git clone --recursive --jobs 8 --branch $gdasapp_branch $gdasapp_url
176
+ cd GDASApp
177
+ fi
120
178
pwd
121
179
122
180
# checkout GDASApp pull request
123
- git pull
124
181
gh pr checkout $pr
125
182
git submodule update --init --recursive
126
183
127
184
# get commit hash
128
185
commit=$( git log --pretty=format:' %h' -n 1)
129
- echo " $commit " > $GDAS_CI_ROOT /PR /$pr /commit
186
+ echo " $commit " > $PR_TEST_DIR /$pr /commit
130
187
131
188
# run build and testing command
132
- echo " Execute $my_dir /run_ci.sh for $GDAS_CI_ROOT /PR/$pr /GDASApp at $( date) "
133
- $my_dir /run_ci.sh -d $GDAS_CI_ROOT /PR/$pr /GDASApp -o $GDAS_CI_ROOT /PR/$pr /output_${commit}
189
+ echo " Running run_ci.sh for $PR_TEST_DIR /$pr /$BASE_REPO at $( date) "
190
+ run_ci_cmd=" $my_dir /run_ci.sh -d $PR_TEST_DIR /$pr /$BASE_REPO -o $PR_TEST_DIR /$pr /output_${commit} "
191
+ if [[ $TEST_WORKFLOW == 1 ]]; then
192
+ # get ci tests from PR description and convert into a regular expressions to be excluded
193
+ branch_body=$( gh pr view $pr --repo ${gdasapp_url} --json body --jq ' .body' )
194
+ ci_checklist=$( echo " $branch_body " | grep ' \[x\]' )
195
+ ctest_regex_exclude=" "
196
+ for ci_test in ${CI_TESTS[@]} ; do
197
+ if ! echo " $ci_checklist " | grep -q " $ci_test " ; then
198
+ ctest_regex_exclude+=" ${ctest_regex_exclude: +|} $ci_test "
199
+ fi
200
+ done
201
+
202
+ # setup run_ci.sh arguments to test in the Global Workflow and exclude chosen CI tests
203
+ run_ci_cmd+=" -w"
204
+ if [ -n " $ctest_regex_exclude " ]; then
205
+ run_ci_cmd+=" -E $ctest_regex_exclude "
206
+ fi
207
+ fi
208
+ $run_ci_cmd
134
209
ci_status=$?
135
- echo " After run_ci.sh with ci_status ${ci_status} at $( date) "
136
- gh pr comment $pr --repo ${repo_url} --body-file $GDAS_CI_ROOT /PR/$pr /output_${commit}
210
+ echo " Finished running run_ci.sh with ci_status ${ci_status} at $( date) "
211
+
212
+ gh pr comment $pr --repo ${gdasapp_url} --body-file $PR_TEST_DIR /$pr /output_${commit}
137
213
if [ $ci_status -eq 0 ]; then
138
- gh pr edit $pr --repo ${repo_url } --remove-label ${CI_LABEL} -Running --add-label ${CI_LABEL} -Passed
214
+ gh pr edit $pr --repo ${gdasapp_url } --remove-label ${CI_LABEL} -Running --add-label ${CI_LABEL} -Passed
139
215
else
140
- gh pr edit $pr --repo ${repo_url } --remove-label ${CI_LABEL} -Running --add-label ${CI_LABEL} -Failed
216
+ gh pr edit $pr --repo ${gdasapp_url } --remove-label ${CI_LABEL} -Running --add-label ${CI_LABEL} -Failed
141
217
fi
142
218
143
219
# Not authorized to run CI
144
220
else
145
- echo " Do NOT run CI "
221
+ echo " No authorized users assigned to this PR. Aborting CI... "
146
222
fi
147
223
148
- echo " Finish processing Pull Request #{pr} at $( date) "
224
+ echo " Finished processing Pull Request #$ {pr} at $( date) "
149
225
done
150
226
151
227
# ==============================================================================
152
228
# scrub working directory for older files
153
- find $GDAS_CI_ROOT /PR /* -maxdepth 1 -mtime +3 -exec rm -rf {} \;
154
- echo " Finish at $( date) "
229
+ find $PR_TEST_DIR /* -maxdepth 1 -mtime +3 -exec rm -rf {} \;
230
+ echo " Finished automated testing at $( date) "
0 commit comments