-
-
Notifications
You must be signed in to change notification settings - Fork 47
496 lines (422 loc) · 15.7 KB
/
Copy pathsdk-publish.yml
File metadata and controls
496 lines (422 loc) · 15.7 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
name: Publish SDKs
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
version_override:
description: "Override SDK version (e.g., 0.1.0-beta.1)"
required: false
permissions:
contents: read
env:
DOTNET_VERSION: "10.0.x"
NODE_VERSION: "24"
PNPM_VERSION: "10"
jobs:
generate-spec:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
sdk_version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: src/Web/pnpm-lock.yaml
- name: Install web dependencies
working-directory: src/Web
run: pnpm install --frozen-lockfile
- name: Build bridge package
working-directory: src/Web/packages/bridge
run: pnpm run build
- name: Restore .NET dependencies
run: dotnet restore
- name: Build API and generate OpenAPI spec
working-directory: src/API/Nocturne.API
run: dotnet build -c Release
- name: Determine SDK version
id: version
run: |
if [[ -n "${{ inputs.version_override }}" ]]; then
echo "version=${{ inputs.version_override }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
else
echo "version=0.0.0-dev.${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
fi
- name: Filter spec to V4 endpoints
run: node sdk/filter-v4-spec.js src/Web/packages/app/src/lib/api/generated/openapi.json sdk/openapi-v4.json
- name: Upload V4 OpenAPI spec
uses: actions/upload-artifact@v4
with:
name: openapi-v4-spec
path: sdk/openapi-v4.json
publish-csharp:
needs: generate-spec
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Generate C# SDK
uses: docker://openapitools/openapi-generator-cli:latest
with:
args: >-
generate
-i sdk/openapi-v4.json
-c sdk/csharp/config.yaml
-o sdk/csharp/out
--additional-properties=packageVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix file permissions
run: sudo chown -R $USER:$USER sdk/csharp/out
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Build and pack
working-directory: sdk/csharp/out
run: |
dotnet build -c Release
dotnet pack -c Release -o ../../../nupkg
- name: NuGet login (trusted publishing)
if: startsWith(github.ref, 'refs/tags/v')
uses: NuGet/login@v1
id: nuget-login
with:
user: rcgy
- name: Publish to NuGet
if: startsWith(github.ref, 'refs/tags/v')
run: dotnet nuget push nupkg/*.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
publish-typescript:
needs: generate-spec
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Generate TypeScript SDK
uses: docker://openapitools/openapi-generator-cli:latest
with:
args: >-
generate
-i sdk/openapi-v4.json
-c sdk/typescript/config.yaml
-o sdk/typescript/out
--additional-properties=npmVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix file permissions
run: sudo chown -R $USER:$USER sdk/typescript/out
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Build
working-directory: sdk/typescript/out
run: |
npm install
npm run build
- name: Publish to npm
if: startsWith(github.ref, 'refs/tags/v')
working-directory: sdk/typescript/out
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-kotlin:
needs: generate-spec
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Generate Kotlin SDK
uses: docker://openapitools/openapi-generator-cli:latest
with:
args: >-
generate
-i sdk/openapi-v4.json
-c sdk/kotlin/config.yaml
-o sdk/kotlin/out
--additional-properties=artifactVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix file permissions
run: |
sudo chown -R $USER:$USER sdk/kotlin/out
chmod +x sdk/kotlin/out/gradlew
- name: Apply publish overlay
run: cat sdk/kotlin/publish.gradle >> sdk/kotlin/out/build.gradle
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build and publish to local
working-directory: sdk/kotlin/out
run: ./gradlew build publishToMavenLocal
env:
SIGNING_KEY: ${{ secrets.MAVEN_SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.MAVEN_SIGNING_PASSWORD }}
- name: Upload to Maven Central
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd ~/.m2/repository
# Generate MD5 and SHA1 checksums required by Maven Central
find org/nightscoutfoundation/nocturne -type f ! -name '*.md5' ! -name '*.sha1' ! -name 'maven-metadata-local.xml' ! -name '_remote.repositories' | while read f; do
md5sum "$f" | awk '{print $1}' > "$f.md5"
sha1sum "$f" | awk '{print $1}' > "$f.sha1"
done
zip -r $GITHUB_WORKSPACE/kotlin-bundle.zip org/nightscoutfoundation/nocturne/ -x '*/maven-metadata-local.xml' '*/_remote.repositories'
cd $GITHUB_WORKSPACE
UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" \
-u "$MAVEN_USERNAME:$MAVEN_PASSWORD" \
-F "bundle=@kotlin-bundle.zip" \
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC")
HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -1)
BODY=$(echo "$UPLOAD_RESPONSE" | head -n -1)
echo "Response: $BODY (HTTP $HTTP_CODE)"
if [ "$HTTP_CODE" -ge 400 ]; then exit 1; fi
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
publish-swift:
needs: generate-spec
runs-on: macos-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Install OpenAPI Generator
run: brew install openapi-generator
- name: Generate Swift SDK
run: |
openapi-generator generate \
-i sdk/openapi-v4.json \
-c sdk/swift/config.yaml \
-o sdk/swift/out \
--ignore-file-override sdk/swift/.openapi-generator-ignore \
--additional-properties=podVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix Swift type inference in generated code
run: |
python3 sdk/swift/fix-generated.py sdk/swift/out/Sources
- name: Build
working-directory: sdk/swift/out
run: swift build
- name: Publish to nocturne-swift repo
if: startsWith(github.ref, 'refs/tags/v')
env:
SDK_DEPLOY_KEY: ${{ secrets.SWIFT_SDK_DEPLOY_KEY }}
SDK_VERSION: ${{ needs.generate-spec.outputs.sdk_version }}
run: |
# Configure SSH for the deploy key
mkdir -p ~/.ssh
echo "$SDK_DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new"
# Clone the target repo
git clone git@github.com:nightscout/nocturne-swift.git /tmp/nocturne-swift
# Replace contents with generated SDK (preserve .git)
find /tmp/nocturne-swift -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
cp -r sdk/swift/out/Package.swift /tmp/nocturne-swift/
cp -r sdk/swift/out/Sources /tmp/nocturne-swift/
cp -r sdk/swift/out/README.md /tmp/nocturne-swift/
# Commit and tag
cd /tmp/nocturne-swift
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git diff --cached --quiet && echo "No changes" || git commit -m "Update SDK to v${SDK_VERSION}"
git tag -f "${SDK_VERSION}"
git push origin main
git push origin "${SDK_VERSION}"
# Cleanup
rm -f ~/.ssh/deploy_key
publish-python:
needs: generate-spec
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Generate Python SDK
uses: docker://openapitools/openapi-generator-cli:latest
with:
args: >-
generate
-i sdk/openapi-v4.json
-c sdk/python/config.yaml
-o sdk/python/out
--additional-properties=packageVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix file permissions
run: sudo chown -R $USER:$USER sdk/python/out
- name: Fix package name
run: sed -i 's/^name = "nocturne_sdk"/name = "nocturne-py"/' sdk/python/out/pyproject.toml
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install and build
working-directory: sdk/python/out
run: |
pip install build
python -m build
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/v')
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: sdk/python/out/dist/
skip-existing: true
publish-java:
needs: generate-spec
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Generate Java SDK
uses: docker://openapitools/openapi-generator-cli:latest
with:
args: >-
generate
-i sdk/openapi-v4.json
-c sdk/java/config.yaml
-o sdk/java/out
--additional-properties=artifactVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix file permissions
run: |
sudo chown -R $USER:$USER sdk/java/out
chmod +x sdk/java/out/gradlew
- name: Apply publish overlay
run: |
cat sdk/java/publish.gradle >> sdk/java/out/build.gradle
# Remove API files with multipart upload bugs (OpenAPI Generator native library issue)
rm -f sdk/java/out/src/main/java/org/nightscoutfoundation/nocturne/api/AlertCustomSoundsApi.java
rm -f sdk/java/out/src/test/java/org/nightscoutfoundation/nocturne/api/AlertCustomSoundsApiTest.java
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build and publish to local
working-directory: sdk/java/out
run: ./gradlew build publishToMavenLocal
env:
SIGNING_KEY: ${{ secrets.MAVEN_SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.MAVEN_SIGNING_PASSWORD }}
- name: Upload to Maven Central
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd ~/.m2/repository
# Generate MD5 and SHA1 checksums required by Maven Central
find org/nightscoutfoundation/nocturne-java -type f ! -name '*.md5' ! -name '*.sha1' ! -name 'maven-metadata-local.xml' ! -name '_remote.repositories' | while read f; do
md5sum "$f" | awk '{print $1}' > "$f.md5"
sha1sum "$f" | awk '{print $1}' > "$f.sha1"
done
zip -r $GITHUB_WORKSPACE/java-bundle.zip org/nightscoutfoundation/nocturne-java/ -x '*/maven-metadata-local.xml' '*/_remote.repositories'
cd $GITHUB_WORKSPACE
UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" \
-u "$MAVEN_USERNAME:$MAVEN_PASSWORD" \
-F "bundle=@java-bundle.zip" \
"https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC")
HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -1)
BODY=$(echo "$UPLOAD_RESPONSE" | head -n -1)
echo "Response: $BODY (HTTP $HTTP_CODE)"
if [ "$HTTP_CODE" -ge 400 ]; then exit 1; fi
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
publish-rust:
needs: generate-spec
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download V4 spec
uses: actions/download-artifact@v4
with:
name: openapi-v4-spec
path: sdk/
- name: Generate Rust SDK
uses: docker://openapitools/openapi-generator-cli:latest
with:
args: >-
generate
-i sdk/openapi-v4.json
-c sdk/rust/config.yaml
-o sdk/rust/out
--additional-properties=packageVersion=${{ needs.generate-spec.outputs.sdk_version }}
- name: Fix file permissions
run: sudo chown -R $USER:$USER sdk/rust/out
- name: Fix crate metadata
run: |
sed -i 's/^license = .*/license = "AGPL-3.0-only"/' sdk/rust/out/Cargo.toml
sed -i 's/^authors = .*/authors = ["Nightscout Foundation"]/' sdk/rust/out/Cargo.toml
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Build
working-directory: sdk/rust/out
run: cargo build --release
- name: Publish to crates.io
if: startsWith(github.ref, 'refs/tags/v')
working-directory: sdk/rust/out
run: cargo publish --allow-dirty --token "$CARGO_REGISTRY_TOKEN"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}