diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 0000000..049619f --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,55 @@ +--- +name: Test PyPI package +description: Run Python `unittest` on a pre-packaged Python wheel uploaded as an artifact + +inputs: + python-version: + description: Python version to run tests with + required: true + default: '3.12' + options-extras: + description: Extras to pass to `pip install` + required: false + default: '' + +runs: + using: composite + steps: + - name: Set up Python ${{ inputs.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Fetch PyPI package + uses: actions/download-artifact@v4 + with: + merge-multiple: true + + - name: Install PyPI package without extras + if: ${{ ! inputs.options-extras }} + run: | + for FILE in `ls *.whl`; do python -m pip install $FILE; done + shell: bash + + - name: Install PyPI package with extras + if: ${{ inputs.options-extras }} + run: | + for FILE in `ls *.whl`; do python -m pip install $FILE'[${{ inputs.options-extras }}]'; done + shell: bash + + - name: Fetch unit and/or integration tests + uses: actions/checkout@v4 + with: + sparse-checkout: | + . + tests + + - name: Install test requirements + run: | + python -m pip --disable-pip-version-check install -r requirements-test.txt + shell: bash + + - name: Run unit and/or integration tests + run: | + python -m unittest discover + shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15cbac4..8e3f2f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,6 +8,9 @@ defaults: run: shell: bash +env: + TEST_INTEGRATION: 1 + jobs: build: runs-on: ubuntu-latest @@ -24,7 +27,7 @@ jobs: - name: Set up build dependencies run: | python -m pip install --upgrade pip - python -m pip --disable-pip-version-check install -r requirements.txt + python -m pip --disable-pip-version-check install -r requirements-dev.txt - name: Run sanity checks run: | @@ -42,7 +45,7 @@ jobs: if-no-files-found: error compression-level: 0 - test: + test-postgresql: runs-on: ubuntu-latest needs: build @@ -64,6 +67,30 @@ jobs: --health-retries 5 --health-start-period 10s + env: + TEST_POSTGRESQL: 1 + + strategy: + matrix: + python-version: ["3.9", "3.12"] + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + .github + + - name: Test PyPI package + uses: ./.github/actions/test + with: + python-version: ${{ matrix.python-version }} + options-extras: postgresql + + test-oracle: + runs-on: ubuntu-latest + needs: build + + services: oracle: image: container-registry.oracle.com/database/free:latest env: @@ -77,6 +104,30 @@ jobs: --health-retries 10 --health-start-period 30s + env: + TEST_ORACLE: 1 + + strategy: + matrix: + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + .github + + - name: Test PyPI package + uses: ./.github/actions/test + with: + python-version: ${{ matrix.python-version }} + options-extras: oracle + + test-mysql: + runs-on: ubuntu-latest + needs: build + + services: mysql: image: mysql:8.0 env: @@ -92,6 +143,30 @@ jobs: --health-retries 5 --health-start-period 10s + env: + TEST_MYSQL: 1 + + strategy: + matrix: + python-version: ["3.9", "3.12"] + + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + .github + + - name: Test PyPI package + uses: ./.github/actions/test + with: + python-version: ${{ matrix.python-version }} + options-extras: mysql + + test-mssql: + runs-on: ubuntu-latest + needs: build + + services: mssql: image: mcr.microsoft.com/mssql/server:2022-latest env: @@ -108,34 +183,24 @@ jobs: --health-retries 5 --health-start-period 10s + env: + TEST_MSSQL: 1 + strategy: matrix: - python-version: ["3.9", "3.12"] + python-version: ["3.12"] steps: - 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@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Fetch PyPI package - uses: actions/download-artifact@v4 - with: - name: pysqlsync-dist - - - name: Install PyPI package - run: | - for FILE in `ls *.whl`; do python -m pip install $FILE'[tsv,postgresql,oracle,mysql,mssql]'; done - - - name: Fetch integration tests - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: sparse-checkout: | - tests + .github - - name: Run integration tests - run: | - TEST_INTEGRATION=1 TEST_POSTGRESQL=1 TEST_ORACLE=1 TEST_MYSQL=1 TEST_MSSQL=1 python -m unittest discover + - name: Test PyPI package + uses: ./.github/actions/test + with: + python-version: ${{ matrix.python-version }} + options-extras: mssql diff --git a/requirements.txt b/requirements-dev.txt similarity index 89% rename from requirements.txt rename to requirements-dev.txt index a1b14a4..a1ce347 100644 --- a/requirements.txt +++ b/requirements-dev.txt @@ -7,9 +7,6 @@ build >= 1.0 mypy >= 1.8 flake8 >= 7.0 -# data export/import -tsv2py >= 0.5.2 - # PostgreSQL asyncpg >= 0.29 asyncpg-stubs >= 0.29 diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..7feda07 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,2 @@ +# data export/import +tsv2py >= 0.5.2