diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c7447c2..982f58d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,5 @@ --- -name: pysqlsync database tests +name: pysqlsync database integration tests on: workflow_dispatch: @@ -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 @@ -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: @@ -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: @@ -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: @@ -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 diff --git a/run_test.sh b/run_test.sh index 17df2ed..636d853 100755 --- a/run_test.sh +++ b/run_test.sh @@ -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=" -p 1521:1521 container-registry.oracle.com/database/free:latest +docker run -d \ + -e "ORACLE_PWD=" \ + -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 @@ -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=" -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=" \ + --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