-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathutils.sh
175 lines (144 loc) · 3.74 KB
/
utils.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
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
# shellcheck shell=bash
#
# Collection of functions used by ~lsstsw builder
#
print_error() {
>&2 echo -e "$@"
}
fail() {
local code=${2:-1}
[[ -n $1 ]] && print_error "$1"
exit "$code"
}
config_curl() {
# Prefer system curl; user-installed ones sometimes behave oddly
if [[ -x /usr/bin/curl ]]; then
CURL=${CURL:-/usr/bin/curl}
else
CURL=${CURL:-curl}
fi
# disable curl progress meter unless running under a tty -- this is intended to
# reduce the amount of console output when running under CI
CURL_OPTS=('-#')
if [[ ! -t 1 ]]; then
CURL_OPTS=('-sS')
fi
# curl will exit 0 on 404 without the fail flag
CURL_OPTS+=('--fail')
}
# funcion to identify the platform
discover_platform() {
case $(uname -s) in
Linux*)
case $(uname -m) in
x86_64)
# shellcheck disable=SC2034
ana_platform='Linux-x86_64'
pkg_postfix='linux-64'
;;
aarch64)
# shellcheck disable=SC2034
ana_platform='Linux-aarch64'
pkg_postfix='linux-aarch64'
;;
esac
;;
Darwin*)
case $(uname -m) in
x86_64)
# shellcheck disable=SC2034
ana_platform='MacOSX-x86_64'
pkg_postfix='osx-64'
;;
arm64)
# shellcheck disable=SC2034
ana_platform='MacOSX-arm64'
pkg_postfix='osx-arm64'
;;
*)
fail "Cannot install miniconda: unsupported Darwin arch $(uname -m)"
;;
esac
;;
*)
fail "Cannot install miniconda: unsupported platform $(uname -s)"
;;
esac
}
# function used to deploy environment
deploy_scipipe_env() {
echo "--------------------- Deploying environment from scipipe_conda_env, git reference: ${LSST_SPLENV_REF}"
local conda_lockfile="conda-${pkg_postfix}.lock"
local lock_file="${LSSTSW}/env/${ENVREF}/${conda_lockfile}"
# conda environment reference
local env_url="https://raw.githubusercontent.com/lsst/scipipe_conda_env/${ENVREF}/etc/"
echo "::: conda lock file: ${lock_file}"
if [ -e "${lock_file}" ]; then
echo "::: conda lock file already present"
else
# if a branch or tag is provided, store the environment yaml inside the corresponding subfolder
mkdir -p "${lock_file%/*}"
echo "${env_url}/${conda_lockfile}"
$CURL "${CURL_OPTS[@]}" -# -L \
"${env_url}/${conda_lockfile}" \
--output "${lock_file}"
fi
(
# Install packages on which the stack is known to depend
# conda may leave behind lock files from an uncompleted package
# installation attempt. These need to be cleaned up before [re]attempting
# to install packages.
conda clean -y --all
ARGS=()
ARGS+=('create')
ARGS+=('--name' "$LSST_CONDA_ENV_NAME")
ARGS+=('-y')
ARGS+=("--file" "$lock_file")
# when running under CI
if [[ ! -t 1 ]]; then
ARGS+=("--quiet")
fi
run conda "${ARGS[@]}"
echo "Cleaning conda environment..."
conda clean -y -a > /dev/null
echo "done"
)
}
run() {
if [[ $DRYRUN == true ]]; then
echo "$@"
elif [[ $DEBUG == true ]]; then
(set -x; "$@")
else
if [[ $VERBOSE == true ]]; then
echo "[- -]" "$@"
fi
"$@"
fi
}
print_settings() {
local vars=(
BUILD
DISTRIBTAG
DEBUG
LSSTSW
LSSTSW_BUILD_DIR
)
# print env vars prefixed with ^EUPS
IFS=" " read -r -a eups_vars <<< "${!EUPS@}"
vars+=("${eups_vars[@]}")
for i in "${vars[@]}"
do
echo "${i}: ${!i}"
done
}
fetch_repos.yaml() {
local ref=${1:-main}
local output_file=${2:-$REPOSFILE}
local repo=${3:-$REPOSFILE_REPO}
local baseurl="https://raw.githubusercontent.com/${repo}/${ref}"
$CURL "${CURL_OPTS[@]}" \
-L \
"${baseurl}/etc/repos.yaml" \
-o "$output_file"
}