-
Notifications
You must be signed in to change notification settings - Fork 451
290 lines (250 loc) · 10.2 KB
/
Copy pathsdk-ruby.yml
File metadata and controls
290 lines (250 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
name: ruby
on:
workflow_dispatch:
pull_request:
paths:
- ".github/**"
- "sdks/ruby/**"
push:
branches:
- main
paths:
- "sdks/ruby/**"
defaults:
run:
working-directory: ./sdks/ruby/src
jobs:
lint:
runs-on: ubicloud-standard-4
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Set up Ruby
uses: ruby/setup-ruby@89f90524b88a01fe6e0b732220432cc6142926af # v1.313.0
with:
ruby-version: "3.2"
bundler-cache: true
working-directory: ./sdks/ruby/src
- name: Run RuboCop
run: bundle exec rubocop
- name: Run RBS validate
run: rbs -I sig validate
- name: Test gem build
run: gem build hatchet-sdk.gemspec
test:
runs-on: ubicloud-standard-4
strategy:
matrix:
ruby-version: ${{ github.event_name == 'pull_request' && fromJSON('["3.2"]') || fromJSON('["3.2", "3.3"]') }}
optimistic-scheduling: ["true", "false"]
timeout-minutes: 20
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Protoc
uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
version: "25.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26"
- name: Start Docker dependencies
working-directory: .
run: docker compose up -d
- name: Generate
working-directory: .
run: |
export DATABASE_URL="postgresql://hatchet:hatchet@127.0.0.1:5431/hatchet"
go run ./cmd/hatchet-migrate
- name: Setup
working-directory: .
run: |
export SEED_DEVELOPMENT=true
export SERVER_PORT=8080
export SERVER_URL=http://localhost:8080
export SERVER_AUTH_COOKIE_DOMAIN=localhost
export SERVER_AUTH_COOKIE_INSECURE=true
export SERVER_DEFAULT_ENGINE_VERSION=V1
export SERVER_MSGQUEUE_RABBITMQ_URL="amqp://user:password@localhost:5672/"
export SERVER_OPTIMISTIC_SCHEDULING_ENABLED=${{ matrix.optimistic-scheduling }}
go run ./cmd/hatchet-admin quickstart
go run ./cmd/hatchet-engine --config ./generated/ > engine.log 2>&1 &
go run ./cmd/hatchet-api --config ./generated/ > api.log 2>&1 &
sleep 30
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@89f90524b88a01fe6e0b732220432cc6142926af # v1.313.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
working-directory: ./sdks/ruby/src
- name: Display Ruby version
run: ruby -v
- name: Generate Env File
working-directory: .
run: |
echo "HATCHET_CLIENT_TOKEN=$(go run ./cmd/hatchet-admin token create --config ./generated/ --tenant-id 707d0855-80ab-4e1f-a156-f1c4546cbf52)" >> $GITHUB_ENV
echo "HATCHET_CLIENT_TLS_ROOT_CA_FILE=../../../certs/ca.cert" >> $GITHUB_ENV
echo "HATCHET_CLIENT_WORKER_HEALTHCHECK_ENABLED=true" >> $GITHUB_ENV
- name: Set HATCHET_CLIENT_NAMESPACE
run: |
RUBY_VER=$(ruby -e "puts \"rb#{RUBY_VERSION.gsub('.','')[0..1]}\"")
SHORT_SHA=$(git rev-parse --short HEAD)
echo "HATCHET_CLIENT_NAMESPACE=${RUBY_VER}-${SHORT_SHA}" >> $GITHUB_ENV
- name: Run unit tests
run: |
echo "Using HATCHET_CLIENT_NAMESPACE: $HATCHET_CLIENT_NAMESPACE"
bundle exec rspec --format documentation --tag ~integration
- name: Run integration tests
run: bundle exec rspec spec/integration/ --format documentation --tag integration
- name: Set up Ruby for examples
uses: ruby/setup-ruby@89f90524b88a01fe6e0b732220432cc6142926af # v1.313.0
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
working-directory: ./sdks/ruby/examples
- name: Wait for API readiness
working-directory: .
run: |
echo "Waiting for API at http://localhost:8080/api/ready..."
for i in $(seq 1 60); do
if curl -sf http://localhost:8080/api/ready > /dev/null 2>&1; then
echo "API ready after ${i}s"
break
fi
if [ "$i" -eq 60 ]; then
echo "API did not become ready within 60s"
tail -n 50 engine.log 2>/dev/null || true
tail -n 50 api.log 2>/dev/null || true
exit 1
fi
sleep 1
done
sleep 5
- name: Start example worker and wait for health
working-directory: ./sdks/ruby/examples
run: |
export HATCHET_CLIENT_WORKER_HEALTHCHECK_PORT=8001
stdbuf -o0 -e0 bundle exec ruby worker.rb > worker.log 2>&1 &
WORKER_PID=$!
echo "Worker started with PID $WORKER_PID"
MAX_WAIT=45
POLL_INTERVAL=1
echo "Waiting 5s for worker to initialize..."
sleep 5
for i in $(seq 1 $MAX_WAIT); do
if ! kill -0 "$WORKER_PID" 2>/dev/null; then
echo "Worker process (PID $WORKER_PID) exited before becoming healthy"
echo "=== worker.log ==="
cat worker.log || true
echo "=== tail engine.log ==="
tail -n 80 "$GITHUB_WORKSPACE/engine.log" 2>/dev/null || true
echo "=== tail api.log ==="
tail -n 80 "$GITHUB_WORKSPACE/api.log" 2>/dev/null || true
exit 1
fi
if curl -sf http://localhost:8001/health > /dev/null 2>&1; then
echo "Worker is healthy after ${i}s"
exit 0
fi
if [ $((i % 5)) -eq 0 ]; then
echo "Still waiting for worker health... ${i}s/${MAX_WAIT}s"
echo "--- worker.log (last 25 lines) ---"
tail -n 25 worker.log 2>/dev/null || true
echo "--- engine.log (last 25 lines) ---"
tail -n 25 "$GITHUB_WORKSPACE/engine.log" 2>/dev/null || true
echo "--- api.log (last 25 lines) ---"
tail -n 25 "$GITHUB_WORKSPACE/api.log" 2>/dev/null || true
fi
sleep $POLL_INTERVAL
done
echo "Worker failed to become healthy within ${MAX_WAIT}s"
echo "=== worker.log ==="
cat worker.log || true
echo "=== tail engine.log ==="
tail -n 80 "$GITHUB_WORKSPACE/engine.log" 2>/dev/null || true
echo "=== tail api.log ==="
tail -n 80 "$GITHUB_WORKSPACE/api.log" 2>/dev/null || true
exit 1
- name: Run e2e tests
working-directory: ./sdks/ruby/examples
run: bundle exec rspec -f d --fail-fast
- name: Upload worker logs
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ env.HATCHET_CLIENT_NAMESPACE }}-opt-${{ matrix.optimistic-scheduling }}-worker-logs
path: ./sdks/ruby/examples/worker.log
- name: Upload engine logs
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ env.HATCHET_CLIENT_NAMESPACE }}-opt-${{ matrix.optimistic-scheduling }}-engine-logs
path: engine.log
- name: Upload API logs
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ env.HATCHET_CLIENT_NAMESPACE }}-opt-${{ matrix.optimistic-scheduling }}-api-logs
path: api.log
publish:
runs-on: ubicloud-standard-4
needs: [lint, test]
if: github.ref == 'refs/heads/main'
permissions:
contents: write
id-token: write
steps:
- name: Checkout Repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
submodules: recursive
- name: Set up Ruby
uses: ruby/setup-ruby@89f90524b88a01fe6e0b732220432cc6142926af # v1.313.0
with:
ruby-version: "3.2"
bundler-cache: true
working-directory: ./sdks/ruby/src
- name: Check if version changed
id: version_check
run: |
NEW_VERSION=$(ruby -e "require_relative 'lib/hatchet/version'; puts Hatchet::VERSION")
CURRENT_VERSION=$(gem info hatchet-sdk --remote --exact 2>/dev/null | grep -oP 'hatchet-sdk \(\K[^)]+' || echo "0.0.0")
if [ "$CURRENT_VERSION" == "$NEW_VERSION" ]; then
echo "Version has not changed ($NEW_VERSION). Skipping publish."
echo "should_publish=false" >> "$GITHUB_OUTPUT"
else
echo "Publishing version $NEW_VERSION (current: $CURRENT_VERSION)"
echo "should_publish=true" >> "$GITHUB_OUTPUT"
fi
- name: Configure RubyGems credentials
if: steps.version_check.outputs.should_publish == 'true'
uses: rubygems/configure-rubygems-credentials@main
- name: Publish to RubyGems
if: steps.version_check.outputs.should_publish == 'true'
run: |
gem build hatchet-sdk.gemspec
NEW_VERSION=$(ruby -e "require_relative 'lib/hatchet/version'; puts Hatchet::VERSION")
gem push hatchet-sdk-${NEW_VERSION}.gem
echo "VERSION_TAG=$NEW_VERSION" >> $GITHUB_ENV
- name: "Generate release notes"
if: env.VERSION_TAG != ''
working-directory: ${{ github.workspace }}
run: ./hack/ci/release-notes.sh ruby > ./release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Release"
if: env.VERSION_TAG != ''
working-directory: ${{ github.workspace }}
run: |
gh release create "rb/${VERSION_TAG}" \
--target "$GITHUB_SHA" \
--title "Ruby SDK ${VERSION_TAG}" \
--notes-file ./release_notes.md \
--latest=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}