forked from openai/openai-java
-
Notifications
You must be signed in to change notification settings - Fork 0
361 lines (306 loc) · 12.2 KB
/
Copy pathci.yml
File metadata and controls
361 lines (306 loc) · 12.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
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
name: CI
on:
push:
branches:
- main
- next
# GitHub's cache service confines this event's writes to refs/pull/<number>/merge,
# even when an untrusted PR changes this workflow or its cache policy tests.
pull_request:
branches:
- main
- next
merge_group:
types:
- checks_requested
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
lint:
name: CI / lint
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Set up Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: |
8
21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
cache-read-only: ${{ github.ref_name != github.event.repository.default_branch }}
- name: Verify Maven Central credential transport
run: |
set -euo pipefail
workflow=.github/workflows/create-releases.yml
for mapping in \
mavenCentralUsername:OPENAI_SONATYPE_USERNAME \
mavenCentralPassword:OPENAI_SONATYPE_PASSWORD; do
property="ORG_GRADLE_PROJECT_${mapping%%:*}"
secret="${mapping#*:}"
if ! awk -v property="$property" -v secret="$secret" '
$1 == property ":" {
if ($2 == ("$" "{{") && $3 == "secrets." secret && $4 == "}}" && NF == 4) {
valid++
} else {
invalid = 1
}
}
END { exit !(valid == 1 && !invalid) }
' "$workflow"; then
echo "::error::Invalid or missing protected Maven mapping: $property"
exit 1
fi
done
if grep -Eq '(^|[[:space:]])-PmavenCentral(Username|Password)(=|[[:space:]]|$)' "$workflow"; then
echo '::error::Maven Central credentials must not appear in Gradle arguments.'
exit 1
fi
- name: Run lints
run: ./scripts/lint
build:
name: CI / build + Jackson compatibility
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 30
outputs:
gradle-cache-artifact-id: ${{ steps.gradle-cache-artifact.outputs.artifact-id }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Set up Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: |
8
21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
cache-read-only: ${{ github.ref_name != github.event.repository.default_branch }}
- name: Build SDK and run compatibility tests
env:
GRADLE_OPTS: -Dkotlin.compiler.execution.strategy=in-process
run: ./scripts/build
- name: Collect exact-run Gradle build cache
env:
CACHE_ARTIFACT_PATH: ${{ runner.temp }}/ci-gradle-build-cache
GRADLE_OPTS: -Dkotlin.compiler.execution.strategy=in-process
run: ./scripts/collect-gradle-build-cache "$CACHE_ARTIFACT_PATH"
# Cross-run caches are read-only on pull requests and merge groups. Publish this run's local
# build cache as an immutable artifact for downstream jobs with the same trust boundary.
- name: Upload exact-run Gradle build cache
id: gradle-cache-artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ci-gradle-build-cache-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/ci-gradle-build-cache
if-no-files-found: error
retention-days: 1
compression-level: 0
test:
name: CI / tests
needs: build
if: needs.build.result == 'success'
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Set up Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: |
8
21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
cache-read-only: true
- name: Restore exact-run Gradle build cache
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.build.outputs.gradle-cache-artifact-id }}
merge-multiple: true
digest-mismatch: error
path: ~/.gradle/caches/build-cache-1
- name: Check concurrent Steady publication
run: node scripts/steady/publication.test.cjs
- name: Run tests
run: ./scripts/test
api_compatibility:
name: CI / API compatibility
needs: build
if: >-
needs.build.result == 'success' &&
(github.event_name == 'pull_request' || github.event_name == 'merge_group')
permissions:
contents: read
pull-requests: read
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: |
8
21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
cache-read-only: true
- name: Restore exact-run Gradle build cache
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.build.outputs.gradle-cache-artifact-id }}
merge-multiple: true
digest-mismatch: error
path: ~/.gradle/caches/build-cache-1
- name: Compile previous tests against the proposed SDK
env:
BASE_COMMIT: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
GRADLE_OPTS: -Dkotlin.compiler.execution.strategy=in-process
run: |
set -euo pipefail
BASE_DETECTOR="$(mktemp ./scripts/detect-breaking-changes.baseline.XXXXXX)"
trap 'rm -f "$BASE_DETECTOR"' EXIT
git show "${BASE_COMMIT}:scripts/detect-breaking-changes" > "$BASE_DETECTOR"
chmod +x "$BASE_DETECTOR"
# Always enforce the trusted baseline policy so a PR cannot weaken the detector to hide
# an SDK break. The proposed detector is identical on most PRs, so only run its duplicate
# compilation when the PR actually changes the detector.
"$BASE_DETECTOR" "$BASE_COMMIT"
if git diff --quiet "$BASE_COMMIT" -- scripts/detect-breaking-changes; then
echo "API compatibility detector is unchanged; skipping duplicate validation."
else
echo "API compatibility detector changed; validating the proposed detector."
./scripts/detect-breaking-changes "$BASE_COMMIT"
fi
version_support_matrix:
name: CI / version support matrix
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 5
outputs:
runtime-matrix: ${{ steps.matrix.outputs.runtime-matrix }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Set up Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: 21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
cache-read-only: ${{ github.ref_name != github.event.repository.default_branch }}
- name: Read version support policy
id: matrix
run: |
./scripts/gradle generateVersionSupportMatrix -PversionSupportMatrix=pull-request
echo "runtime-matrix=$(< build/version-support-matrix.json)" >> "$GITHUB_OUTPUT"
runtime_compatibility:
name: CI / runtime compatibility / Java ${{ matrix.java }}
needs:
- build
- version_support_matrix
if: >-
always() &&
needs.version_support_matrix.result == 'success' &&
needs.build.result == 'success'
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
java: ${{ fromJSON(needs.version_support_matrix.outputs.runtime-matrix) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Set up consumer Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Set up build Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: 21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
cache-read-only: true
- name: Restore exact-run Gradle build cache
if: needs.build.result == 'success'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
artifact-ids: ${{ needs.build.outputs.gradle-cache-artifact-id }}
merge-multiple: true
digest-mismatch: error
path: ~/.gradle/caches/build-cache-1
- name: Run consumer compatibility smoke test
env:
RUNTIME_JAVA_VERSION: ${{ matrix.java }}
run: >-
./scripts/gradle
:openai-java-runtime-compatibility:runRuntimeCompatibility
-PruntimeJavaVersion="$RUNTIME_JAVA_VERSION"
required:
name: CI / required
if: always()
needs:
- lint
- build
- test
- api_compatibility
- runtime_compatibility
runs-on: ${{ vars.SDK_GHA_RUNNER || 'ubuntu-24.04' }}
timeout-minutes: 5
steps:
- name: Verify required jobs succeeded
env:
EVENT_NAME: ${{ github.event_name }}
LINT_RESULT: ${{ needs.lint.result }}
BUILD_RESULT: ${{ needs.build.result }}
TEST_RESULT: ${{ needs.test.result }}
API_COMPATIBILITY_RESULT: ${{ needs.api_compatibility.result }}
RUNTIME_COMPATIBILITY_RESULT: ${{ needs.runtime_compatibility.result }}
run: |
set -euo pipefail
failed_jobs=()
[[ "$LINT_RESULT" == "success" ]] || failed_jobs+=("lint: $LINT_RESULT")
[[ "$BUILD_RESULT" == "success" ]] || failed_jobs+=("build: $BUILD_RESULT")
[[ "$TEST_RESULT" == "success" ]] || failed_jobs+=("test: $TEST_RESULT")
if [[ ( "$EVENT_NAME" == "pull_request" || "$EVENT_NAME" == "merge_group" ) &&
"$API_COMPATIBILITY_RESULT" != "success" ]]; then
failed_jobs+=("API compatibility: $API_COMPATIBILITY_RESULT")
fi
[[ "$RUNTIME_COMPATIBILITY_RESULT" == "success" ]] ||
failed_jobs+=("runtime compatibility: $RUNTIME_COMPATIBILITY_RESULT")
if (( ${#failed_jobs[@]} > 0 )); then
printf 'Required CI job did not succeed: %s\n' "${failed_jobs[@]}"
exit 1
fi
echo "All required CI jobs succeeded."