Skip to content

Commit

Permalink
Github action to ensure vendored requests version.
Browse files Browse the repository at this point in the history
  • Loading branch information
purple4reina committed Dec 19, 2024
1 parent 5ee2c8c commit c69e6d1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/check_dependencies.yml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions scripts/check_dependencies.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c69e6d1

Please sign in to comment.