Skip to content

Commit d07cb6e

Browse files
committed
chore(ruby): Add github workflows to verify wrapper tests work on all platforms
1 parent c2e43d1 commit d07cb6e

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
# The Spanner emulator is now started manually in the steps below
19+
# instead of using the services block, which requires Docker.
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: '1.21' # Or your project's Go version
29+
30+
- name: Set up Ruby
31+
uses: ruby/setup-ruby@v1
32+
with:
33+
ruby-version: '3.3' # Or your project's Ruby version
34+
bundler-cache: true
35+
working-directory: 'spannerlib/wrappers/spannerlib-ruby'
36+
37+
- name: Set up Google Cloud CLI
38+
uses: 'google-github-actions/setup-gcloud@v2'
39+
with:
40+
version: 'latest'
41+
42+
- name: Update and Install Spanner Emulator (Linux/macOS)
43+
if: runner.os == 'Linux' || runner.os == 'macOS'
44+
run: |
45+
echo "Runner OS: ${{ runner.os }}"
46+
echo "Runner Arch: $(uname -m)"
47+
echo "---- gcloud version BEFORE update ----"
48+
gcloud --version
49+
echo "---- Running gcloud components update ----"
50+
gcloud components update --quiet
51+
echo "---- gcloud version AFTER update ----"
52+
gcloud --version
53+
echo "---- gcloud components list AFTER update ----"
54+
gcloud components list
55+
echo "---- Searching for cloud-spanner-emulator in the list ----"
56+
if gcloud components list | grep -q cloud-spanner-emulator; then
57+
echo "cloud-spanner-emulator FOUND in list"
58+
else
59+
echo "cloud-spanner-emulator NOT FOUND in list"
60+
fi
61+
echo "---- Attempting to install cloud-spanner-emulator ----"
62+
gcloud components install cloud-spanner-emulator --quiet
63+
shell: bash
64+
65+
66+
- name: Start Spanner Emulator (Linux/macOS)
67+
if: runner.os == 'Linux' || runner.os == 'macOS'
68+
run: |
69+
# Start in background, but log stdout/stderr to a file
70+
gcloud beta emulators spanner start --host-port=localhost:9010 > spanner-emulator.log 2>&1 &
71+
72+
- name: Start Spanner Emulator (Windows)
73+
if: runner.os == 'Windows'
74+
shell: powershell
75+
run: |
76+
# Start-Process runs in the background by default
77+
Start-Process gcloud "beta emulators spanner start --host-port=localhost:9010" -RedirectStandardOutput "spanner-emulator.log" -RedirectStandardError "spanner-emulator.log"
78+
79+
- name: Wait for Emulator
80+
# This step is crucial to ensure the emulator is ready
81+
# before the tests try to connect to it.
82+
run: |
83+
timeout=60
84+
while ! curl -s http://localhost:9010; do
85+
sleep 1
86+
timeout=$((timeout - 1))
87+
if [ $timeout -le 0 ]; then
88+
echo "Emulator failed to start"
89+
# Print the log file for debugging if it exists
90+
if [ -f spanner-emulator.log ]; then
91+
echo "--- Emulator Log ---"
92+
cat spanner-emulator.log
93+
echo "--------------------"
94+
fi
95+
exit 1
96+
fi
97+
done
98+
shell: bash
99+
100+
# This step automatically figures out the Ruby arch string
101+
# e.g., "x86_64-linux" or "aarch64-darwin"
102+
- name: Get Ruby Arch
103+
id: ruby_arch
104+
run: echo "arch=$(ruby -r rbconfig -e "puts RbConfig::CONFIG['arch']")" >> $GITHUB_OUTPUT
105+
shell: bash
106+
107+
- name: Compile Local Native Binary
108+
working-directory: spannerlib/wrappers/spannerlib-ruby
109+
run: |
110+
# Runs the specific compile task for the OS this job is on
111+
# e.g., bundle exec rake compile:x86_64-linux
112+
bundle exec rake compile:${{ steps.ruby_arch.outputs.arch }}
113+
114+
- name: Run RSpec
115+
working-directory: spannerlib/wrappers/spannerlib-ruby
116+
env:
117+
# This tells the tests where to find the emulator
118+
SPANNER_EMULATOR_HOST: localhost:9010
119+
run: bundle exec rake spec
120+

0 commit comments

Comments
 (0)