forked from project-koku/koku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_check.sh
executable file
·197 lines (173 loc) · 7.47 KB
/
pr_check.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
#!/bin/bash
# --------------------------------------------
# Options that must be configured by app owner
# --------------------------------------------
APP_NAME="hccm" # name of app-sre "application" folder this component lives in
COMPONENT_NAME="koku" # name of app-sre "resourceTemplate" in deploy.yaml for this component
IMAGE="quay.io/cloudservices/koku"
IMAGE_TAG=$(git rev-parse --short=7 HEAD)
DBM_IMAGE=${IMAGE}
DBM_INVOCATION=$(printf "%02d" $(((RANDOM%100))))
COMPONENTS="hive-metastore koku presto" # specific components to deploy (optional, default: all)
COMPONENTS_W_RESOURCES="hive-metastore koku presto" # components which should preserve resource settings (optional, default: none)
LABELS_DIR="$WORKSPACE/github_labels"
export IQE_PLUGINS="cost_management"
export IQE_MARKER_EXPRESSION="cost_smoke"
export IQE_CJI_TIMEOUT="120m"
set -ex
mkdir -p $LABELS_DIR
exit_code=0
task_arr=([1]="Build" [2]="Smoke Tests" [3]="Latest Commit")
error_arr=([1]="The PR is not labeled to build the test image" [2]="The PR is not labeled to run smoke tests" [3]="This commit is out of date with the PR")
function check_for_labels() {
if [ -f $LABELS_DIR/github_labels.txt ]; then
egrep "$1" $LABELS_DIR/github_labels.txt &>/dev/null
else
null &>/dev/null
fi
}
function build_image() {
export DOCKER_BUILDKIT=1
source $CICD_ROOT/build.sh
}
function run_smoke_tests() {
source ${CICD_ROOT}/_common_deploy_logic.sh
export NAMESPACE=$(bonfire namespace reserve --duration 2h15m)
oc get secret/koku-aws -o json -n ephemeral-base | jq -r '.data' > aws-creds.json
oc get secret/koku-gcp -o json -n ephemeral-base | jq -r '.data' > gcp-creds.json
oc get secret/koku-oci -o json -n ephemeral-base | jq -r '.data' > oci-creds.json
AWS_ACCESS_KEY_ID_EPH=$(jq -r '."aws-access-key-id"' < aws-creds.json | base64 -d)
AWS_SECRET_ACCESS_KEY_EPH=$(jq -r '."aws-secret-access-key"' < aws-creds.json | base64 -d)
GCP_CREDENTIALS_EPH=$(jq -r '."gcp-credentials"' < gcp-creds.json)
OCI_CREDENTIALS_EPH=$(jq -r '."oci-credentials"' < oci-creds.json)
OCI_CLI_USER_EPH=$(jq -r '."oci-cli-user"' < oci-creds.json | base64 -d)
OCI_CLI_FINGERPRINT_EPH=$(jq -r '."oci-cli-fingerprint"' < oci-creds.json | base64 -d)
OCI_CLI_TENANCY_EPH=$(jq -r '."oci-cli-tenancy"' < oci-creds.json | base64 -d)
# This sets the image tag for the migrations Job to be the current koku image tag
DBM_IMAGE_TAG=${IMAGE_TAG}
bonfire deploy \
${APP_NAME} \
--ref-env insights-production \
--set-template-ref ${APP_NAME}/${COMPONENT_NAME}=${ghprbActualCommit} \
--set-image-tag ${IMAGE}=${IMAGE_TAG} \
--namespace ${NAMESPACE} \
${COMPONENTS_ARG} \
${COMPONENTS_RESOURCES_ARG} \
--optional-deps-method hybrid \
--set-parameter rbac/MIN_REPLICAS=1 \
--set-parameter koku/AWS_ACCESS_KEY_ID_EPH=${AWS_ACCESS_KEY_ID_EPH} \
--set-parameter koku/AWS_SECRET_ACCESS_KEY_EPH=${AWS_SECRET_ACCESS_KEY_EPH} \
--set-parameter koku/GCP_CREDENTIALS_EPH=${GCP_CREDENTIALS_EPH} \
--set-parameter koku/OCI_CREDENTIALS_EPH=${OCI_CREDENTIALS_EPH} \
--set-parameter koku/OCI_CLI_USER_EPH=${OCI_CLI_USER_EPH} \
--set-parameter koku/OCI_CLI_FINGERPRINT_EPH=${OCI_CLI_FINGERPRINT_EPH} \
--set-parameter koku/OCI_CLI_TENANCY_EPH=${OCI_CLI_TENANCY_EPH} \
--set-parameter koku/DBM_IMAGE_TAG=${DBM_IMAGE_TAG} \
--set-parameter koku/DBM_INVOCATION=${DBM_INVOCATION} \
--no-single-replicas \
--source=appsre \
--timeout 600
source $CICD_ROOT/cji_smoke_test.sh
}
function run_test_filter_expression {
if check_for_labels "aws-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api_aws or test_api_ocp_on_aws or test_api_cost_model_aws or test_api_cost_model_ocp_on_aws"
elif check_for_labels "azure-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api_azure or test_api_ocp_on_azure or test_api_cost_model_azure or test_api_cost_model_ocp_on_azure"
elif check_for_labels "gcp-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api_gcp or test_api_ocp_on_gcp or test_api_cost_model_gcp or test_api_cost_model_ocp_on_gcp"
elif check_for_labels "oci-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api_oci or test_api_cost_model_oci"
elif check_for_labels "ocp-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api_ocp or test_api_cost_model_ocp or _ingest_multi_sources"
elif check_for_labels "hot-fix-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api"
export IQE_MARKER_EXPRESSION="outage"
elif check_for_labels "cost-model-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api_cost_model or test_api_ocp_source_upload_service"
elif check_for_labels "full-run-smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api"
elif check_for_labels "smoke-tests"
then
export IQE_FILTER_EXPRESSION="test_api"
export IQE_MARKER_EXPRESSION="cost_required"
else
echo "PR smoke tests skipped"
exit_code=2
fi
}
function make_failed_results_xml() {
mkdir $WORKSPACE/artifacts
cat << EOF > $WORKSPACE/artifacts/junit-pr_check.xml
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite id="pr_check" name="PR Check" tests="1" failures="1">
<testcase id="pr_check.${task_arr[$exit_code]}" name="${task_arr[$exit_code]}">
<failure type="${task_arr[$exit_code]}">"${error_arr[$exit_code]}"</failure>
</testcase>
</testsuite>
EOF
}
function make_skipped_xml() {
mkdir $WORKSPACE/artifacts
cat << EOF > $WORKSPACE/artifacts/junit-pr_check.xml
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite id="pr_check" name="PR Check" tests="1" failures="0">
<testcase id="pr_check.skipped" name="Skipped">
</testcase>
</testsuite>
EOF
}
# check if this commit is out of date with the branch
latest_commit=$(curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/project-koku/koku/pulls/$ghprbPullId | jq -r '.head.sha')
if [[ $latest_commit != $ghprbActualCommit ]]; then
exit_code=3
make_results_xml
exit $exit_code
fi
# Save PR labels into a file
curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/project-koku/koku/issues/$ghprbPullId/labels | jq '.[].name' > $LABELS_DIR/github_labels.txt
# check if this PR is labeled to build the test image
if ! check_for_labels 'lgtm|pr-check-build|*smoke-tests|ok-to-skip-smokes'; then
echo "PR check skipped"
exit_code=1
elif check_for_labels 'ok-to-skip-smokes'; then
echo "smokes not required"
exit_code=-1
else
# Install bonfire repo/initialize
run_test_filter_expression
echo $IQE_MARKER_EXPRESSION
echo $IQE_FILTER_EXPRESSION
CICD_URL=https://raw.githubusercontent.com/RedHatInsights/bonfire/master/cicd
curl -s $CICD_URL/bootstrap.sh > .cicd_bootstrap.sh && source .cicd_bootstrap.sh
echo "creating PR image"
build_image
fi
if [[ $exit_code == 0 ]]; then
# check if this PR is labeled to run smoke tests
if ! check_for_labels 'lgtm|*smoke-tests'; then
echo "PR smoke tests skipped"
exit_code=2
else
echo "running PR smoke tests"
run_smoke_tests
source $CICD_ROOT/post_test_results.sh # send test results to Ibutsu
fi
fi
if [[ $exit_code > 0 ]]; then
echo "PR check failed"
make_failed_results_xml
elif [[ $exit_code < 0 ]]; then
echo "PR check skipped"
make_skipped_xml
exit_code=0
fi
exit $exit_code