Skip to content

Commit 3ea860b

Browse files
authored
SNOW-608095: Create new SQLAlchemy Jenkins test pipeline (#304)
Create new SQLAlchemy Jenkins test pipeline which runs pytest against pre-built sqlalchemy wheel
1 parent 5d17bfb commit 3ea860b

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

ci/test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash -e
2+
#
3+
# Test Snowflake SQLAlchemy
4+
#
5+
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
SQLALCHEMY_DIR="$( dirname "${THIS_DIR}")"
7+
PARAMETERS_DIR="${SQLALCHEMY_DIR}/.github/workflows/parameters"
8+
9+
cd "${SQLALCHEMY_DIR}"
10+
11+
# Check Requirements
12+
if [ -z "${PARAMETERS_SECRET}" ]; then
13+
echo "Missing PARAMETERS_SECRET, failing..."
14+
exit 1
15+
fi
16+
17+
# Decrypt parameters file
18+
PARAMS_FILE="${PARAMETERS_DIR}/parameters_aws.py.gpg"
19+
[ ${cloud_provider} == azure ] && PARAMS_FILE="${PARAMETERS_DIR}/parameters_azure.py.gpg"
20+
[ ${cloud_provider} == gcp ] && PARAMS_FILE="${PARAMETERS_DIR}/parameters_gcp.py.gpg"
21+
gpg --quiet --batch --yes --decrypt --passphrase="${PARAMETERS_SECRET}" ${PARAMS_FILE} > tests/parameters.py
22+
23+
# Download artifacts made by build
24+
aws s3 cp --recursive --only-show-errors s3://sfc-jenkins/repository/sqlalchemy/linux/${client_git_branch}/${client_git_commit}/ dist
25+
26+
echo "[Info] Going to run regular tests for Python ${python_env}"
27+
${THIS_DIR}/test_docker.sh ${python_env}

ci/test_docker.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash -e
2+
# Test Snowflake SQLAlchemy in Docker
3+
# NOTES:
4+
# - By default this script runs Python 3.7 tests, as these are installed in dev vms
5+
# - To compile only a specific version(s) pass in versions like: `./test_docker.sh "3.7 3.8"`
6+
7+
set -o pipefail
8+
9+
# In case this is ran from dev-vm
10+
PYTHON_ENV=${1:-3.7}
11+
12+
# Set constants
13+
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14+
SQLALCHEMY_DIR="$( dirname "${THIS_DIR}")"
15+
WORKSPACE=${WORKSPACE:-$SQLALCHEMY_DIR}
16+
source $THIS_DIR/set_base_image.sh
17+
18+
cd $THIS_DIR/docker/sqlalchemy_build
19+
20+
CONTAINER_NAME=test_sqlalchemy
21+
22+
echo "[Info] Building docker image"
23+
arch=$(uname -p)
24+
25+
echo "[Info] Building docker image"
26+
if [[ "$arch" == "aarch64" ]]; then
27+
BASE_IMAGE=$BASE_IMAGE_MANYLINUX2014AARCH64
28+
GOSU_URL=https://github.com/tianon/gosu/releases/download/1.14/gosu-arm64
29+
else
30+
BASE_IMAGE=$BASE_IMAGE_MANYLINUX2014
31+
GOSU_URL=https://github.com/tianon/gosu/releases/download/1.14/gosu-amd64
32+
fi
33+
34+
echo "[Info] Start building docker image and testing"
35+
36+
user_id=$(id -u ${USER})
37+
docker run \
38+
--rm \
39+
--network=host \
40+
-e TERM=vt102 \
41+
-e PIP_DISABLE_PIP_VERSION_CHECK=1 \
42+
-e OPENSSL_FIPS=1 \
43+
-e LOCAL_USER_ID=${user_id} \
44+
-e AWS_ACCESS_KEY_ID \
45+
-e AWS_SECRET_ACCESS_KEY \
46+
-e SF_REGRESS_LOGS \
47+
-e SF_PROJECT_ROOT \
48+
-e cloud_provider \
49+
-e JENKINS_HOME \
50+
-e GITHUB_ACTIONS \
51+
--mount type=bind,source="${SQLALCHEMY_DIR}",target=/home/user/snowflake-sqlalchemy \
52+
$(docker build --pull --build-arg BASE_IMAGE=$BASE_IMAGE --build-arg GOSU_URL="$GOSU_URL" -q .) \
53+
/home/user/snowflake-sqlalchemy/ci/test_linux.sh ${PYTHON_ENV}

ci/test_linux.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash -e
2+
#
3+
# Test Snowflake SQLAlchemy in Linux
4+
# NOTES:
5+
# - Versions to be tested should be passed in as the first argument, e.g: "3.7 3.8". If omitted 3.7-3.10 will be assumed.
6+
# - This script assumes that ../dist/repaired_wheels has the wheel(s) built for all versions to be tested
7+
# - This is the script that test_docker.sh runs inside of the docker container
8+
9+
PYTHON_VERSIONS="${1:-3.7 3.8 3.9 3.10}"
10+
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
11+
SQLALCHEMY_DIR="$( dirname "${THIS_DIR}")"
12+
13+
# Install one copy of tox
14+
python3 -m pip install -U tox-external-wheels
15+
python3 -m pip install --pre tox
16+
17+
# Run tests
18+
cd $SQLALCHEMY_DIR
19+
for PYTHON_VERSION in ${PYTHON_VERSIONS}; do
20+
echo "[Info] Testing with ${PYTHON_VERSION}"
21+
SHORT_VERSION=$(python3 -c "print('${PYTHON_VERSION}'.replace('.', ''))")
22+
SQLALCHEMY_WHL=$(ls $SQLALCHEMY_DIR/dist/snowflake_sqlalchemy-*-py2.py3-none-any.whl | sort -r | head -n 1)
23+
TEST_ENVLIST=fix_lint,py${SHORT_VERSION}-ci,py${SHORT_VERSION}-coverage
24+
echo "[Info] Running tox for ${TEST_ENVLIST}"
25+
python3 -m tox -e ${TEST_ENVLIST} --external_wheels ${SQLALCHEMY_WHL}
26+
done

tox.ini

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,30 @@ description = run the tests with pytest under {basepython}
1111
extras =
1212
development
1313
pandas
14+
external_wheels =
15+
py37-ci: dist/*.whl
16+
py38-ci: dist/*.whl
17+
py39-ci: dist/.whl
18+
py310-ci: dist/.whl
1419
deps = pip
1520
passenv =
21+
AWS_ACCESS_KEY_ID
22+
AWS_SECRET_ACCESS_KEY
23+
SF_PROJECT_ROOT
1624
cloud_provider
25+
SF_REGRESS_LOGS
26+
; Github Actions provided environmental variables
1727
GITHUB_ACTIONS
28+
JENKINS_HOME
29+
; This is required on windows. Otherwise pwd module won't be imported successfully,
30+
; see https://github.com/tox-dev/tox/issues/1455
31+
USERNAME
1832
PYTEST_ADDOPTS
19-
setenv = COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
33+
setenv =
34+
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
35+
ci: SNOWFLAKE_PYTEST_OPTS = -vvv
2036
commands = pytest \
37+
{env:SNOWFLAKE_PYTEST_OPTS:} \
2138
--cov "snowflake.sqlalchemy" \
2239
--junitxml {toxworkdir}/junit.{envname}.xml \
2340
{posargs:tests}

0 commit comments

Comments
 (0)