blob: 001959c7e0174d8aca9767cb8503f5f92dfeb211 (
plain)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
#!/bin/bash -eu
# Script to dual-home the upstream and downstream Collection in a single repo
#
# This script will build or test a downstream collection, removing any
# upstream components that will not ship in the downstream release
#
# NOTES:
# - All functions are prefixed with f_ so it's obvious where they come
# from when in use throughout the script
DOWNSTREAM_VERSION="2.3.0"
KEEP_DOWNSTREAM_TMPDIR="${KEEP_DOWNSTREAM_TMPDIR:-''}"
INSTALL_DOWNSTREAM_COLLECTION_PATH="${INSTALL_DOWNSTREAM_COLLECTION_PATH:-}"
_build_dir=""
f_log_info()
{
printf "%s:LOG:INFO: %s\n" "${0}" "${1}"
}
f_show_help()
{
printf "Usage: downstream.sh [OPTION]\n"
printf "\t-s\t\tCreate a temporary downstream release and perform sanity tests.\n"
printf "\t-u\t\tCreate a temporary downstream release and perform units tests.\n"
printf "\t-i\t\tCreate a temporary downstream release and perform integration tests.\n"
printf "\t-m\t\tCreate a temporary downstream release and perform molecule tests.\n"
printf "\t-b\t\tCreate a downstream release and stage for release.\n"
printf "\t-r\t\tCreate a downstream release and publish release.\n"
}
f_text_sub()
{
# Switch FQCN and dependent components
OKD_sed_files="${_build_dir}/README.md ${_build_dir}/CHANGELOG.rst ${_build_dir}/changelogs/config.yaml ${_build_dir}/ci/downstream.sh ${_build_dir}/galaxy.yml"
# shellcheck disable=SC2068
for okd_file in ${OKD_sed_files[@]}; do sed -i.bak "s/OKD/OpenShift/g" "${okd_file}"; done
sed -i.bak "s/============================/==================================/" "${_build_dir}/CHANGELOG.rst"
sed -i.bak "s/Ansible Galaxy/Automation Hub/" "${_build_dir}/README.md"
sed -i.bak "s/community-okd/redhat-openshift/" "${_build_dir}/Makefile"
sed -i.bak "s/community\/okd/redhat\/openshift/" "${_build_dir}/Makefile"
sed -i.bak "s/^VERSION\:/VERSION: ${DOWNSTREAM_VERSION}/" "${_build_dir}/Makefile"
sed -i.bak "s/name\:.*$/name: openshift/" "${_build_dir}/galaxy.yml"
sed -i.bak "s/namespace\:.*$/namespace: redhat/" "${_build_dir}/galaxy.yml"
sed -i.bak "s/Kubernetes/OpenShift/g" "${_build_dir}/galaxy.yml"
sed -i.bak "s/^version\:.*$/version: ${DOWNSTREAM_VERSION}/" "${_build_dir}/galaxy.yml"
sed -i.bak "/STARTREMOVE/,/ENDREMOVE/d" "${_build_dir}/README.md"
sed -i.bak "s/[[:space:]]okd:$/ openshift:/" ${_build_dir}/meta/runtime.yml
find "${_build_dir}" -type f ! -name galaxy.yml -exec sed -i.bak "s/community\.okd/redhat\.openshift/g" {} \;
find "${_build_dir}" -type f -name "*.bak" -delete
}
f_prep()
{
f_log_info "${FUNCNAME[0]}"
# Array of excluded files from downstream build (relative path)
_file_exclude=(
)
# Files to copy downstream (relative repo root dir path)
_file_manifest=(
CHANGELOG.rst
galaxy.yml
LICENSE
README.md
Makefile
setup.cfg
.yamllint
requirements.txt
requirements.yml
test-requirements.txt
)
# Directories to recursively copy downstream (relative repo root dir path)
_dir_manifest=(
changelogs
ci
meta
molecule
plugins
tests
)
# Temp build dir
_tmp_dir=$(mktemp -d)
_start_dir="${PWD}"
_build_dir="${_tmp_dir}/ansible_collections/redhat/openshift"
mkdir -p "${_build_dir}"
}
f_cleanup()
{
f_log_info "${FUNCNAME[0]}"
if [[ -n "${_build_dir}" ]]; then
if [[ -n ${KEEP_DOWNSTREAM_TMPDIR} ]]; then
if [[ -d ${_build_dir} ]]; then
rm -fr "${_build_dir}"
fi
fi
else
exit 0
fi
}
# Exit and handle cleanup processes if needed
f_exit()
{
f_cleanup
exit "$0"
}
f_create_collection_dir_structure()
{
f_log_info "${FUNCNAME[0]}"
# Create the Collection
for f_name in "${_file_manifest[@]}";
do
cp "./${f_name}" "${_build_dir}/${f_name}"
done
for d_name in "${_dir_manifest[@]}";
do
cp -r "./${d_name}" "${_build_dir}/${d_name}"
done
if [ -n "${_file_exclude:-}" ]; then
for exclude_file in "${_file_exclude[@]}";
do
if [[ -f "${_build_dir}/${exclude_file}" ]]; then
rm -f "${_build_dir}/${exclude_file}"
fi
done
fi
}
f_handle_doc_fragments_workaround()
{
f_log_info "${FUNCNAME[0]}"
local install_collections_dir="${_build_dir}/collections/"
local temp_fragments_json="${_tmp_dir}/fragments.json"
local temp_start="${_tmp_dir}/startfile.txt"
local temp_end="${_tmp_dir}/endfile.txt"
local rendered_fragments="./rendereddocfragments.txt"
# FIXME: Check Python interpreter from environment variable to work with prow
PYTHON=${DOWNSTREAM_BUILD_PYTHON:-/usr/bin/python3.6}
f_log_info "Using Python interpreter: ${PYTHON}"
# Modules with inherited doc fragments from kubernetes.core that need
# rendering to deal with Galaxy/AH lack of functionality.
# shellcheck disable=SC2207
_doc_fragment_modules=($("${PYTHON}" "${_start_dir}/ci/doc_fragment_modules.py" -c "${_start_dir}"))
# Build the collection, export docs, render them, stitch it all back together
pushd "${_build_dir}" || return
ansible-galaxy collection build
ansible-galaxy collection install -p "${install_collections_dir}" ./*.tar.gz
rm ./*.tar.gz
for doc_fragment_mod in "${_doc_fragment_modules[@]}"
do
local module_py="plugins/modules/${doc_fragment_mod}.py"
f_log_info "Processing doc fragments for ${module_py}"
# We need following variable for ansible-doc only
# shellcheck disable=SC2097,SC2098
ANSIBLE_COLLECTIONS_PATH="${install_collections_dir}" \
ANSIBLE_COLLECTIONS_PATHS="${ANSIBLE_COLLECTIONS_PATH}:${install_collections_dir}" \
ansible-doc -j "redhat.openshift.${doc_fragment_mod}" > "${temp_fragments_json}"
"${PYTHON}" "${_start_dir}/ci/downstream_fragments.py" "redhat.openshift.${doc_fragment_mod}" "${temp_fragments_json}"
sed -n '/STARTREMOVE/q;p' "${module_py}" > "${temp_start}"
sed '1,/ENDREMOVE/d' "${module_py}" > "${temp_end}"
cat "${temp_start}" "${rendered_fragments}" "${temp_end}" > "${module_py}"
done
rm -f "${rendered_fragments}"
rm -fr "${install_collections_dir}"
popd
}
f_copy_collection_to_working_dir()
{
f_log_info "${FUNCNAME[0]}"
# Copy the Collection build result into original working dir
f_log_info "copying built collection *.tar.gz into ./"
cp "${_build_dir}"/*.tar.gz ./
# Install downstream collection into provided path
if [[ -n ${INSTALL_DOWNSTREAM_COLLECTION_PATH} ]]; then
f_log_info "Install built collection *.tar.gz into ${INSTALL_DOWNSTREAM_COLLECTION_PATH}"
ansible-galaxy collection install -p "${INSTALL_DOWNSTREAM_COLLECTION_PATH}" "${_build_dir}"/*.tar.gz
fi
rm -f "${_build_dir}"/*.tar.gz
}
f_common_steps()
{
f_log_info "${FUNCNAME[0]}"
f_prep
f_create_collection_dir_structure
f_text_sub
f_handle_doc_fragments_workaround
}
# Run the test sanity scanerio
f_test_sanity_option()
{
f_log_info "${FUNCNAME[0]}"
f_common_steps
pushd "${_build_dir}" || return
if command -v docker &> /dev/null
then
make sanity
else
SANITY_TEST_ARGS="--venv --color" make sanity
fi
f_log_info "SANITY TEST PWD: ${PWD}"
make sanity
popd || return
f_cleanup
}
# Run the test integration
f_test_integration_option()
{
f_log_info "${FUNCNAME[0]}"
f_common_steps
pushd "${_build_dir}" || return
f_log_info "INTEGRATION TEST WD: ${PWD}"
make molecule
popd || return
f_cleanup
}
# Run the test units
f_test_units_option()
{
f_log_info "${FUNCNAME[0]}"
f_common_steps
pushd "${_build_dir}" || return
if command -v docker &> /dev/null
then
make units
else
UNITS_TEST_ARGS="--venv --color" make units
fi
f_log_info "UNITS TEST PWD: ${PWD}"
make units
popd || return
f_cleanup
}
# Run the build scanerio
f_build_option()
{
f_log_info "${FUNCNAME[0]}"
f_common_steps
pushd "${_build_dir}" || return
f_log_info "BUILD WD: ${PWD}"
make build
popd || return
f_copy_collection_to_working_dir
f_cleanup
}
# If no options are passed, display usage and exit
if [[ "${#}" -eq "0" ]]; then
f_show_help
f_exit 0
fi
# Handle options
while getopts ":siurb" option
do
case $option in
s)
f_test_sanity_option
;;
i)
f_test_integration_option
;;
u)
f_test_units_option
;;
r)
f_release_option
;;
b)
f_build_option
;;
*)
printf "ERROR: Unimplemented option chosen.\n"
f_show_help
f_exit 1
;; # Default.
esac
done
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|