Repository navigation
Expand file tree
/
Copy pathpatch-image.sh
More file actions
executable file
·86 lines (68 loc) · 2.88 KB
/
Copy pathpatch-image.sh
File metadata and controls
executable file
·86 lines (68 loc) · 2.88 KB
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
#!/usr/bin/bash
set -euxo pipefail
patch_file="/tmp/${PATCH_LIST}"
while IFS= read -r line
do
EXEC=$(echo "$line" | cut -d " " -f1)
echo "$EXEC"
case $EXEC in
REBUILD)
# each line is in the form "exec project_dir refsspec" where:
# - project is the last part of the project url including the org,
# for example openstack/ironic
# - refspec is the gerrit refspec of the patch we want to test,
# for example refs/changes/67/759567/1
PROJECT=$(echo "$line" | cut -d " " -f2)
PROJ_NAME=$(echo "$PROJECT" | cut -d "/" -f2)
PROJ_URL="https://opendev.org/${PROJECT}"
REFSPEC=$(echo "$line" | cut -d " " -f3)
cd /tmp
git clone "$PROJ_URL"
cd "$PROJ_NAME"
git fetch "$PROJ_URL" "$REFSPEC"
git checkout FETCH_HEAD
SKIP_GENERATE_AUTHORS=1 SKIP_WRITE_GIT_CHANGELOG=1 ${PYTHON_VERSION} setup.py sdist
${PYTHON_VERSION} -m pip install --prefix /usr dist/*.tar.gz
# clean local repo
cd ..
rm -fr "$PROJ_NAME"
;;
PATCH)
PYTHON_LIB_PATH=$(${PYTHON_VERSION} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
PATCH_URL=$(echo "$line" | cut -d " " -f3)
cd /tmp
wget --content-disposition "$PATCH_URL"
ZIPPED_PATCH_FILE=$(find . -maxdepth 1 -name '*.zip' -printf '%T@ %p\n' | sort -n | tail -n 1 | cut -d' ' -f2)
unzip "$ZIPPED_PATCH_FILE"
PATCH_FILE=$(basename "$ZIPPED_PATCH_FILE" .zip)
# The container contains the installed package, not its source
# tree. Install requirements added by the patch separately.
CHANGED_REQUIREMENTS_FILE="${PATCH_FILE}.requirements"
awk '
/^diff --git / {
in_requirements = ($0 ~ / b\/requirements\.txt$/)
next
}
in_requirements && /^\+\+\+ / { next }
in_requirements && /^\+/ {
requirement = substr($0, 2)
if (requirement !~ /^[[:space:]]*($|#)/) print requirement
}
' "$PATCH_FILE" > "$CHANGED_REQUIREMENTS_FILE"
if [ -s "$CHANGED_REQUIREMENTS_FILE" ]; then
echo "Installing requirements added by $PATCH_FILE"
${PYTHON_VERSION} -m pip install --no-cache-dir \
-r "$CHANGED_REQUIREMENTS_FILE"
fi
rm -f "$CHANGED_REQUIREMENTS_FILE"
patch -d"${PYTHON_LIB_PATH}" -f -N -p1 < "$PATCH_FILE" || true
# clean patch file
rm -f "$PATCH_FILE"
;;
*)
echo "$EXEC operation not supported, closing."
exit 1
;;
esac
done < "$patch_file"
cd /