|
| 1 | +name: MSSQL CI |
| 2 | + |
| 3 | +# Dedicated CI for this MSSQL-focused fork of SQLx. |
| 4 | +# It mirrors the MSSQL-relevant parts of `sqlx.yml` but scoped to MSSQL features |
| 5 | +# only, so the status of the MSSQL driver changes is easy to see at a glance. |
| 6 | +# The upstream `sqlx.yml` / `sqlx-cli.yml` / `examples.yml` workflows are left |
| 7 | +# untouched. |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + - "*-dev" |
| 15 | + |
| 16 | +jobs: |
| 17 | + format: |
| 18 | + name: Format |
| 19 | + runs-on: ubuntu-24.04 |
| 20 | + timeout-minutes: 15 |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v5 |
| 23 | + - run: rustup component add rustfmt |
| 24 | + - run: cargo fmt --all -- --check |
| 25 | + |
| 26 | + check: |
| 27 | + name: Check (MSSQL) |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + runtime: [ tokio ] |
| 32 | + tls: [ native-tls, rustls, none ] |
| 33 | + timeout-minutes: 30 |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v5 |
| 36 | + |
| 37 | + # Swatinem/rust-cache recommends setting up the rust toolchain first |
| 38 | + # because it's used in the cache keys. |
| 39 | + - name: Setup Rust |
| 40 | + run: | |
| 41 | + rustup show active-toolchain || rustup toolchain install |
| 42 | + rustup component add clippy |
| 43 | +
|
| 44 | + - uses: Swatinem/rust-cache@v2 |
| 45 | + |
| 46 | + - run: > |
| 47 | + cargo clippy |
| 48 | + --no-default-features |
| 49 | + --features mssql,any,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }},macros,migrate |
| 50 | + -- -D warnings |
| 51 | +
|
| 52 | + test: |
| 53 | + name: Unit Tests (MSSQL) |
| 54 | + runs-on: ubuntu-24.04 |
| 55 | + timeout-minutes: 30 |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v5 |
| 58 | + |
| 59 | + # `sqlx-mssql --all-features` enables tiberius `integrated-auth-gssapi`, |
| 60 | + # which builds `libgssapi-sys` and needs the Kerberos dev headers. |
| 61 | + - name: Install Kerberos headers (for tiberius integrated-auth-gssapi) |
| 62 | + run: sudo apt-get update && sudo apt-get install -y libkrb5-dev |
| 63 | + |
| 64 | + - name: Setup Rust |
| 65 | + run: rustup show active-toolchain || rustup toolchain install |
| 66 | + |
| 67 | + - uses: Swatinem/rust-cache@v2 |
| 68 | + |
| 69 | + - name: Test sqlx-core |
| 70 | + run: cargo test -p sqlx-core --all-features |
| 71 | + |
| 72 | + - name: Test sqlx-mssql |
| 73 | + run: cargo test -p sqlx-mssql --all-features |
| 74 | + |
| 75 | + # Note: use `--lib` to not run integration tests that require a DB. |
| 76 | + - name: Test sqlx (lib only) |
| 77 | + run: > |
| 78 | + cargo test |
| 79 | + -p sqlx |
| 80 | + --lib |
| 81 | + --no-default-features |
| 82 | + --features mssql,any,_unstable-all-types,macros,migrate,runtime-tokio,tls-rustls |
| 83 | +
|
| 84 | + mssql: |
| 85 | + name: MSSQL |
| 86 | + runs-on: ubuntu-24.04 |
| 87 | + strategy: |
| 88 | + matrix: |
| 89 | + mssql: [ 2022, 2019 ] |
| 90 | + runtime: [ tokio ] |
| 91 | + tls: [ rustls-ring, none ] |
| 92 | + needs: check |
| 93 | + timeout-minutes: 30 |
| 94 | + steps: |
| 95 | + - uses: actions/checkout@v5 |
| 96 | + |
| 97 | + - name: Setup Rust |
| 98 | + run: rustup show active-toolchain || rustup toolchain install |
| 99 | + |
| 100 | + - uses: Swatinem/rust-cache@v2 |
| 101 | + |
| 102 | + - run: > |
| 103 | + cargo build |
| 104 | + --no-default-features |
| 105 | + --features mssql,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }},macros,migrate |
| 106 | +
|
| 107 | + # Retry: the SQL Server base image pull from mcr.microsoft.com can return a |
| 108 | + # transient 403 when many matrix jobs pull it concurrently. |
| 109 | + - name: Start SQL Server |
| 110 | + run: | |
| 111 | + for i in 1 2 3; do |
| 112 | + docker rm -f mssql_${{ matrix.mssql }} 2>/dev/null || true |
| 113 | + if docker compose -f tests/docker-compose.yml run -d -p 1433:1433 --name mssql_${{ matrix.mssql }} mssql_${{ matrix.mssql }}; then |
| 114 | + exit 0 |
| 115 | + fi |
| 116 | + echo "::warning::SQL Server start attempt $i failed (transient registry error?); retrying in 20s" |
| 117 | + sleep 20 |
| 118 | + done |
| 119 | + echo "::error::Failed to start SQL Server after 3 attempts" |
| 120 | + exit 1 |
| 121 | + - run: sleep 60 |
| 122 | + |
| 123 | + # Create data dir for offline mode |
| 124 | + - run: mkdir .sqlx |
| 125 | + |
| 126 | + - run: > |
| 127 | + cargo test |
| 128 | + --no-default-features |
| 129 | + --features any,mssql,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }} |
| 130 | + env: |
| 131 | + DATABASE_URL: mssql://sa:YourStrong!Passw0rd@localhost:1433/sqlx?sslmode=disabled |
| 132 | + SQLX_OFFLINE_DIR: .sqlx |
| 133 | + RUSTFLAGS: --cfg mssql_${{ matrix.mssql }} |
| 134 | +
|
| 135 | + # Run the `test-attr` test again to cover cleanup. |
| 136 | + - run: > |
| 137 | + cargo test |
| 138 | + --test mssql-test-attr |
| 139 | + --no-default-features |
| 140 | + --features any,mssql,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }} |
| 141 | + env: |
| 142 | + DATABASE_URL: mssql://sa:YourStrong!Passw0rd@localhost:1433/sqlx?sslmode=disabled |
| 143 | + SQLX_OFFLINE_DIR: .sqlx |
| 144 | + RUSTFLAGS: --cfg mssql_${{ matrix.mssql }} |
| 145 | +
|
| 146 | + # Remove test artifacts |
| 147 | + - run: cargo clean -p sqlx |
| 148 | + |
| 149 | + # Build the macros-test in offline mode (omit DATABASE_URL) |
| 150 | + - run: > |
| 151 | + cargo build |
| 152 | + --no-default-features |
| 153 | + --test mssql-macros |
| 154 | + --features any,mssql,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }} |
| 155 | + env: |
| 156 | + SQLX_OFFLINE: true |
| 157 | + SQLX_OFFLINE_DIR: .sqlx |
| 158 | + RUSTFLAGS: -D warnings --cfg mssql_${{ matrix.mssql }} |
| 159 | +
|
| 160 | + # Test macros in offline mode (still needs DATABASE_URL to run) |
| 161 | + - run: > |
| 162 | + cargo test |
| 163 | + --no-default-features |
| 164 | + --test mssql-macros |
| 165 | + --features any,mssql,macros,migrate,_unstable-all-types,runtime-${{ matrix.runtime }},tls-${{ matrix.tls }} |
| 166 | + env: |
| 167 | + DATABASE_URL: mssql://sa:YourStrong!Passw0rd@localhost:1433/sqlx?sslmode=disabled |
| 168 | + SQLX_OFFLINE: true |
| 169 | + SQLX_OFFLINE_DIR: .sqlx |
| 170 | + RUSTFLAGS: --cfg mssql_${{ matrix.mssql }} |
0 commit comments