|
| 1 | +name: CI for gaussdb-python |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "*" |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref_name }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + runs-on: ubuntu-22.04 |
| 17 | + |
| 18 | + services: |
| 19 | + opengauss: |
| 20 | + image: opengauss/opengauss-server:latest |
| 21 | + ports: |
| 22 | + - 5432:5432 |
| 23 | + env: |
| 24 | + GS_USERNAME: root |
| 25 | + GS_USER_PASSWORD: ${{ secrets.OPENGAUSS_PASSWORD }} |
| 26 | + GS_PASSWORD: ${{ secrets.OPENGAUSS_PASSWORD }} |
| 27 | + options: >- |
| 28 | + --privileged=true |
| 29 | + --name opengauss-custom |
| 30 | +
|
| 31 | + steps: |
| 32 | + - name: Checkout code |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: "3.9" |
| 39 | + cache: pip |
| 40 | + |
| 41 | + - name: Create and activate virtual environment |
| 42 | + run: | |
| 43 | + python -m venv venv |
| 44 | + echo "VENV_PATH=$GITHUB_WORKSPACE/venv/bin" >> $GITHUB_ENV |
| 45 | + source venv/bin/activate |
| 46 | +
|
| 47 | + - name: Install gaussdb libpq driver |
| 48 | + run: | |
| 49 | + sudo apt update |
| 50 | + sudo apt install -y wget unzip |
| 51 | + wget -O /tmp/GaussDB_driver.zip https://dbs-download.obs.cn-north-1.myhuaweicloud.com/GaussDB/1730887196055/GaussDB_driver.zip |
| 52 | + unzip /tmp/GaussDB_driver.zip -d /tmp/ && rm -rf /tmp/GaussDB_driver.zip |
| 53 | + \cp /tmp/GaussDB_driver/Centralized/Hce2_X86_64/GaussDB-Kernel*64bit_Python.tar.gz /tmp/ |
| 54 | + tar -zxvf /tmp/GaussDB-Kernel*64bit_Python.tar.gz -C /tmp/ && rm -rf /tmp/GaussDB-Kernel*64bit_Python.tar.gz && rm -rf /tmp/psycopg2 && rm -rf /tmp/GaussDB_driver |
| 55 | + echo /tmp/lib | sudo tee /etc/ld.so.conf.d/gauss-libpq.conf |
| 56 | + sudo sed -i '1s|^|/tmp/lib\n|' /etc/ld.so.conf |
| 57 | + sudo ldconfig |
| 58 | + ldconfig -p | grep pq |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: | |
| 62 | + source venv/bin/activate |
| 63 | + python -m pip install --upgrade pip |
| 64 | + pip install -r requirements.txt |
| 65 | + pip install -e "./psycopg[dev,test]" |
| 66 | + pip install -e ./psycopg_pool |
| 67 | +
|
| 68 | + |
| 69 | + - name: Wait for openGauss to be ready |
| 70 | + env: |
| 71 | + GSQL_PASSWORD: ${{ secrets.OPENGAUSS_PASSWORD }} |
| 72 | + run: | |
| 73 | + source venv/bin/activate |
| 74 | + for i in {1..15}; do |
| 75 | + pg_isready -h localhost -p 5432 -U root && break |
| 76 | + sleep 5 |
| 77 | + done |
| 78 | + if ! pg_isready -h localhost -p 5432 -U root; then |
| 79 | + echo "openGauss is not ready" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Create test database |
| 84 | + run: | |
| 85 | + docker exec opengauss-custom bash -c "su - omm -c 'gsql -d postgres -c \"CREATE DATABASE test DBCOMPATIBILITY '\''PG'\'';\"'" |
| 86 | +
|
| 87 | + - name: Create report directory |
| 88 | + run: | |
| 89 | + mkdir -p reports |
| 90 | +
|
| 91 | + - name: Run tests |
| 92 | + env: |
| 93 | + PYTHONPATH: ./psycopg:./psycopg_pool |
| 94 | + PSYCOPG_IMPL: python |
| 95 | + PSYCOPG_TEST_DSN: "host=127.0.0.1 port=5432 dbname=test user=root password=${{ secrets.OPENGAUSS_PASSWORD }} " |
| 96 | + run: | |
| 97 | + source venv/bin/activate |
| 98 | + pytest -s -v |
| 99 | +
|
| 100 | + - name: Cleanup |
| 101 | + if: always() |
| 102 | + run: | |
| 103 | + docker stop opengauss-custom |
| 104 | + docker rm opengauss-custom |
0 commit comments