diff --git a/.github/workflows/check_dependencies.yml b/.github/workflows/check_dependencies.yml new file mode 100644 index 00000000..c5cb32f5 --- /dev/null +++ b/.github/workflows/check_dependencies.yml @@ -0,0 +1,20 @@ +name: Check Dependencies + +on: + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + architecture: ['linux/amd64', 'linux/arm64'] + steps: + - uses: actions/checkout@v3 + + - name: Check Dependencies + run: | + ARCHITECTURE=${{ matrix.architecture }} \ + PYTHON_VERSION=${{ matrix.python-version }} \ + ./scripts/check_dependencies.sh diff --git a/scripts/check_dependencies.sh b/scripts/check_dependencies.sh new file mode 100755 index 00000000..eab419d8 --- /dev/null +++ b/scripts/check_dependencies.sh @@ -0,0 +1,55 @@ +#!/bin/bash -ex + +# This script checks to make sure that the vendored version of requests shipped +# with pip meets the minimum required version of requests as defined by the +# datadog package. + +if [[ -z $ARCHITECTURE ]]; then + DOCKER_DEFAULT_PLATFORM='linux/amd64' +else + DOCKER_DEFAULT_PLATFORM=$ARCHITECTURE +fi + +if [[ -z $PYTHON_VERSION ]]; then + PYTHON_VERSION=latest +fi + +# create virtual environment +rm -rf venv +pip install virtualenv +virtualenv venv +source venv/bin/activate + +# determine highest available version of requests +pip install . +highest=$(pip freeze | grep requests | tr -d 'requests==') +echo "Highest available version of requests: $highest" + +# determine minumum required version of requests +pip uninstall -y requests +pip install uv +uv pip install --resolution=lowest . +lowest=$(pip freeze | grep requests | tr -d 'requests==') +echo "Minimum required version of requests: $lowest" + +# determine version of requests packaged with pip +vendored=$( + DOCKER_DEFAULT_PLATFORM=$DOCKER_DEFAULT_PLATFORM \ + docker run --entrypoint='' public.ecr.aws/lambda/python:$PYTHON_VERSION \ + python -c "import pip._vendor.requests; print(pip._vendor.requests.__version__)" +) +echo "Version of vendored requests: $vendored" + +# compare versions +compared=$(python -c " +parse = lambda v: tuple(map(int, v.split('.'))) +print(parse('$lowest') <= parse('$vendored'))") + +if [[ $compared == "True" ]]; then + echo "The vendored version of requests meets the minimum requirement" + echo " lowest required ($lowest) <= vendored version ($vendored) <= highest available ($highest)" +else + echo "The vendored version of requests does not meet the minimum requirement" + echo " vendered version ($vendored) < lowest required ($lowest) <= highest available ($highest)" + exit 1 +fi