Debian Codegraph @

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

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