Created
September 15, 2020 05:13
-
-
Save jborean93/65495d1e36aa9c02fbdf707d4232fff7 to your computer and use it in GitHub Desktop.
ansible-galaxy collection update scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o pipefail -eu | |
function create_package { | |
name="${1}" | |
version="${2}" | |
requirements="${3:-}" | |
if [ ! -z "${requirements}" ]; then | |
IFS=',' read -ra requirements <<< "${requirements}" | |
requirements="$( printf "\n %s" "${requirements[@]}" )" | |
fi | |
mkdir "${name}" | |
pushd "${name}" | |
cat > pyproject.toml << EOL | |
[build-system] | |
requires = ["setuptools>=40.8.9", "wheel"] | |
build-backend = "setuptools.build_meta" | |
EOL | |
cat > setup.cfg << EOL | |
[metadata] | |
name = ${name} | |
version = ${version} | |
[options] | |
packages = find: | |
install_requires = ${requirements} | |
[bdist_wheel] | |
universal = 1 | |
EOL | |
mkdir "${name}" | |
echo "__version__ = \"${version}\"" > "${name}/__init__.py" | |
python -m pep517.build . | |
popd | |
if [ ! -d "dist/${name}" ]; then | |
mkdir "dist/${name}" | |
fi | |
mv "${name}/dist/"* "dist/${name}/" | |
rm -r "${name}" | |
} | |
echo "Creating the output dist directory for pypiserver" | |
if [ -d dist ]; then | |
rm -r dist | |
fi | |
mkdir dist | |
echo "Creating test packages" | |
create_package ansible_pkg1 1.0.0 | |
create_package ansible_pkg1 1.0.1 | |
create_package ansible_dep 1.0.0 | |
create_package ansible_dep 1.0.1 | |
create_package ansible_pkg2 1.0.0 ansible_dep | |
create_package ansible_pkg2 2.0.0 'ansible_dep>1.0.0' | |
create_package ansible_pkg3 1.0.0 'ansible_dep<1.0.1' | |
echo "Starting test pypi server" | |
docker run \ | |
--detach \ | |
--rm \ | |
-p 8080:8080 \ | |
-v "$(pwd)/dist":/data/packages \ | |
pypiserver/pypiserver:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -o pipefail -eu | |
trap "if [ -d test-venv ]; then rm -r test-venv; fi" EXIT | |
export PIP_EXTRA_INDEX_URL=http://localhost:8080/simple/ | |
export PIP_DISABLE_PIP_VERSION_CHECK=1 | |
function test { | |
virtualenv test-venv > /dev/null | |
source test-venv/bin/activate | |
echo -e "| Testing - ${1} |\n" | |
eval "${2}" | |
echo -e "\n| Test Complete |\n" | |
deactivate | |
rm -r test-venv | |
} | |
# Not updated | |
code=" | |
pip install ansible_pkg1==1.0.0 | |
pip install ansible_pkg1 | |
pip list | |
" | |
test "Install package with version already satisfied" "${code}" | |
# Will update the package based on the new req | |
code=" | |
pip install ansible_pkg1==1.0.0 | |
pip install 'ansible_pkg1>1.0.0' | |
pip list | |
" | |
test "Install package with version req not satisfied" "${code}" | |
# No packages update | |
code=" | |
pip install ansible_dep==1.0.0 | |
pip install ansible_pkg2==1.0.0 | |
pip list | |
" | |
test "Install package with older dep" "${code}" | |
# Same as above | |
code=" | |
pip install ansible_dep==1.0.0 --use-feature=2020-resolver | |
pip install ansible_pkg2==1.0.0 --use-feature=2020-resolver | |
pip list | |
" | |
test "Install package with older dep - new dep resolver" "${code}" | |
# Will update the dep package based on the new requirements | |
code=" | |
pip install ansible_dep==1.0.0 | |
pip install ansible_pkg2 | |
pip list | |
" | |
test "Install package with older dep version constraint" "${code}" | |
# Install the dep based on ansible_pkg3 requirements but outputs warning that new dep resolver will fail | |
code=" | |
pip install ansible_pkg2 | |
pip install ansible_pkg3 | |
pip list | |
" | |
test "Try to install package with incomptaible dep version" "${code}" | |
# I expect this to actually fail but it installs the older incompatible dep | |
code=" | |
pip install ansible_pkg2 --use-feature=2020-resolver | |
pip install ansible_pkg3 --use-feature=2020-resolver | |
pip list | |
" | |
test "Try to install package with incomptaible dep version - new dep resolver" "${code}" | |
# Updates ansible_pkg1 | |
code=" | |
pip install ansible_pkg1==1.0.0 | |
pip install -U ansible_pkg1 | |
pip list | |
" | |
test "Install -U with older package" "${code}" | |
# Both ansible_pkg2 and ansible_dep are updated | |
code=" | |
pip install ansible_dep==1.0.0 | |
pip install ansible_pkg2 | |
pip install -U ansible_pkg2 | |
pip list | |
" | |
test "Install -U with older dep" "${code}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment