Debian Codegraph @

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