|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + paths-ignore: |
| 7 | + - '**.md' |
| 8 | + - '.spi.yml' |
| 9 | + - 'Sources/**/*.docc/**' |
| 10 | + pull_request: |
| 11 | + branches: [main] |
| 12 | + paths-ignore: |
| 13 | + - '**.md' |
| 14 | + - '.spi.yml' |
| 15 | + - 'Sources/**/*.docc/**' |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +# ───────────────────────────────────────────────────────────────────────────── |
| 22 | +# Environment variables shared across all jobs |
| 23 | +# ───────────────────────────────────────────────────────────────────────────── |
| 24 | +env: |
| 25 | + SWIFT_VERSION: "6.0" |
| 26 | + |
| 27 | +jobs: |
| 28 | + # ─────────────────────────────────────────────────────────────────────────── |
| 29 | + # 1. Build + SQLite tests — macOS and Linux, multiple Swift versions |
| 30 | + # No Docker needed — SQLite uses an in-memory database. |
| 31 | + # ─────────────────────────────────────────────────────────────────────────── |
| 32 | + test-sqlite: |
| 33 | + name: SQLite — ${{ matrix.os }} / Swift ${{ matrix.swift }} |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + os: [macos-15, ubuntu-24.04] |
| 39 | + swift: ["5.10", "6.0"] |
| 40 | + exclude: |
| 41 | + # macOS 15 ships with Swift 6 (Xcode 16); skip redundant 5.10 run |
| 42 | + - os: macos-15 |
| 43 | + swift: "5.10" |
| 44 | + steps: |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Setup Swift ${{ matrix.swift }} |
| 49 | + if: runner.os == 'Linux' |
| 50 | + uses: swift-actions/setup-swift@v2 |
| 51 | + with: |
| 52 | + swift-version: ${{ matrix.swift }} |
| 53 | + |
| 54 | + - name: Cache SPM |
| 55 | + uses: actions/cache@v4 |
| 56 | + with: |
| 57 | + path: .build |
| 58 | + key: ${{ runner.os }}-spm-${{ matrix.swift }}-${{ hashFiles('Package.resolved') }} |
| 59 | + restore-keys: | |
| 60 | + ${{ runner.os }}-spm-${{ matrix.swift }}- |
| 61 | +
|
| 62 | + - name: Build |
| 63 | + run: swift build --configuration debug 2>&1 |
| 64 | + |
| 65 | + - name: Run SQLite tests |
| 66 | + run: swift test --filter SQLiteNioTests 2>&1 |
| 67 | + |
| 68 | + - name: Run Core tests |
| 69 | + run: swift test --filter SQLNioCoreTests 2>&1 |
| 70 | + |
| 71 | + # ─────────────────────────────────────────────────────────────────────────── |
| 72 | + # 2. SQL Server integration tests |
| 73 | + # Uses GitHub Actions service container — Linux only. |
| 74 | + # ─────────────────────────────────────────────────────────────────────────── |
| 75 | + test-mssql: |
| 76 | + name: SQL Server integration tests |
| 77 | + runs-on: ubuntu-24.04 |
| 78 | + services: |
| 79 | + mssql: |
| 80 | + image: mcr.microsoft.com/mssql/server:2022-latest |
| 81 | + env: |
| 82 | + ACCEPT_EULA: "Y" |
| 83 | + SA_PASSWORD: "aBCD111!" |
| 84 | + MSSQL_PID: Developer |
| 85 | + ports: |
| 86 | + - 1433:1433 |
| 87 | + options: >- |
| 88 | + --health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'aBCD111!' -Q 'SELECT 1' -C" |
| 89 | + --health-interval 10s |
| 90 | + --health-timeout 5s |
| 91 | + --health-retries 15 |
| 92 | + steps: |
| 93 | + - name: Checkout |
| 94 | + uses: actions/checkout@v4 |
| 95 | + |
| 96 | + - name: Setup Swift |
| 97 | + uses: swift-actions/setup-swift@v2 |
| 98 | + with: |
| 99 | + swift-version: ${{ env.SWIFT_VERSION }} |
| 100 | + |
| 101 | + - name: Cache SPM |
| 102 | + uses: actions/cache@v4 |
| 103 | + with: |
| 104 | + path: .build |
| 105 | + key: ${{ runner.os }}-spm-mssql-${{ hashFiles('Package.resolved') }} |
| 106 | + restore-keys: | |
| 107 | + ${{ runner.os }}-spm-mssql- |
| 108 | +
|
| 109 | + - name: Create test database |
| 110 | + run: | |
| 111 | + until /opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'aBCD111!' -C \ |
| 112 | + -Q "CREATE DATABASE MSSQLNioTestDb" 2>/dev/null; do |
| 113 | + echo "Waiting for SQL Server..."; sleep 3 |
| 114 | + done |
| 115 | +
|
| 116 | + - name: Run MSSQL tests |
| 117 | + env: |
| 118 | + MSSQL_TEST_HOST: "127.0.0.1" |
| 119 | + MSSQL_TEST_PASS: "aBCD111!" |
| 120 | + MSSQL_TEST_DB: "MSSQLNioTestDb" |
| 121 | + MSSQL_TEST_USER: "sa" |
| 122 | + run: swift test --filter MSSQLNioTests 2>&1 |
| 123 | + |
| 124 | + # ─────────────────────────────────────────────────────────────────────────── |
| 125 | + # 3. PostgreSQL integration tests |
| 126 | + # ─────────────────────────────────────────────────────────────────────────── |
| 127 | + test-postgres: |
| 128 | + name: PostgreSQL integration tests |
| 129 | + runs-on: ubuntu-24.04 |
| 130 | + services: |
| 131 | + postgres: |
| 132 | + image: postgres:16-alpine |
| 133 | + env: |
| 134 | + POSTGRES_DB: PostgresNioTestDb |
| 135 | + POSTGRES_USER: pguser |
| 136 | + POSTGRES_PASSWORD: pgPass123 |
| 137 | + ports: |
| 138 | + - 5432:5432 |
| 139 | + options: >- |
| 140 | + --health-cmd "pg_isready -U pguser -d PostgresNioTestDb" |
| 141 | + --health-interval 5s |
| 142 | + --health-timeout 3s |
| 143 | + --health-retries 10 |
| 144 | + steps: |
| 145 | + - name: Checkout |
| 146 | + uses: actions/checkout@v4 |
| 147 | + |
| 148 | + - name: Setup Swift |
| 149 | + uses: swift-actions/setup-swift@v2 |
| 150 | + with: |
| 151 | + swift-version: ${{ env.SWIFT_VERSION }} |
| 152 | + |
| 153 | + - name: Cache SPM |
| 154 | + uses: actions/cache@v4 |
| 155 | + with: |
| 156 | + path: .build |
| 157 | + key: ${{ runner.os }}-spm-pg-${{ hashFiles('Package.resolved') }} |
| 158 | + restore-keys: | |
| 159 | + ${{ runner.os }}-spm-pg- |
| 160 | +
|
| 161 | + - name: Run PostgreSQL tests |
| 162 | + env: |
| 163 | + PG_TEST_HOST: "127.0.0.1" |
| 164 | + PG_TEST_DB: PostgresNioTestDb |
| 165 | + PG_TEST_USER: pguser |
| 166 | + PG_TEST_PASS: pgPass123 |
| 167 | + run: swift test --filter PostgresNioTests 2>&1 |
| 168 | + |
| 169 | + # ─────────────────────────────────────────────────────────────────────────── |
| 170 | + # 4. MySQL integration tests |
| 171 | + # ─────────────────────────────────────────────────────────────────────────── |
| 172 | + test-mysql: |
| 173 | + name: MySQL integration tests |
| 174 | + runs-on: ubuntu-24.04 |
| 175 | + services: |
| 176 | + mysql: |
| 177 | + image: mysql:8 |
| 178 | + env: |
| 179 | + MYSQL_DATABASE: MySQLNioTestDb |
| 180 | + MYSQL_USER: mysqluser |
| 181 | + MYSQL_PASSWORD: mysqlPass123 |
| 182 | + MYSQL_ROOT_PASSWORD: root |
| 183 | + ports: |
| 184 | + - 3306:3306 |
| 185 | + options: >- |
| 186 | + --health-cmd "mysqladmin ping -u mysqluser -pmysqlPass123" |
| 187 | + --health-interval 5s |
| 188 | + --health-timeout 3s |
| 189 | + --health-retries 15 |
| 190 | + steps: |
| 191 | + - name: Checkout |
| 192 | + uses: actions/checkout@v4 |
| 193 | + |
| 194 | + - name: Setup Swift |
| 195 | + uses: swift-actions/setup-swift@v2 |
| 196 | + with: |
| 197 | + swift-version: ${{ env.SWIFT_VERSION }} |
| 198 | + |
| 199 | + - name: Cache SPM |
| 200 | + uses: actions/cache@v4 |
| 201 | + with: |
| 202 | + path: .build |
| 203 | + key: ${{ runner.os }}-spm-mysql-${{ hashFiles('Package.resolved') }} |
| 204 | + restore-keys: | |
| 205 | + ${{ runner.os }}-spm-mysql- |
| 206 | +
|
| 207 | + - name: Run MySQL tests |
| 208 | + env: |
| 209 | + MYSQL_TEST_HOST: "127.0.0.1" |
| 210 | + MYSQL_TEST_DB: MySQLNioTestDb |
| 211 | + MYSQL_TEST_USER: mysqluser |
| 212 | + MYSQL_TEST_PASS: mysqlPass123 |
| 213 | + run: swift test --filter MySQLNioTests 2>&1 |
| 214 | + |
| 215 | + # ─────────────────────────────────────────────────────────────────────────── |
| 216 | + # 5. Summary / Required status check |
| 217 | + # PRs cannot be merged until all four test jobs pass. |
| 218 | + # ─────────────────────────────────────────────────────────────────────────── |
| 219 | + ci-success: |
| 220 | + name: All tests passed |
| 221 | + runs-on: ubuntu-24.04 |
| 222 | + needs: [test-sqlite, test-mssql, test-postgres, test-mysql] |
| 223 | + if: always() |
| 224 | + steps: |
| 225 | + - name: Check results |
| 226 | + run: | |
| 227 | + if [[ "${{ needs.test-sqlite.result }}" != "success" || \ |
| 228 | + "${{ needs.test-mssql.result }}" != "success" || \ |
| 229 | + "${{ needs.test-postgres.result }}" != "success" || \ |
| 230 | + "${{ needs.test-mysql.result }}" != "success" ]]; then |
| 231 | + echo "One or more test jobs failed." |
| 232 | + exit 1 |
| 233 | + fi |
| 234 | + echo "All test jobs passed." |
0 commit comments