create_release.sh (tink-1.6.0) | : | create_release.sh (tink-1.6.1) | ||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
# This script creates the release artifacts of Tink Python which includes a | # This script creates the release artifacts of Tink Python which includes a | |||
# source distribution and binary wheels for Linux and macOS. All Python tests | # source distribution and binary wheels for Linux and macOS. All Python tests | |||
# are exectued for each binary wheel and the source distribution. | # are exectued for each binary wheel and the source distribution. | |||
set -euo pipefail | set -euo pipefail | |||
declare -a PYTHON_VERSIONS= | declare -a PYTHON_VERSIONS= | |||
PYTHON_VERSIONS+=("3.7") | PYTHON_VERSIONS+=("3.7") | |||
PYTHON_VERSIONS+=("3.8") | PYTHON_VERSIONS+=("3.8") | |||
# TODO(ckl): Enable when macOS solution is in place. | PYTHON_VERSIONS+=("3.9") | |||
#PYTHON_VERSIONS+=("3.9") | ||||
readonly PYTHON_VERSIONS | readonly PYTHON_VERSIONS | |||
readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')" | readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')" | |||
readonly TINK_BASE="${PWD}/.." | ||||
readonly TINK_SRC_PATH="${PWD}/.." | ||||
readonly TINK_VERSION="$(grep ^TINK "${TINK_SRC_PATH}/tink_version.bzl" \ | ||||
| awk '{gsub(/"/, "", $3); print $3}')" | ||||
readonly IMAGE_NAME="quay.io/pypa/manylinux2014_x86_64" | readonly IMAGE_NAME="quay.io/pypa/manylinux2014_x86_64" | |||
readonly IMAGE_DIGEST="sha256:d4604fe14cb0d691031f202ee7daf240e6d463297b060e2de6 0994d82a8f22ac" | readonly IMAGE_DIGEST="sha256:d4604fe14cb0d691031f202ee7daf240e6d463297b060e2de6 0994d82a8f22ac" | |||
readonly IMAGE="${IMAGE_NAME}@${IMAGE_DIGEST}" | readonly IMAGE="${IMAGE_NAME}@${IMAGE_DIGEST}" | |||
build_linux() { | build_linux() { | |||
echo "### Building Linux binary wheels ###" | echo "### Building Linux binary wheels ###" | |||
if [[ -n "${KOKORO_ROOT}" ]] ; then | ||||
eval "$(pyenv init -)" | ||||
pyenv versions | ||||
fi | ||||
mkdir -p release | mkdir -p release | |||
# Use signatures for getting images from registry (see | # Use signatures for getting images from registry (see | |||
# https://docs.docker.com/engine/security/trust/content_trust/). | # https://docs.docker.com/engine/security/trust/content_trust/). | |||
export DOCKER_CONTENT_TRUST=1 | export DOCKER_CONTENT_TRUST=1 | |||
# Build binary wheels. | # Build binary wheels. | |||
docker run --volume "${TINK_BASE}:/tmp/tink" --workdir /tmp/tink/python \ | docker run --volume "${TINK_SRC_PATH}:/tmp/tink" --workdir /tmp/tink/python \ | |||
"${IMAGE}" /tmp/tink/python/tools/distribution/build_linux_binary_wheels.sh | "${IMAGE}" /tmp/tink/python/tools/distribution/build_linux_binary_wheels.sh | |||
# Test binary wheels. | ## Test binary wheels. | |||
docker run --volume "${TINK_BASE}:/tmp/tink" --workdir /tmp/tink/python \ | docker run --volume "${TINK_SRC_PATH}:/tmp/tink" --workdir /tmp/tink/python \ | |||
"${IMAGE}" /tmp/tink/python/tools/distribution/test_linux_binary_wheels.sh | "${IMAGE}" /tmp/tink/python/tools/distribution/test_linux_binary_wheels.sh | |||
# Build source wheels. | echo "### Building Linux source distribution ###" | |||
pip3 install wheel | local sorted=( $( echo "${PYTHON_VERSIONS[@]}" \ | |||
export TINK_PYTHON_SETUPTOOLS_OVERRIDE_BASE_PATH="${TINK_BASE}" | | xargs -n1 | sort -V | xargs ) ) | |||
# TODO(ckl): Is sudo necessary? | local latest="${sorted[${#sorted[@]}-1]}" | |||
sudo python3 setup.py sdist | enable_py_version "${latest}" | |||
cp dist/*.tar.gz release/ | ||||
# Build source distribution. | ||||
export TINK_PYTHON_SETUPTOOLS_OVERRIDE_BASE_PATH="${TINK_SRC_PATH}" | ||||
python3 setup.py sdist | ||||
local sdist_filename="tink-${TINK_VERSION}.tar.gz" | ||||
set_owner_within_tar "dist/${sdist_filename}" | ||||
cp "dist/${sdist_filename}" release/ | ||||
# Test install from source wheel | # Test install from source distribution. | |||
python3 --version | ||||
pip3 list | pip3 list | |||
pip3 install release/*.tar.gz | pip3 install -v "release/${sdist_filename}" | |||
pip3 list | pip3 list | |||
find tink/ -not -path "*cc/pybind*" -type f -name "*_test.py" -print0 \ | find tink/ -not -path "*cc/pybind*" -type f -name "*_test.py" -print0 \ | |||
| xargs -0 -n1 python3 | | xargs -0 -n1 python3 | |||
} | } | |||
build_macos() { | build_macos() { | |||
echo "### Building macOS binary wheels ###" | echo "### Building macOS binary wheels ###" | |||
mkdir -p release | ||||
for v in "${PYTHON_VERSIONS[@]}"; do | for v in "${PYTHON_VERSIONS[@]}"; do | |||
enable_py_version "${v}" | ||||
# Build binary wheel. | # Build binary wheel. | |||
local pip_command="pip${v}" | pip3 wheel -w release . | |||
${pip_command} wheel . | ||||
# Test binary wheel. | # Test binary wheel. | |||
# TODO(ckl): Implement test. | # TODO(ckl): Implement test. | |||
done | done | |||
} | } | |||
enable_py_version() { | ||||
# A partial version number (e.g. "3.9"). | ||||
local partial_version="$1" | ||||
# The latest installed Python version that matches the partial version number | ||||
# (e.g. "3.9.5"). | ||||
local version="$(pyenv versions --bare | grep "${partial_version}" | tail -1)" | ||||
# Set current Python version via environment variable. | ||||
pyenv shell "${version}" | ||||
# Update environment. | ||||
pip3 install --upgrade pip | ||||
pip3 install --upgrade setuptools | ||||
pip3 install --upgrade wheel | ||||
} | ||||
# setuptools does not replicate the distutils feature of explicitly setting | ||||
# user/group ownership on the files within the source distribution archive. | ||||
# | ||||
# This function is an easy workaround that doesn't require monkey-patching | ||||
# setuptools. This behavior is desired to produce deterministic release | ||||
# artifacts. | ||||
set_owner_within_tar() { | ||||
local tar_file="$1" | ||||
local tmp_dir="$(mktemp -d tink-py-tar-XXXXXX)" | ||||
tar -C "${tmp_dir}" -xzf "${tar_file}" | ||||
local tink_dir="$(basename $(ls -d ${tmp_dir}/tink*))" | ||||
tar -C "${tmp_dir}" -czf "${tar_file}" \ | ||||
--owner=root --group=root "${tink_dir}" | ||||
rm -r "${tmp_dir}" | ||||
} | ||||
main() { | main() { | |||
if [[ "${PLATFORM}" == 'linux' ]]; then | if [[ "${PLATFORM}" == 'linux' ]]; then | |||
build_linux | build_linux | |||
elif [[ "${PLATFORM}" == 'darwin' ]]; then | elif [[ "${PLATFORM}" == 'darwin' ]]; then | |||
build_macos | build_macos | |||
else | else | |||
echo "${PLATFORM} is not a supported platform." | echo "${PLATFORM} is not a supported platform." | |||
exit 1 | exit 1 | |||
fi | fi | |||
} | } | |||
End of changes. 12 change blocks. | ||||
16 lines changed or deleted | 67 lines changed or added |