|
| 1 | +name: Run Test Suite |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - test_dll_issue |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + os: |
| 10 | + description: 'Runner OS' |
| 11 | + required: true |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - ubuntu-latest |
| 15 | + - windows-latest |
| 16 | + - macos-latest |
| 17 | + - all |
| 18 | + default: 'ubuntu-latest' |
| 19 | + python-version: |
| 20 | + description: 'Python version' |
| 21 | + required: true |
| 22 | + type: choice |
| 23 | + options: |
| 24 | + - '3.9' |
| 25 | + - '3.10' |
| 26 | + - '3.11' |
| 27 | + - '3.12' |
| 28 | + - '3.13' |
| 29 | + - '3.14' |
| 30 | + - 'all' |
| 31 | + default: '3.14' |
| 32 | + test-pattern: |
| 33 | + description: 'Test glob pattern (e.g. test_001*.py). Leave empty to run all.' |
| 34 | + required: false |
| 35 | + type: string |
| 36 | + default: '' |
| 37 | + |
| 38 | +jobs: |
| 39 | + run_tests: |
| 40 | + name: Test on ${{ matrix.os }} / Python ${{ matrix.python-version }} |
| 41 | + runs-on: ${{ matrix.os }} |
| 42 | + strategy: |
| 43 | + fail-fast: false |
| 44 | + matrix: |
| 45 | + os: ${{ github.event.inputs.os == 'all' && fromJSON('["ubuntu-latest","windows-latest","macos-latest"]') || fromJSON(format('["{0}"]', github.event.inputs.os || 'ubuntu-latest')) }} |
| 46 | + python-version: ${{ github.event.inputs.python-version == 'all' && fromJSON('["3.9","3.10","3.11","3.12","3.13","3.14"]') || fromJSON(format('["{0}"]', github.event.inputs.python-version || '3.14')) }} |
| 47 | + |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v5 |
| 50 | + |
| 51 | + - name: Set up Python ${{ matrix.python-version }} |
| 52 | + uses: actions/setup-python@v5 |
| 53 | + with: |
| 54 | + python-version: ${{ matrix.python-version }} |
| 55 | + |
| 56 | + - name: Install ibm_db from source |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + python -m pip install --upgrade pip |
| 60 | + python -m pip install . |
| 61 | +
|
| 62 | + - name: Generate config.json from secrets |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + cat > config.json <<ENDOFCFG |
| 66 | + { |
| 67 | + "database" : "${{ secrets.DB2_DATABASE }}", |
| 68 | + "user" : "${{ secrets.DB2_USER }}", |
| 69 | + "password" : "${{ secrets.DB2_PASSWD }}", |
| 70 | + "hostname" : "${{ secrets.DB2_HOSTNAME }}", |
| 71 | + "port" : ${{ secrets.DB2_PORT }} |
| 72 | + } |
| 73 | + ENDOFCFG |
| 74 | +
|
| 75 | + - name: Write db2dsdriver.cfg into clidriver/cfg |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + CFG_DIR=$(python -c " |
| 79 | + import os, sys, glob, importlib.util |
| 80 | +
|
| 81 | + def find_cfg(): |
| 82 | + candidates = [] |
| 83 | +
|
| 84 | + # 1. IBM_DB_HOME env var |
| 85 | + ibm_db_home = os.environ.get('IBM_DB_HOME', '').strip('\"') |
| 86 | + if ibm_db_home: |
| 87 | + candidates.append(os.path.join(ibm_db_home, 'cfg')) |
| 88 | +
|
| 89 | + # 2. PATH — look for clidriver or dsdriver bin dirs |
| 90 | + for p in os.environ.get('PATH', '').split(os.pathsep): |
| 91 | + parent = os.path.dirname(p) |
| 92 | + if os.path.basename(p) == 'bin': |
| 93 | + for sub in ['clidriver', 'dsdriver', '']: |
| 94 | + base = os.path.join(parent, sub) if sub else parent |
| 95 | + candidates.append(os.path.join(base, 'cfg')) |
| 96 | +
|
| 97 | + # 3. ibm_db site-package (user or system site-packages) |
| 98 | + spec = importlib.util.find_spec('ibm_db') |
| 99 | + if spec and spec.origin: |
| 100 | + pkg_dir = os.path.dirname(spec.origin) |
| 101 | + for sub in ['clidriver/cfg', 'dsdriver/cfg']: |
| 102 | + candidates.append(os.path.join(pkg_dir, sub)) |
| 103 | +
|
| 104 | + # 4. Common system install paths |
| 105 | + if sys.platform == 'win32': |
| 106 | + candidates.append(r'C:\Program Files\IBM\clidriver\cfg') |
| 107 | + else: |
| 108 | + candidates.extend([ |
| 109 | + '/opt/ibm/db2/clidriver/cfg', |
| 110 | + '/opt/ibm/dsdriver/cfg', |
| 111 | + os.path.expanduser('~/sqllib/cfg'), |
| 112 | + ]) |
| 113 | +
|
| 114 | + # Return the first candidate whose parent dir exists |
| 115 | + for c in candidates: |
| 116 | + if os.path.isdir(os.path.dirname(c)): |
| 117 | + return c |
| 118 | +
|
| 119 | + return '' |
| 120 | +
|
| 121 | + print(find_cfg()) |
| 122 | + ") |
| 123 | +
|
| 124 | + if [ -z "$CFG_DIR" ]; then |
| 125 | + echo "::error::Could not locate clidriver/cfg or dsdriver/cfg directory" |
| 126 | + exit 1 |
| 127 | + fi |
| 128 | +
|
| 129 | + echo "Writing db2dsdriver.cfg to $CFG_DIR" |
| 130 | + mkdir -p "$CFG_DIR" |
| 131 | + cat > "$CFG_DIR/db2dsdriver.cfg" <<EOF |
| 132 | + <configuration> |
| 133 | + <dsncollection> |
| 134 | + <dsn alias="${{ secrets.DB2_DATABASE }}" name="${{ secrets.DB2_DATABASE }}" host="${{ secrets.DB2_HOSTNAME }}" port="${{ secrets.DB2_PORT }}"> |
| 135 | + <parameter name="Protocol" value="TCPIP"/> |
| 136 | + </dsn> |
| 137 | + </dsncollection> |
| 138 | + <databases> |
| 139 | + <database name="${{ secrets.DB2_DATABASE }}" host="${{ secrets.DB2_HOSTNAME }}" port="${{ secrets.DB2_PORT }}"> |
| 140 | + <parameter name="Protocol" value="TCPIP"/> |
| 141 | + </database> |
| 142 | + </databases> |
| 143 | + </configuration> |
| 144 | + EOF |
| 145 | +
|
| 146 | + - name: Run test suite |
| 147 | + shell: bash |
| 148 | + env: |
| 149 | + DB2_USER: ${{ secrets.DB2_USER }} |
| 150 | + DB2_PASSWD: ${{ secrets.DB2_PASSWD }} |
| 151 | + SINGLE_PYTHON_TEST: ${{ github.event.inputs.test-pattern }} |
| 152 | + run: python ibmdb_tests.py |
0 commit comments