|
| 1 | +name: Cross-platform |
| 2 | + |
| 3 | +# Called by build.yml after build-wasm: macOS and Windows run the plugin.wasm built on Linux (the artifact a release |
| 4 | +# publishes) through sqlc, and the generated code against natively installed PostgreSQL / MySQL and SQLite. |
| 5 | +# The full Ruby / option matrix stays on Linux (tests.yml); here the oldest and newest supported Ruby. |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + DB_NAME: tests |
| 18 | + DB_USER: root |
| 19 | + DB_PASS: pass # ignored by the servers below (trust / empty-password root), required by the pg tests' env |
| 20 | + POSTGRES_HOST: 127.0.0.1 |
| 21 | + MYSQL_HOST: 127.0.0.1 |
| 22 | + |
| 23 | +jobs: |
| 24 | + codegen: |
| 25 | + name: Codegen (${{ matrix.os-name }}, Ruby ${{ matrix.ruby-version }}) |
| 26 | + runs-on: ${{ matrix.os }} |
| 27 | + timeout-minutes: 10 |
| 28 | + |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + os: [macos-latest, windows-latest] |
| 33 | + ruby-version: ['3.1', '4.0'] |
| 34 | + include: |
| 35 | + - { os: macos-latest, os-name: macOS } |
| 36 | + - { os: windows-latest, os-name: Windows } |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v7 |
| 40 | + |
| 41 | + - name: Load tool versions |
| 42 | + run: grep -E '^[A-Z_]+=' scripts/tool-versions.env >> "$GITHUB_ENV" |
| 43 | + |
| 44 | + - uses: sqlc-dev/setup-sqlc@bac53b7fb28c039a6c7f5736fd1e89744021bdd6 # v5.0.0 |
| 45 | + with: |
| 46 | + sqlc-version: '${{ env.SQLC_VERSION }}' |
| 47 | + |
| 48 | + - uses: ruby/setup-ruby@v1 |
| 49 | + with: |
| 50 | + ruby-version: ${{ matrix.ruby-version }} |
| 51 | + |
| 52 | + - uses: actions/download-artifact@v8 |
| 53 | + with: |
| 54 | + name: wasm-file |
| 55 | + path: dist |
| 56 | + |
| 57 | + - name: Updating plugin sha |
| 58 | + run: ./scripts/wasm/update_sha.sh sqlc.ci.yaml |
| 59 | + |
| 60 | + # the process plugin on this OS's Ruby: no bundler, only the standard library + minitest |
| 61 | + - name: Unit & golden tests |
| 62 | + run: ruby -Ilib -Itest -e 'Dir["test/*_test.rb"].sort.each { |file| require File.expand_path(file) }' |
| 63 | + |
| 64 | + # the committed examples/ (LF, byte for byte) must come out of sqlc + the Linux-built WASM on this OS too |
| 65 | + - name: Verify generated code is synced (WASM plugin) |
| 66 | + run: sqlc -f sqlc.ci.yaml diff |
| 67 | + |
| 68 | + - name: Verify generated code is synced (process plugin) |
| 69 | + run: | |
| 70 | + if [ "${RUNNER_OS}" = Windows ]; then |
| 71 | + # Windows cannot execute plugin.rb directly: sqlc runs the exe\plugin.cmd wrapper (through cmd.exe, so backslashes) |
| 72 | + sed 's#cmd: ./exe/plugin.rb#cmd: exe\\plugin.cmd#' sqlc.local.yaml > .sqlc-windows.yaml |
| 73 | + trap 'rm -f .sqlc-windows.yaml' EXIT |
| 74 | + sqlc -f .sqlc-windows.yaml diff |
| 75 | + else |
| 76 | + sqlc -f sqlc.local.yaml diff |
| 77 | + fi |
| 78 | +
|
| 79 | + - name: Generate with the WASM for Ruby ${{ matrix.ruby-version }} and check the output |
| 80 | + run: ruby scripts/tests/run_codegen.rb sqlc.ci.yaml "${{ matrix.ruby-version }}" true true |
| 81 | + |
| 82 | + end2end: |
| 83 | + name: End-to-End (${{ matrix.os-name }}, Ruby ${{ matrix.ruby-version }}) |
| 84 | + runs-on: ${{ matrix.os }} |
| 85 | + timeout-minutes: 10 |
| 86 | + |
| 87 | + strategy: |
| 88 | + fail-fast: false |
| 89 | + matrix: |
| 90 | + os: [macos-latest, windows-latest] |
| 91 | + ruby-version: ['3.1', '4.0'] |
| 92 | + include: |
| 93 | + - { os: macos-latest, os-name: macOS, postgres-version: '16' } |
| 94 | + - { os: windows-latest, os-name: Windows, postgres-version: '17' } # the only version on windows-2025 |
| 95 | + |
| 96 | + env: |
| 97 | + EXAMPLES_DIR: ${{ github.workspace }}/.examples-ruby-${{ matrix.ruby-version }} |
| 98 | + BUNDLE_GEMFILE: ${{ github.workspace }}/Gemfile.e2e |
| 99 | + BUNDLE_PATH: ${{ github.workspace }}/.e2e-gems |
| 100 | + |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v7 |
| 103 | + |
| 104 | + - name: Load tool versions |
| 105 | + run: grep -E '^[A-Z_]+=' scripts/tool-versions.env >> "$GITHUB_ENV" |
| 106 | + |
| 107 | + - uses: sqlc-dev/setup-sqlc@bac53b7fb28c039a6c7f5736fd1e89744021bdd6 # v5.0.0 |
| 108 | + with: |
| 109 | + sqlc-version: '${{ env.SQLC_VERSION }}' |
| 110 | + |
| 111 | + - uses: ankane/setup-postgres@b1a598d92f86cb2ed364411898d150d4eac6d5ca # v1 |
| 112 | + with: |
| 113 | + postgres-version: ${{ matrix.postgres-version }} |
| 114 | + database: ${{ env.DB_NAME }} |
| 115 | + user: ${{ env.DB_USER }} |
| 116 | + |
| 117 | + - uses: ankane/setup-mysql@4aa1b08412d4c8bf537fea5bc412e4e831d839d7 # v1 |
| 118 | + if: runner.os != 'Windows' |
| 119 | + with: |
| 120 | + mysql-version: '8.4' |
| 121 | + database: ${{ env.DB_NAME }} |
| 122 | + user: ${{ env.DB_USER }} |
| 123 | + |
| 124 | + # windows-2025 ships MySQL 8.4 (on PATH); setup-mysql only treats 8.0 as preinstalled there and fails to |
| 125 | + # reinstall 8.4 over it, so start the image's server the same way the action does |
| 126 | + - name: Start the preinstalled MySQL 8.4 (Windows) |
| 127 | + if: runner.os == 'Windows' |
| 128 | + shell: pwsh |
| 129 | + run: | |
| 130 | + $ErrorActionPreference = 'Stop' |
| 131 | + $PSNativeCommandUseErrorActionPreference = $true |
| 132 | + $bin = 'C:\Program Files\MySQL\MySQL Server 8.4\bin' |
| 133 | + & "$bin\mysqld" --initialize-insecure |
| 134 | + & "$bin\mysqld" --install |
| 135 | + net start MySQL |
| 136 | + & "$bin\mysqladmin" -u $env:DB_USER create $env:DB_NAME |
| 137 | +
|
| 138 | + # after the databases: their bin dirs (PostgreSQL ships its own zlib/iconv DLLs) must come after Ruby's MSYS2 |
| 139 | + # toolchain on PATH, or gcc fails silently on Windows and no native gem builds |
| 140 | + - uses: ruby/setup-ruby@v1 |
| 141 | + with: |
| 142 | + ruby-version: ${{ matrix.ruby-version }} |
| 143 | + |
| 144 | + - uses: actions/download-artifact@v8 |
| 145 | + with: |
| 146 | + name: wasm-file |
| 147 | + path: dist |
| 148 | + |
| 149 | + - name: Updating plugin sha |
| 150 | + run: ./scripts/wasm/update_sha.sh sqlc.ci.yaml |
| 151 | + |
| 152 | + # the E2E suites below run this WASM output, with the Gemfile it generates |
| 153 | + - name: Generate the E2E examples with the WASM |
| 154 | + run: ruby scripts/tests/generate_examples.rb "${{ matrix.ruby-version }}" sqlc.ci.yaml --generate-gemfile |
| 155 | + |
| 156 | + - name: Create the schemas (and allow LOAD DATA LOCAL INFILE for :copyfrom) |
| 157 | + run: | |
| 158 | + psql -v ON_ERROR_STOP=1 -h "${POSTGRES_HOST}" -U "${DB_USER}" -d "${DB_NAME}" -f examples/authors/postgresql/schema.sql |
| 159 | + mysql -h "${MYSQL_HOST}" -u "${DB_USER}" -e 'SET GLOBAL local_infile = 1' |
| 160 | + mysql -h "${MYSQL_HOST}" -u "${DB_USER}" --default-character-set=utf8mb4 "${DB_NAME}" < examples/authors/mysql/schema.sql |
| 161 | +
|
| 162 | + - name: Native build settings for mysql2 |
| 163 | + run: | |
| 164 | + if [ "${RUNNER_OS}" = Windows ]; then |
| 165 | + ridk.cmd exec pacman -S --noconfirm --needed mingw-w64-ucrt-x86_64-libmariadbclient |
| 166 | + # mysql2's extconf can't glob for mariadb_config.exe through Windows PATH entries, so point at it |
| 167 | + mariadb_config=$(cygpath -m "${RI_DEVKIT}/ucrt64/bin/mariadb_config.exe") |
| 168 | + test -x "${mariadb_config}" |
| 169 | + echo "BUNDLE_BUILD__MYSQL2=--with-mysql-config=${mariadb_config}" >> "$GITHUB_ENV" |
| 170 | + else |
| 171 | + echo "BUNDLE_BUILD__MYSQL2=--with-opt-dir=$(brew --prefix openssl@3):$(brew --prefix zstd)" >> "$GITHUB_ENV" |
| 172 | + fi |
| 173 | +
|
| 174 | + # prism (minitest 6), mysql2 and date compile from source on Windows (~2 min): keep the installed E2E gems, per runner |
| 175 | + # image (the native extensions link against its libraries) |
| 176 | + - name: Runner image |
| 177 | + id: image |
| 178 | + run: echo "version=${ImageOS}-${ImageVersion}" >> "$GITHUB_OUTPUT" |
| 179 | + |
| 180 | + - uses: actions/cache@v6 |
| 181 | + with: |
| 182 | + path: ${{ env.BUNDLE_PATH }} |
| 183 | + key: e2e-gems-${{ steps.image.outputs.version }}-ruby${{ matrix.ruby-version }}-${{ hashFiles('Gemfile.e2e') }} |
| 184 | + |
| 185 | + - name: End-to-End tests (SQLite) |
| 186 | + if: ${{ !cancelled() }} |
| 187 | + env: |
| 188 | + EXAMPLES_DRIVER: sqlite3 |
| 189 | + run: bundle install && bundle exec rake end2end_sqlite3 |
| 190 | + |
| 191 | + - name: End-to-End tests (PostgreSQL ${{ matrix.postgres-version }}) |
| 192 | + if: ${{ !cancelled() }} |
| 193 | + env: |
| 194 | + EXAMPLES_DRIVER: pg |
| 195 | + run: bundle install && bundle exec rake end2end_pg |
| 196 | + |
| 197 | + - name: End-to-End tests (MySQL 8.4) |
| 198 | + if: ${{ !cancelled() }} |
| 199 | + env: |
| 200 | + EXAMPLES_DRIVER: mysql2 |
| 201 | + run: bundle install && bundle exec rake end2end_mysql2 |
| 202 | + |
| 203 | + - name: Generator options E2E |
| 204 | + if: ${{ !cancelled() }} |
| 205 | + env: |
| 206 | + BUNDLE_GEMFILE: ${{ github.workspace }}/Gemfile.options.e2e |
| 207 | + # default gem path (only prebuilt gems): with BUNDLE_PATH, the test's nested `bundle install` on Windows Ruby |
| 208 | + # 3.1 trips over setup-ruby's newer Bundler next to the default 2.3 one |
| 209 | + run: | |
| 210 | + unset BUNDLE_PATH |
| 211 | + bundle install && bundle exec ruby tests/end2end_options.rb |
| 212 | +
|
| 213 | + - name: Native extension build logs |
| 214 | + if: failure() |
| 215 | + run: find "$(ruby -e 'print Gem.dir')" -name mkmf.log -exec sh -c 'echo "== $1"; cat "$1"' _ {} \; |
0 commit comments