-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
get-dependencies.sh
executable file
·131 lines (103 loc) · 2.63 KB
/
get-dependencies.sh
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
#!/usr/bin/env bash
set -euo pipefail
BUILDNAME="${1:-}"
GITREPO="${2:-}"
GITREF="${3:-}"
OPT_DEPSPEC=("${@}")
OPT_DEPSPEC=("${OPT_DEPSPEC[@]:3}")
declare -A DEPS=(
[jq]=jq
[yq]=yq
[mktemp]=mktemp
)
ROOT=$(git rev-parse --show-toplevel 2>/dev/null || dirname "$(readlink -f "${0}")")
CONFIG="${ROOT}/config.yml"
# ----
SELF=$(basename "$(readlink -f "${0}")")
log() {
echo "[${SELF}]" "${@}"
}
err() {
log >&2 "${@}"
exit 1
}
for dep in "${!DEPS[@]}"; do
command -v "${dep}" >/dev/null 2>&1 || err "Missing dependency: ${DEPS["${dep}"]}"
done
CONFIGJSON=$(cat "${CONFIG}")
if [[ -n "${BUILDNAME}" ]]; then
yq -e ".builds[\"${BUILDNAME}\"]" >/dev/null 2>&1 <<< "${CONFIGJSON}" \
|| err "Invalid build name"
else
BUILDNAME=$(yq -r '.builds | keys | first' <<< "${CONFIGJSON}")
fi
read -r gitrepo gitref \
< <(yq -r '.git | "\(.repo) \(.ref)"' <<< "${CONFIGJSON}")
read -r implementation pythonversion platform \
< <(yq -r ".builds[\"${BUILDNAME}\"] | \"\(.implementation) \(.pythonversion) \(.platform)\"" <<< "${CONFIGJSON}")
gitrepo="${GITREPO:-${gitrepo}}"
gitref="${GITREF:-${gitref}}"
dependency_override=($(yq -r ".builds[\"${BUILDNAME}\"].dependency_override[]" <<< "${CONFIGJSON}"))
# ----
# shellcheck disable=SC2064
TEMP=$(mktemp -d) && trap "rm -rf '${TEMP}'" EXIT || exit 255
DIR_REPO="${TEMP}/source.git"
get_sources() {
log "Getting sources"
git \
-c advice.detachedHead=false \
clone \
"${gitrepo}" \
"${DIR_REPO}"
log "Commit information"
git \
-c core.pager=cat \
-C "${DIR_REPO}" \
log \
-1 \
--pretty=full \
"${gitref}"
}
get_deps() {
pushd "${TEMP}"
log "Downloading wheels"
python -m pip install \
--disable-pip-version-check \
--root-user-action=ignore \
--isolated \
--no-cache-dir \
--check-build-dependencies \
--ignore-installed \
--only-binary=:all: \
--implementation="${implementation}" \
--python-version="${pythonversion}" \
--platform="${platform}" \
--target=. \
--dry-run \
--report=report.json \
"git+file://${DIR_REPO}@${gitref}" \
"${dependency_override[@]}" \
"${OPT_DEPSPEC[@]}"
log "Generating lockfile for build ${BUILDNAME}"
yq -y -C \
'
[
.install[]
| select(.is_direct != true)
| .download_info.archive_info.hash |= sub("^(?<hash>[^=]+)="; "\(.hash):")
| {
key: .metadata.name,
value: "\(.metadata.version) --hash=\(.download_info.archive_info.hash)"
}
]
| sort_by(.key | ascii_upcase)
| from_entries
| {"dependencies": .}
' \
report.json
}
build() {
get_sources
get_deps
}
build