forked from seapath/ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch-yocto.sh
executable file
·183 lines (161 loc) · 5.06 KB
/
launch-yocto.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
#!/bin/bash
#
# Copyright (C) 2023 Savoir-faire Linux, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# This script download the sources of a specific pull request,
# then test it and upload a report given the test results.
if [ "${RUNNER_DEBUG}" == "1" ] ; then
set -x
fi
set -e
die() {
echo "CI internal failure : $*" 1>&2
exit 1
}
# default variables
SEAPATH_BASE_REPO="github.com/seapath"
SEAPATH_SSH_BASE_REPO="[email protected]:seapath"
ANSIBLE_INVENTORY="/tmp/ci-private-files/ci_yocto_standalone.yaml"
CQFD_EXTRA_RUN_ARGS="-e ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY} -v /home/github/ci-private-files:/tmp/ci-private-files"
PRIVATE_KEYFILE_PATH="/tmp/ci-private-files/ssh_keys/ci_rsa"
export CQFD_EXTRA_RUN_ARGS
# Standard help message
usage()
{
cat <<EOF
This script is the main launcher for the SEAPATH CI.
It is separated in many functions in order to display logs properly.
They should be called one after another.
USAGE:
./launch.sh <init|conf|system|report>
DESCRIPTION:
- init : download and prepare the sources.
- conf : configure SEAPATH.
- system : launch system tests and gather results.
- report: build and upload the test report.
EOF
}
# Download and prepare the pull request sources
initialization() {
if ! type -p cqfd > /dev/null; then
die "cqfd not found"
fi
# Get sources
git clone -q "https://${SEAPATH_BASE_REPO}/ansible"
cd ansible
git fetch -q origin "${GITHUB_REF}"
git checkout -q FETCH_HEAD
echo "Pull request sources got succesfully"
# Prepare ansible repository
cqfd init
cqfd -b prepare
echo "Sources prepared succesfully"
}
# Launch SEAPATH configuration and hardening
configure_seapath() {
cd ansible
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
--skip-tags "package-install" \
playbooks/ci_standalone_setup.yaml
echo "SEAPATH set up succesfully"
}
# Prepare and launch cukinia test
# Send the result of the tests as return code
launch_system_tests() {
cd ansible
cqfd run ansible-playbook \
--key-file "${PRIVATE_KEYFILE_PATH}" \
-e machines_tested=hypervisors \
playbooks/ci_common_tests.yaml \
playbooks/ci_hypervisor_tests.yaml
echo "System tests launched successfully"
# Generate test report part
INCLUDE_DIR=${WORK_DIR}/ci/report-generator/include
mkdir "$INCLUDE_DIR"
mv "${WORK_DIR}"/ansible/playbooks/common/yoctoCI/cukinia_common.xml \
"${WORK_DIR}"/ansible/playbooks/hypervisor/yoctoCI/cukinia_hypervisor.xml \
"$INCLUDE_DIR"
cd "${WORK_DIR}/ci/report-generator"
cqfd -q init
if ! cqfd -q -b generate_test_part; then
die "cqfd error"
fi
# Check for kernel backtrace error. This is a random error so it must not
# stop the CI but just display a warning
# See https://github.com/seapath/ansible/issues/164
if grep '<failure' "$INCLUDE_DIR"/*.xml | grep -q '00080'; then
echo -e "\033[0;33mWarning :\033[0m kernel back trace detected, see \
https://github.com/seapath/ansible/issues/164"
fi
# Display test results
if grep '<failure' "$INCLUDE_DIR"/*.xml | grep -q -v '00080'; then
echo "Test fails, See test report in the section 'Upload test report'"
exit 1
else
echo "All tests pass"
exit 0
fi
}
# Generate the test report and upload it
generate_report() {
# Generate pdf
cd "${WORK_DIR}/ci/report-generator"
if ! CQFD_EXTRA_RUN_ARGS="" cqfd -q run; then
die "cqfd error"
fi
echo "Test report generated successfully"
# Upload report
PR_N=$(echo "$GITHUB_REF" | cut -d '/' -f 3)
TIME=$(date +%F_%Hh%Mm%S)
REPORT_NAME="test-report_${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}_${TIME}.pdf"
REPORT_DIR="${WORK_DIR}/reports/docs/reports/PR-${PR_N}"
REPORT_BRANCH="reports-PR${PR_N}"
# The CI repo have one branche per pull request.
# If the report is the first of the PR, the branch need to be created.
# Otherwise, it just have to be switched on.
git clone -q --depth 1 -b reports-base-commit \
--config core.sshCommand="ssh -i ~/ci-private-files/ssh_keys/ci_rsa" \
"${SEAPATH_SSH_BASE_REPO}/ci.git" "$WORK_DIR/reports"
cd "$WORK_DIR/reports"
if ! git ls-remote origin "$REPORT_BRANCH" | grep -q "$REPORT_BRANCH"; then
git branch "$REPORT_BRANCH"
else
git fetch -q origin "$REPORT_BRANCH":"$REPORT_BRANCH"
fi
git switch -q "$REPORT_BRANCH"
mkdir -p "$REPORT_DIR"
mv "${WORK_DIR}"/ci/report-generator/test-report.pdf "$REPORT_DIR/$REPORT_NAME"
git config --local user.email "[email protected]"
git config --local user.name "Seapath CI"
git config --local core.sshCommand "ssh -i ~/ci-private-files/ssh_keys/ci_rsa"
git add "$REPORT_DIR/$REPORT_NAME"
git commit -q -m "upload report $REPORT_NAME"
git push -q origin "$REPORT_BRANCH"
echo "Test report uploaded successfully"
echo See test Report at \
"https://${SEAPATH_BASE_REPO}/ci/blob/${REPORT_BRANCH}/docs/reports/PR-${PR_N}/${REPORT_NAME}"
}
case "$1" in
init)
initialization
exit 0
;;
conf)
configure_seapath
exit 0
;;
system)
launch_system_tests
exit 0
;;
report)
generate_report
exit 0
;;
*)
usage
die "Unknown command"
;;
esac