Debian Codegraph @

ansible_collections/community/rabbitmq/tests/utils/shippable/shippable.sh

raw
1 #!/usr/bin/env bash
2
3 set -o pipefail -eux
4
5 declare -a args
6 IFS='/:' read -ra args <<< "$1"
7
8 ansible_version="${args[0]}"
9 script="${args[1]}"
10
11 function join {
12 local IFS="$1";
13 shift;
14 echo "$*";
15 }
16
17 # Ensure we can write other collections to this dir
18 sudo chown "$(whoami)" "${PWD}/../../"
19
20 test="$(join / "${args[@]:1}")"
21 docker images ansible/ansible
22 docker images quay.io/ansible/*
23 docker ps
24
25 for container in $(docker ps --format '{{.Image}} {{.ID}}' | grep -v -e '^drydock/' -e '^quay.io/ansible/azure-pipelines-test-container:' | sed 's/^.* //'); do
26 docker rm -f "${container}" || true # ignore errors
27 done
28
29 docker ps
30
31 if [ -d /home/shippable/cache/ ]; then
32 ls -la /home/shippable/cache/
33 fi
34
35 command -v python
36 python -V
37
38 function retry
39 {
40 # shellcheck disable=SC2034
41 for repetition in 1 2 3; do
42 set +e
43 "$@"
44 result=$?
45 set -e
46 if [ ${result} == 0 ]; then
47 return ${result}
48 fi
49 echo "@* -> ${result}"
50 done
51 echo "Command '@*' failed 3 times!"
52 exit 1
53 }
54
55 command -v pip
56 pip --version
57 pip list --disable-pip-version-check
58 if [ "${ansible_version}" == "devel" ]; then
59 retry pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
60 else
61 retry pip install "https://github.com/ansible/ansible/archive/stable-${ansible_version}.tar.gz" --disable-pip-version-check
62 fi
63
64
65 if [ "${SHIPPABLE_BUILD_ID:-}" ]; then
66 export ANSIBLE_COLLECTIONS_PATHS="${HOME}/.ansible"
67 SHIPPABLE_RESULT_DIR="$(pwd)/shippable"
68 TEST_DIR="${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/rabbitmq"
69 mkdir -p "${TEST_DIR}"
70 # shellcheck disable=SC2153
71 cp -aT "${SHIPPABLE_BUILD_DIR}" "${TEST_DIR}"
72 cd "${TEST_DIR}"
73 else
74 # AZP
75 export ANSIBLE_COLLECTIONS_PATHS="$PWD/../../../"
76 fi
77
78 # START: HACK install integration test dependencies
79 if [ "${script}" != "units" ] && [ "${script}" != "sanity" ] && [ "${ansible_version}" != "2.9" ]; then
80 retry ansible-galaxy -vvv collection install community.general
81 fi
82 # END: HACK
83
84
85 export PYTHONIOENCODING='utf-8'
86
87 if [ "${JOB_TRIGGERED_BY_NAME:-}" == "nightly-trigger" ]; then
88 COVERAGE=yes
89 COMPLETE=yes
90 fi
91
92 if [ -n "${COVERAGE:-}" ]; then
93 # on-demand coverage reporting triggered by setting the COVERAGE environment variable to a non-empty value
94 export COVERAGE="--coverage"
95 elif [[ "${COMMIT_MESSAGE}" =~ ci_coverage ]]; then
96 # on-demand coverage reporting triggered by having 'ci_coverage' in the latest commit message
97 export COVERAGE="--coverage"
98 else
99 # on-demand coverage reporting disabled (default behavior, always-on coverage reporting remains enabled)
100 export COVERAGE="--coverage-check"
101 fi
102
103 if [ -n "${COMPLETE:-}" ]; then
104 # disable change detection triggered by setting the COMPLETE environment variable to a non-empty value
105 export CHANGED=""
106 elif [[ "${COMMIT_MESSAGE}" =~ ci_complete ]]; then
107 # disable change detection triggered by having 'ci_complete' in the latest commit message
108 export CHANGED=""
109 else
110 # enable change detection (default behavior)
111 export CHANGED="--changed"
112 fi
113
114 if [ "${IS_PULL_REQUEST:-}" == "true" ]; then
115 # run unstable tests which are targeted by focused changes on PRs
116 export UNSTABLE="--allow-unstable-changed"
117 else
118 # do not run unstable tests outside PRs
119 export UNSTABLE=""
120 fi
121
122 # remove empty core/extras module directories from PRs created prior to the repo-merge
123 find plugins -type d -empty -print -delete
124
125 function cleanup
126 {
127 # for complete on-demand coverage generate a report for all files with no coverage on the "sanity/5" job so we only have one copy
128 if [ "${COVERAGE}" == "--coverage" ] && [ "${CHANGED}" == "" ] && [ "${test}" == "sanity/5" ]; then
129 stub="--stub"
130 # trigger coverage reporting for stubs even if no other coverage data exists
131 mkdir -p tests/output/coverage/
132 else
133 stub=""
134 fi
135
136 if [ -d tests/output/coverage/ ]; then
137 if find tests/output/coverage/ -mindepth 1 -name '.*' -prune -o -print -quit | grep -q .; then
138 process_coverage='yes' # process existing coverage files
139 elif [ "${stub}" ]; then
140 process_coverage='yes' # process coverage when stubs are enabled
141 else
142 process_coverage=''
143 fi
144
145 if [ "${process_coverage}" ]; then
146 # use python 3.7 for coverage to avoid running out of memory during coverage xml processing
147 # only use it for coverage to avoid the additional overhead of setting up a virtual environment for a potential no-op job
148 virtualenv --python /usr/bin/python3.7 ~/ansible-venv
149 set +ux
150 . ~/ansible-venv/bin/activate
151 set -ux
152
153 # shellcheck disable=SC2086
154 ansible-test coverage xml --color -v --requirements --group-by command --group-by version ${stub:+"$stub"}
155 cp -a tests/output/reports/coverage=*.xml "$SHIPPABLE_RESULT_DIR/codecoverage/"
156
157 if [ "${ansible_version}" != "2.9" ]; then
158 # analyze and capture code coverage aggregated by integration test target
159 ansible-test coverage analyze targets generate -v "$SHIPPABLE_RESULT_DIR/testresults/coverage-analyze-targets.json"
160 fi
161
162 # upload coverage report to codecov.io only when using complete on-demand coverage
163 if [ "${COVERAGE}" == "--coverage" ] && [ "${CHANGED}" == "" ]; then
164 for file in tests/output/reports/coverage=*.xml; do
165 flags="${file##*/coverage=}"
166 flags="${flags%-powershell.xml}"
167 flags="${flags%.xml}"
168 # remove numbered component from stub files when converting to tags
169 flags="${flags//stub-[0-9]*/stub}"
170 flags="${flags//=/,}"
171 flags="${flags//[^a-zA-Z0-9_,]/_}"
172
173 bash <(curl -s https://ansible-ci-files.s3.us-east-1.amazonaws.com/codecov/codecov.sh) \
174 -f "${file}" \
175 -F "${flags}" \
176 -n "${test}" \
177 -t 31525df8-da26-4e61-b31f-05e3df48b091 \
178 -X coveragepy \
179 -X gcov \
180 -X fix \
181 -X search \
182 -X xcode \
183 || echo "Failed to upload code coverage report to codecov.io: ${file}"
184 done
185 fi
186 fi
187 fi
188
189 if [ -d tests/output/junit/ ]; then
190 cp -aT tests/output/junit/ "$SHIPPABLE_RESULT_DIR/testresults/"
191 fi
192
193 if [ -d tests/output/data/ ]; then
194 cp -a tests/output/data/ "$SHIPPABLE_RESULT_DIR/testresults/"
195 fi
196
197 if [ -d tests/output/bot/ ]; then
198 cp -aT tests/output/bot/ "$SHIPPABLE_RESULT_DIR/testresults/"
199 fi
200 }
201
202 if [ "${SHIPPABLE_BUILD_ID:-}" ]; then trap cleanup EXIT; fi
203
204 if [[ "${COVERAGE:-}" == "--coverage" ]]; then
205 timeout=60
206 else
207 timeout=50
208 fi
209
210 ansible-test env --dump --show --timeout "${timeout}" --color -v
211
212 if [ "${SHIPPABLE_BUILD_ID:-}" ]; then "tests/utils/shippable/check_matrix.py"; fi
213 "tests/utils/shippable/${script}.sh" "${test}"