Skip to content

Commit

Permalink
Optimize workflow for automated integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyadi committed Jan 10, 2024
1 parent 7b5ccaf commit fcfa808
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 106 deletions.
155 changes: 51 additions & 104 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: pysqlsync database tests
name: pysqlsync database integration tests

on:
workflow_dispatch:
Expand All @@ -9,9 +9,43 @@ defaults:
shell: bash

jobs:
postgresql:
build:
runs-on: ubuntu-latest

steps:
- name: Fetch source code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Set up build dependencies
run: |
python -m pip install --upgrade pip
python -m pip --disable-pip-version-check install -r requirements.txt
- name: Run sanity checks
run: |
./check.sh
- name: Build PyPI package
run: |
python -m build
- name: Save PyPI package as artifact
uses: actions/upload-artifact@v4
with:
name: pysqlsync-dist
path: dist/**
if-no-files-found: error
compression-level: 0

test:
runs-on: ubuntu-latest
needs: build

services:
postgres:
image: postgres:15-alpine
Expand All @@ -30,36 +64,6 @@ jobs:
--health-retries 5
--health-start-period 10s
strategy:
matrix:
python-version: ["3.12"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip --disable-pip-version-check install -r requirements.txt
- name: Build package
run: |
./check.sh
python -m build
- name: Run integration tests
run: |
TEST_INTEGRATION=1 TEST_POSTGRESQL=1 python -m unittest discover
oracle:
runs-on: ubuntu-latest

services:
oracle:
image: container-registry.oracle.com/database/free:latest
env:
Expand All @@ -73,36 +77,6 @@ jobs:
--health-retries 10
--health-start-period 30s
strategy:
matrix:
python-version: ["3.12"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip --disable-pip-version-check install -r requirements.txt
- name: Build package
run: |
./check.sh
python -m build
- name: Run integration tests
run: |
TEST_INTEGRATION=1 TEST_ORACLE=1 python -m unittest discover
mysql:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0
env:
Expand All @@ -118,36 +92,6 @@ jobs:
--health-retries 5
--health-start-period 10s
strategy:
matrix:
python-version: ["3.12"]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip --disable-pip-version-check install -r requirements.txt
- name: Build package
run: |
./check.sh
python -m build
- name: Run integration tests
run: |
TEST_INTEGRATION=1 TEST_MYSQL=1 python -m unittest discover
mssql:
runs-on: ubuntu-latest

services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
Expand All @@ -166,29 +110,32 @@ jobs:
strategy:
matrix:
python-version: ["3.12"]
python-version: ["3.9", "3.12"]

steps:
- uses: actions/checkout@v3

- name: Install Microsoft ODBC
run: sudo ACCEPT_EULA=Y apt-get install msodbcsql18 -y

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip --disable-pip-version-check install -r requirements.txt
- name: Fetch PyPI package
uses: actions/download-artifact@v4
with:
name: pysqlsync-dist

- name: Build package
- name: Install PyPI package
run: |
./check.sh
python -m build
python -m pip install *.whl
- name: Fetch integration tests
uses: actions/checkout@v4
with:
sparse-checkout: |
tests
- name: Run integration tests
run: |
TEST_INTEGRATION=1 TEST_MSSQL=1 python -m unittest discover
TEST_INTEGRATION=1 TEST_POSTGRESQL=1 TEST_ORACLE=1 TEST_MYSQL=1 TEST_MSSQL=1 python -m unittest discover
10 changes: 8 additions & 2 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ TEST_INTEGRATION=1 TEST_POSTGRESQL=1 TEST_MYSQL=1 python3 -m unittest discover
CONTAINER=oracle-db
docker ps -q --filter "name=$CONTAINER" | xargs -r docker stop
docker ps -aq --filter "name=$CONTAINER" | xargs -r docker rm
docker run -d --name $CONTAINER -e "ORACLE_PWD=<YourStrong@Passw0rd>" -p 1521:1521 container-registry.oracle.com/database/free:latest
docker run -d \
-e "ORACLE_PWD=<YourStrong@Passw0rd>" \
-p 1521:1521 \
--name $CONTAINER container-registry.oracle.com/database/free:latest
sleep 30
TEST_INTEGRATION=1 TEST_ORACLE=1 python3 -m unittest discover
docker stop $CONTAINER && docker rm $CONTAINER
Expand All @@ -25,7 +28,10 @@ docker stop $CONTAINER && docker rm $CONTAINER
CONTAINER=sql1
docker ps -q --filter "name=$CONTAINER" | xargs -r docker stop
docker ps -aq --filter "name=$CONTAINER" | xargs -r docker rm
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" -p 1433:1433 --name $CONTAINER --hostname sql1 -d mcr.microsoft.com/mssql/server:2022-latest
docker run -d \
-e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<YourStrong@Passw0rd>" \
--hostname sql1 -p 1433:1433 \
--name $CONTAINER mcr.microsoft.com/mssql/server:2022-latest
sleep 30
TEST_INTEGRATION=1 TEST_MSSQL=1 python3 -m unittest discover
docker stop $CONTAINER && docker rm $CONTAINER

0 comments on commit fcfa808

Please sign in to comment.