|
| 1 | +name: Ruby Wrapper CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + # Run CI on PRs targeting the main branch |
| 8 | + branches: [ main ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + strategy: |
| 13 | + # Run this job for all 3 major operating systems |
| 14 | + matrix: |
| 15 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + |
| 18 | + services: |
| 19 | + spanner-emulator: |
| 20 | + image: gcr.io/cloud-spanner-emulator/emulator |
| 21 | + ports: |
| 22 | + - 9010:9010 |
| 23 | + |
| 24 | + # The Spanner emulator is now started manually in the steps below |
| 25 | + # instead of using the services block, which requires Docker. |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout code |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up Go |
| 32 | + uses: actions/setup-go@v5 |
| 33 | + with: |
| 34 | + go-version: '1.21' # Or your project's Go version |
| 35 | + |
| 36 | + - name: Set up Ruby |
| 37 | + uses: ruby/setup-ruby@v1 |
| 38 | + with: |
| 39 | + ruby-version: '3.3' # Or your project's Ruby version |
| 40 | + bundler-cache: true |
| 41 | + working-directory: 'spannerlib/wrappers/spannerlib-ruby' |
| 42 | + |
| 43 | + - name: Wait for Emulator |
| 44 | + # This step is crucial to ensure the emulator is ready |
| 45 | + # before the tests try to connect to it. |
| 46 | + run: | |
| 47 | + timeout=60 |
| 48 | + while ! curl -s http://localhost:9010; do |
| 49 | + sleep 1 |
| 50 | + timeout=$((timeout - 1)) |
| 51 | + if [ $timeout -le 0 ]; then |
| 52 | + echo "Emulator failed to start" |
| 53 | + # Print the log file for debugging if it exists |
| 54 | + if [ -f spanner-emulator.log ]; then |
| 55 | + echo "--- Emulator Log ---" |
| 56 | + cat spanner-emulator.log |
| 57 | + echo "--------------------" |
| 58 | + fi |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + done |
| 62 | + shell: bash |
| 63 | + |
| 64 | + # This step automatically figures out the Ruby arch string |
| 65 | + # e.g., "x86_64-linux" or "aarch64-darwin" |
| 66 | + - name: Get Ruby Arch |
| 67 | + id: ruby_arch |
| 68 | + run: echo "arch=$(ruby -r rbconfig -e "puts RbConfig::CONFIG['arch']")" >> $GITHUB_OUTPUT |
| 69 | + shell: bash |
| 70 | + |
| 71 | + - name: Compile Local Native Binary |
| 72 | + working-directory: spannerlib/wrappers/spannerlib-ruby |
| 73 | + run: | |
| 74 | + # Runs the specific compile task for the OS this job is on |
| 75 | + # e.g., bundle exec rake compile:x86_64-linux |
| 76 | + bundle exec rake compile:${{ steps.ruby_arch.outputs.arch }} |
| 77 | +
|
| 78 | + - name: Run RSpec |
| 79 | + working-directory: spannerlib/wrappers/spannerlib-ruby |
| 80 | + env: |
| 81 | + # This tells the tests where to find the emulator |
| 82 | + SPANNER_EMULATOR_HOST: localhost:9010 |
| 83 | + run: bundle exec rake spec |
| 84 | + |
0 commit comments