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
|
#!/bin/bash
opt_dry_run=0
opt_timings=0
python='false'
cache_dir='.cache'
wheels_cache="$cache_dir/wheels"
downloads_cache="$cache_dir/downloads"
# Usage: parse_opts args "$@"
#
# `$args` will be set to unhandled options and non-option arguments.
#
# Consumed options:
#
# --dry-run/-n: don't execute run/run_eval commands (print them instead)
# --debug/-d: enable `set -x` for debugging script
# --: stop options processing
#
# Tip: to update $@ after the call, use:
# parse_opts args "$@" && set -- "${args[@]}"
parse_opts()
{
args_varname="$1"
shift
local _args=()
while [ $# -ne 0 ]
do
case "$1" in
--dry-run|-n)
opt_dry_run=1
;;
--debug|-d)
set -x
;;
--)
shift
_args+=("$@")
break
;;
*)
_args+=("$1")
;;
esac
shift
done
eval "$args_varname=(\"\${_args[@]}\")"
}
info()
{
color=34
case "$1" in
-c*)
color="${1#-c}"
shift
;;
esac
if [ -t 2 -o "x$CI" = "xtrue" ]
then
echo "[${color}m$@[0m" 1>&2
else
echo "$@" 1>&2
fi
}
err()
{
info -c31 "$@"
}
die()
{
code=$?
if [ $# -ne 0 ]
then
code="$1"
shift
fi
if [ $# -ne 0 ]
then
err "$@"
fi
exit "$code"
}
run()
{
if [ $opt_dry_run -eq 0 -a "x$CI" = "xtrue" ]
then
echo -n '::group::' 1>&2
fi
info "$(printf "%q " "$@")"
[ $opt_dry_run -ne 0 ] && return
if [ $opt_timings -ne 0 ]
then
time "$@"
code=$?
else
"$@"
code=$?
fi
if [ "x$CI" = "xtrue" ]
then
echo "::endgroup::" 1>&2
fi
return $code
}
run_eval()
{
info "$@"
[ $opt_dry_run -ne 0 ] && return
if [ $opt_timings -ne 0 ]
then
time eval "$@"
else
eval "$@"
fi
}
sha1sum()
{
kernel="$(uname -s)" || die
if [ "$kernel" = 'Darwin' ]
then
shasum "$@"
else
command sha1sum "$@"
fi
}
get_base_devel()
{
run "$python" -m plover_build_utils.get_pip -c reqs/constraints.txt -r reqs/bootstrap.txt "$@"
}
install_wheels()
{
run "$python" -m plover_build_utils.install_wheels --disable-pip-version-check "$@"
}
bootstrap_dist()
{
wheel="$1"
shift
get_base_devel "$wheel" --no-deps "$@" || die
# Install plover's dependencies
install_wheels \
-c reqs/constraints.txt \
-r reqs/dist.txt \
-r reqs/dist_extra_gui_qt.txt \
-r reqs/dist_extra_log.txt \
"$@" || die
# Avoid caching Plover's wheel.
if [ -f "$wheels_cache/$(basename "$wheel")" ]; then
info "Removing cached wheel: $wheels_cache/$(basename "$wheel")"
run rm "$wheels_cache/$(basename "$wheel")"
else
info "Wheel was not cached so no need to remove it: $wheels_cache/$(basename "$wheel")"
fi
}
osx_standalone_python()
{
[[ $# -eq 6 ]] || return 1
dest="$1"
py_version="$2"
py_macos="$3"
py_sha1="$4"
reloc_py_url="$5"
reloc_py_sha1="$6"
py_framework_dir="$dest/Python.framework"
[[ ! -e "$py_framework_dir" ]] || return 1
run mkdir -p "$dest"
run "$python" -m plover_build_utils.download "https://www.python.org/ftp/python/$py_version/python-$py_version-macos$py_macos.pkg" "$py_sha1"
reloc_py_zip="$(run "$python" -m plover_build_utils.download "$reloc_py_url" "$reloc_py_sha1")"
run unzip -d "$dest" "$reloc_py_zip"
reloc_py_dir="$(echo -n "$dest"/relocatable-python-*/)"
run "$python" "$reloc_py_dir/make_relocatable_python_framework.py" \
--baseurl="file://$PWD/$downloads_cache/%s/../python-%s-macos%s.pkg" \
--python-version="$py_version" --os-version="$py_macos" \
--destination="$dest" \
--without-pip \
;
run ln -s 'python3' "$py_framework_dir/Versions/Current/bin/python"
run rm -rf "$reloc_py_dir"
}
packaging_checks()
{
run rm -rf dist
# Check PEP 517/518 support.
run "$python" -m build --sdist --wheel .
# Validate distributions.
run "$python" -m twine check --strict dist/*
# Check manifest.
run "$python" -m check_manifest -v
}
git_tree_sha1()
{
if [ "x$1" = "x-d" ]
then
debug=1
shift
else
debug=1
fi
refspec="$1"
shift
# Build excludes list.
excludes=()
for skiplist in "$@"
do
IFS=$'\r\n' read -r -d '{EOF}' -a patterns <"$skiplist" || die
excludes+=("${patterns[@]/#/:!:}")
done
if [ $debug -eq 1 ]
then
info "excludes [${#excludes[@]}]"
echo "${excludes[@]}" 1>&2
fi
# Build source tree listing.
IFS=$'\r\n' sources=($(git ls-files "${excludes[@]}")) || die
if [ $debug -eq 1 ]
then
info "sources [${#sources[@]}]:"
echo "${sources[@]}" 1>&2
fi
# Build git tree listing.
tree="$(git ls-tree "$refspec" "${sources[@]}")" || die
if [ $debug -eq 1 ]
then
info "tree: [$(wc -l <<<"$tree")]"
echo "${tree}" 1>&2
fi
# Calculate tree SHA1.
sha1="$(sha1sum <<<"$tree")" || die
sha1="${sha1%% *}"
if [ $debug -eq 1 ]
then
info "sha1: $sha1"
fi
echo "$sha1"
}
release_prepare()
{
[ $# -eq 1 ] || die 1 'expecting one argument: the new version'
run "$python" setup.py patch_version "$1"
run git add plover/__init__.py
run git add doc/conf.py
run towncrier build --version "$1" --yes
}
release_finalize()
{
[ $# -eq 0 ] || die 1 'expecting no argument'
version="$("$python" setup.py --version)"
message="Release version $version"
tag="v$version"
run git commit -m "$message"
run git tag -m "$message" "$tag"
cat <<EOF
# now all that's left is to push to GitHub:
# first push the release commit:
git push
# and once the build was successful, assuming \`origin\` is the correct remote, push the tag:
git push origin "$tag"
EOF
}
parse_opts args "$@"
set -- "${args[@]}"
|