1 name: SDK Ruby Gem Release
2
3 # Publishes the smbcloud-auth Ruby gem (sdk/gems/auth) to RubyGems.
4 # Builds pre-compiled native gems for the supported Unix platforms, plus a
5 # source gem as a fallback for unsupported environments.
6 #
7 # Required secrets:
8 # RUBYGEMS_API_KEY — RubyGems.org API key with push access to smbcloud-auth
9
10 on:
11 workflow_dispatch:
12 inputs:
13 tag:
14 description: "Release tag (e.g. v0.3.35)"
15 required: true
16
17 permissions:
18 contents: read
19
20 env:
21 CARGO_TERM_COLOR: always
22
23 jobs:
24 # ── Build native gems ──────────────────────────────────────────────────────
25 build-gems:
26 name: Build gem (${{ matrix.name }})
27 runs-on: ${{ matrix.runner }}
28 strategy:
29 fail-fast: false
30 matrix:
31 include:
32 - { name: linux-x64, runner: ubuntu-latest, platform: x86_64-linux }
33 - {
34 name: linux-arm64,
35 runner: ubuntu-24.04-arm,
36 platform: aarch64-linux,
37 }
38 - { name: darwin-arm64, runner: macos-latest, platform: arm64-darwin }
39 - {
40 name: darwin-x64,
41 runner: macos-15-intel,
42 platform: x86_64-darwin,
43 }
44 # Windows is excluded: rb-sys bindgen fails because RubyInstaller is
45 # MinGW-based and its rbconfig emits GCC flags that are incompatible
46 # with the MSVC clang used by bindgen. The source gem provides a
47 # fallback for Windows users (compiled at install time).
48
49 steps:
50 - name: Checkout
51 uses: actions/checkout@v6
52 with:
53 ref: ${{ github.event.inputs.tag || github.ref }}
54
55 - name: Set the release version
56 shell: bash
57 run: |
58 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
59 release_version="${GITHUB_REF_NAME#v}"
60 else
61 release_version="${{ github.event.inputs.tag }}"
62 release_version="${release_version#v}"
63 fi
64 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
65
66 - name: Wait for Rust crate dependencies on crates.io
67 shell: bash
68 run: |
69 for crate_name in smbcloud-auth-sdk smbcloud-model smbcloud-network; do
70 for attempt in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
71 if curl -fsS -H "User-Agent: smbcloud-cli-release" "https://crates.io/api/v1/crates/${crate_name}/${RELEASE_VERSION}" >/dev/null 2>&1; then
72 echo "${crate_name} ${RELEASE_VERSION} is available on crates.io"
73 break
74 fi
75
76 if [ "$attempt" -eq 20 ]; then
77 echo "Timed out waiting for ${crate_name} ${RELEASE_VERSION} on crates.io" >&2
78 exit 1
79 fi
80
81 echo "Waiting for ${crate_name} ${RELEASE_VERSION} to appear on crates.io..."
82 sleep 15
83 done
84 done
85
86 - name: Install system dependencies (Linux)
87 if: runner.os == 'Linux'
88 run: sudo apt-get update -q && sudo apt-get install -y libclang-dev
89
90 - name: Read Rust toolchain
91 shell: bash
92 run: |
93 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
94 if [ -z "$rust_toolchain" ]; then
95 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
96 exit 1
97 fi
98 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
99
100 - name: Install toolkit
101 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
102 with:
103 toolchain: ${{ env.RUST_TOOLCHAIN }}
104
105 # Scope the Rust cache to the gem's own Cargo workspace so its registry
106 # deps are cached independently from the main workspace.
107 - name: Setup Rust cache
108 uses: Swatinem/rust-cache@v2
109 with:
110 key: sdk-gem-${{ matrix.name }}
111 workspaces: sdk/gems/auth
112
113 - name: Setup Ruby
114 uses: ruby/setup-ruby@v1
115 with:
116 ruby-version: "3.4.2"
117 bundler-cache: true
118 working-directory: sdk/gems/auth
119
120 - name: Build native gem
121 working-directory: sdk/gems/auth
122 shell: bash
123 run: bundle exec rake native gem
124
125 - name: Upload gem artifact
126 uses: actions/upload-artifact@v7
127 with:
128 name: gem-${{ matrix.name }}
129 path: sdk/gems/auth/pkg/*.gem
130
131 # ── Build source gem (fallback for unsupported platforms) ──────────────────
132 build-source-gem:
133 name: Build source gem
134 runs-on: ubuntu-latest
135 steps:
136 - name: Checkout
137 uses: actions/checkout@v6
138 with:
139 ref: ${{ github.event.inputs.tag || github.ref }}
140
141 - name: Set the release version
142 shell: bash
143 run: |
144 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
145 release_version="${GITHUB_REF_NAME#v}"
146 else
147 release_version="${{ github.event.inputs.tag }}"
148 release_version="${release_version#v}"
149 fi
150 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
151
152 - name: Verify gem version matches tag
153 shell: bash
154 run: |
155 GEM_VERSION=$(sed -n "s/.*VERSION = '\(.*\)'/\1/p" sdk/gems/auth/lib/auth/version.rb)
156
157 echo "Gem version : ${GEM_VERSION}"
158 echo "Tag version : ${RELEASE_VERSION}"
159
160 if [[ "${GEM_VERSION}" != "${RELEASE_VERSION}" ]]; then
161 echo "::error::Version mismatch — bump Auth::VERSION in sdk/gems/auth/lib/auth/version.rb before releasing."
162 exit 1
163 fi
164
165 - name: Setup Ruby
166 uses: ruby/setup-ruby@v1
167 with:
168 ruby-version: "3.4.2"
169 bundler-cache: true
170 working-directory: sdk/gems/auth
171
172 - name: Build source gem
173 working-directory: sdk/gems/auth
174 run: bundle exec rake build
175
176 - name: Upload source gem artifact
177 uses: actions/upload-artifact@v7
178 with:
179 name: gem-source
180 path: sdk/gems/auth/pkg/*.gem
181
182 # ── Push all gems to RubyGems ──────────────────────────────────────────────
183 push-gems:
184 name: Push to RubyGems
185 needs: [build-gems, build-source-gem]
186 runs-on: ubuntu-latest
187
188 steps:
189 - name: Checkout
190 uses: actions/checkout@v6
191 with:
192 ref: ${{ github.event.inputs.tag || github.ref }}
193
194 - name: Set the release version
195 shell: bash
196 run: |
197 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
198 release_version="${GITHUB_REF_NAME#v}"
199 else
200 release_version="${{ github.event.inputs.tag }}"
201 release_version="${release_version#v}"
202 fi
203 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
204
205 - name: Check whether release already exists on RubyGems
206 id: rubygems-check
207 shell: bash
208 run: |
209 if curl -fsS \
210 "https://rubygems.org/api/v2/rubygems/smbcloud-auth/versions/${RELEASE_VERSION}.json" \
211 >/dev/null 2>&1; then
212 echo "smbcloud-auth ${RELEASE_VERSION} already exists on RubyGems, skipping publish"
213 echo "exists=true" >> "$GITHUB_OUTPUT"
214 else
215 echo "exists=false" >> "$GITHUB_OUTPUT"
216 fi
217
218 - name: Download all gem artifacts
219 if: steps.rubygems-check.outputs.exists != 'true'
220 uses: actions/download-artifact@v7
221 with:
222 pattern: "gem-*"
223 path: gems
224 merge-multiple: true
225
226 - name: Setup Ruby
227 if: steps.rubygems-check.outputs.exists != 'true'
228 uses: ruby/setup-ruby@v1
229 with:
230 ruby-version: "3.4.2"
231
232 - name: Configure RubyGems credentials
233 if: steps.rubygems-check.outputs.exists != 'true'
234 shell: bash
235 run: |
236 mkdir -p "${HOME}/.gem"
237 echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > "${HOME}/.gem/credentials"
238 chmod 0600 "${HOME}/.gem/credentials"
239
240 # Push each .gem file individually. Platform-specific gems that are already
241 # published (e.g. from a re-run) emit a warning and continue rather than
242 # failing the whole job.
243 - name: Push gems to RubyGems
244 if: steps.rubygems-check.outputs.exists != 'true'
245 shell: bash
246 run: |
247 for gem_file in gems/*.gem; do
248 echo "Pushing $(basename "${gem_file}")…"
249 gem push "${gem_file}" \
250 || echo "::warning::$(basename "${gem_file}") may already exist for this version — skipping."
251 done