-
Notifications
You must be signed in to change notification settings - Fork 15
287 lines (249 loc) · 9.18 KB
/
Copy pathcd.yml
File metadata and controls
287 lines (249 loc) · 9.18 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
name: Ruby - Continuous Deployment
on:
push:
tags:
- "v*.*"
workflow_dispatch:
inputs:
version:
description: "The release version of GLIDE, formatted as *.*.* or *.*.*-rc*"
required: true
publish_gem:
description: "Publish to RubyGems"
required: true
type: boolean
default: false
concurrency:
group: ruby-cd-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
jobs:
load-platform-matrix:
runs-on: ubuntu-latest
outputs:
PLATFORM_MATRIX: ${{ steps.load-platform-matrix.outputs.PLATFORM_MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load platform matrix
id: load-platform-matrix
shell: bash
run: |
export PLATFORM_MATRIX=$(jq -c '.' < .github/json_matrices/build-matrix.json)
echo "PLATFORM_MATRIX=${PLATFORM_MATRIX}" >> $GITHUB_OUTPUT
echo "Loaded platform matrix: ${PLATFORM_MATRIX}"
set-release-version:
runs-on: ubuntu-latest
outputs:
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
steps:
- name: Set the release version
id: release-version
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
R_VERSION="${{ github.event.inputs.version }}"
else
# Remove 'v' prefix from tag
R_VERSION="${GITHUB_REF_NAME#v}"
fi
echo "Release version: $R_VERSION"
echo "RELEASE_VERSION=$R_VERSION" >> $GITHUB_OUTPUT
- name: Validate version format
run: |
VERSION="${{ steps.release-version.outputs.RELEASE_VERSION }}"
if ! echo "$VERSION" | grep -Pq '^\d+\.\d+\.\d+(-rc\d+)?$'; then
echo "Invalid version format: $VERSION"
echo "Expected format: X.Y.Z or X.Y.Z-rcN"
exit 1
fi
build-native-libraries:
needs: [set-release-version, load-platform-matrix]
strategy:
fail-fast: false
matrix:
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
runs-on: ${{ matrix.host.RUNNER }}
env:
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
with:
version: "29.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build native library
working-directory: valkey-glide/ffi
env:
GLIDE_NAME: GlideRuby
GLIDE_VERSION: ${{ env.RELEASE_VERSION }}
run: |
cargo build --release
- name: Upload native library artifact
uses: actions/upload-artifact@v4
with:
name: native-lib-${{ matrix.host.TARGET }}
path: valkey-glide/ffi/target/release/libglide_ffi.so
if-no-files-found: error
build-and-publish-gem:
needs: [set-release-version, load-platform-matrix, build-native-libraries]
runs-on: ubuntu-latest
env:
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
PLATFORM_MATRIX: ${{ needs.load-platform-matrix.outputs.PLATFORM_MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Download all native library artifacts
uses: actions/download-artifact@v4
with:
pattern: native-lib-*
path: native-libs
- name: Organize native libraries for gem
run: |
echo "Creating native library directories from matrix..."
for target in $(echo '${{ env.PLATFORM_MATRIX }}' | jq -r '.[].TARGET'); do
echo "Creating directory for $target"
mkdir -p "lib/valkey/native/$target"
echo "Copying native library for $target"
cp "native-libs/native-lib-$target/libglide_ffi.so" "lib/valkey/native/$target/"
done
echo "Native libraries organized:"
find lib/valkey/native -type f -exec ls -lh {} \;
- name: Update gem version
run: |
sed -i "s/VERSION = .*/VERSION = \"${{ env.RELEASE_VERSION }}\"/" lib/valkey/version.rb
echo "Updated version.rb:"
cat lib/valkey/version.rb
- name: Build gem
id: build-gem
run: |
gem build valkey.gemspec
echo "Built gem:"
ls -lh *.gem
# Capture the actual gem filename (RubyGems may transform version format)
GEM_FILE=$(ls *.gem | head -1)
echo "GEM_FILE=${GEM_FILE}" >> $GITHUB_OUTPUT
echo "Gem file: ${GEM_FILE}"
- name: Verify gem contents
run: |
gem unpack ${{ steps.build-gem.outputs.GEM_FILE }} --target=gem-contents
echo "Gem contents:"
find gem-contents -type f | head -50
echo ""
echo "Native libraries in gem:"
find gem-contents -name "libglide_ffi.*" -exec ls -lh {} \;
- name: Upload gem artifact
uses: actions/upload-artifact@v4
with:
name: ruby-gem
path: "*.gem"
if-no-files-found: error
- name: Publish to RubyGems
id: publish
if: ${{ github.event_name == 'push' || inputs.publish_gem == true }}
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
gem push ${{ steps.build-gem.outputs.GEM_FILE }}
echo "published=true" >> $GITHUB_OUTPUT
outputs:
published: ${{ steps.publish.outputs.published || 'false' }}
test-gem:
needs: [set-release-version, load-platform-matrix, build-and-publish-gem]
strategy:
fail-fast: false
matrix:
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
runs-on: ${{ matrix.host.RUNNER }}
env:
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
steps:
- name: Checkout (for test files)
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: false # We'll install gems manually
- name: Install test dependencies
run: |
# Install test dependencies as system gems (not via bundler)
# This avoids bundler's gemspec loading which would pull in local lib
# Use specific versions to match Gemfile.lock for consistency
gem install minitest -v 5.27.0
gem install minitest-reporters -v 1.8.0
gem install ansi
gem install ruby-progressbar
gem install rake
- name: Start Valkey
run: |
docker run -d --name valkey-test -p 6379:6379 valkey/valkey:8
sleep 5
docker exec valkey-test valkey-cli ping
- name: Download gem artifact (unpublished)
if: ${{ needs.build-and-publish-gem.outputs.published != 'true' }}
uses: actions/download-artifact@v4
with:
name: ruby-gem
path: .
- name: Install gem from artifact (unpublished)
if: ${{ needs.build-and-publish-gem.outputs.published != 'true' }}
run: |
GEM_FILE=$(ls *.gem | head -1)
echo "Installing gem from artifact: ${GEM_FILE}"
gem install "${GEM_FILE}"
echo "Installed gem:"
# Get gem name from gemspec for listing
GEM_NAME=$(ruby -e "puts Gem::Specification.load('valkey.gemspec').name")
gem list "${GEM_NAME}"
- name: Install gem from RubyGems (published)
if: ${{ needs.build-and-publish-gem.outputs.published == 'true' }}
run: |
echo "Installing published gem from RubyGems..."
# Wait a bit for RubyGems to index the new version
sleep 30
# Get gem name from gemspec
GEM_NAME=$(ruby -e "puts Gem::Specification.load('valkey.gemspec').name")
echo "Installing gem: ${GEM_NAME}"
gem install "${GEM_NAME}" --version "${{ env.RELEASE_VERSION }}" || gem install "${GEM_NAME}" --pre
echo "Installed gem:"
gem list "${GEM_NAME}"
- name: Test gem loading
run: |
ruby -e "
require 'valkey'
puts 'Valkey gem loaded successfully!'
puts 'Testing basic client creation...'
# Just verify the FFI library loaded correctly
puts 'FFI library loaded: OK'
"
- name: Run standalone tests
env:
TEST_INSTALLED_GEM: "true"
run: |
# Remove local lib to ensure we use the installed gem
# The installed gem has the native library, local lib doesn't
rm -rf lib/
# Run tests - they will use the installed gem
rake test:standalone
- name: Stop Valkey
if: always()
run: docker stop valkey-test && docker rm valkey-test || true