openai/openai-java
Publicmirrored from https://github.com/openai/openai-javaAvailable
.github/workflows/ci.yml
163lines · modecode
| 1 | name: CI |
| 2 | on: |
| 3 | push: |
| 4 | branches: |
| 5 | - '**' |
| 6 | - '!integrated/**' |
| 7 | - '!stl-preview-head/**' |
| 8 | - '!stl-preview-base/**' |
| 9 | - '!generated' |
| 10 | - '!codegen/**' |
| 11 | - 'codegen/stl/**' |
| 12 | pull_request: |
| 13 | branches-ignore: |
| 14 | - 'stl-preview-head/**' |
| 15 | - 'stl-preview-base/**' |
| 16 | |
| 17 | jobs: |
| 18 | lint: |
| 19 | timeout-minutes: 15 |
| 20 | name: lint |
| 21 | runs-on: ${{ github.repository == 'stainless-sdks/openai-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} |
| 22 | if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') |
| 23 | |
| 24 | steps: |
| 25 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 26 | |
| 27 | - name: Set up Java |
| 28 | uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 |
| 29 | with: |
| 30 | distribution: temurin |
| 31 | java-version: | |
| 32 | 8 |
| 33 | 21 |
| 34 | cache: gradle |
| 35 | |
| 36 | - name: Set up Gradle |
| 37 | uses: gradle/actions/setup-gradle@0b6dd653ba04f4f93bf581ec31e66cbd7dcb644d # v4 |
| 38 | |
| 39 | - name: Run lints |
| 40 | run: ./scripts/lint |
| 41 | |
| 42 | build: |
| 43 | timeout-minutes: 30 |
| 44 | name: build |
| 45 | permissions: |
| 46 | contents: read |
| 47 | id-token: write |
| 48 | runs-on: ${{ github.repository == 'stainless-sdks/openai-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} |
| 49 | if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') |
| 50 | |
| 51 | steps: |
| 52 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 53 | |
| 54 | - name: Set up Java |
| 55 | uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 |
| 56 | with: |
| 57 | distribution: temurin |
| 58 | java-version: | |
| 59 | 8 |
| 60 | 21 |
| 61 | cache: gradle |
| 62 | |
| 63 | - name: Set up Gradle |
| 64 | uses: gradle/actions/setup-gradle@0b6dd653ba04f4f93bf581ec31e66cbd7dcb644d # v4 |
| 65 | |
| 66 | - name: Build SDK |
| 67 | # disable gradle daemon in CI because it is flakey |
| 68 | env: |
| 69 | GRADLE_OPTS: "-Dkotlin.compiler.execution.strategy=in-process" |
| 70 | run: ./scripts/build |
| 71 | |
| 72 | - name: Build and upload Maven artifacts |
| 73 | if: |- |
| 74 | github.repository == 'stainless-sdks/openai-java' && |
| 75 | !startsWith(github.ref, 'refs/heads/stl/') |
| 76 | env: |
| 77 | URL: https://pkg.stainless.com/s |
| 78 | SHA: ${{ github.sha }} |
| 79 | PROJECT: openai-java |
| 80 | run: | |
| 81 | set -euo pipefail |
| 82 | |
| 83 | max_retries=5 |
| 84 | attempt=1 |
| 85 | |
| 86 | while true; do |
| 87 | echo "Maven artifact upload attempt ${attempt}/${max_retries}" |
| 88 | |
| 89 | oidc_response="$(curl -sSf \ |
| 90 | -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \ |
| 91 | "${ACTIONS_ID_TOKEN_REQUEST_URL}")" |
| 92 | github_token="$(printf '%s' "$oidc_response" | jq -er '.value')" |
| 93 | |
| 94 | upload_log="$(mktemp)" |
| 95 | set +e |
| 96 | AUTH="$github_token" ./scripts/upload-artifacts 2>&1 | tee "$upload_log" |
| 97 | upload_status=${PIPESTATUS[0]} |
| 98 | set -e |
| 99 | |
| 100 | if [ "$upload_status" -eq 0 ]; then |
| 101 | break |
| 102 | fi |
| 103 | |
| 104 | if [ "$attempt" -lt "$max_retries" ] && \ |
| 105 | grep -q "Failed to get valid signed URL" "$upload_log" && \ |
| 106 | grep -q "GitHub JWT is missing or invalid\\." "$upload_log"; then |
| 107 | sleep_seconds=$((3 * (1 << (attempt - 1)))) |
| 108 | echo "Retrying after fresh OIDC token due to transient GitHub JWT validation failure" |
| 109 | echo "Sleeping ${sleep_seconds}s before retry" |
| 110 | sleep "$sleep_seconds" |
| 111 | attempt=$((attempt + 1)) |
| 112 | continue |
| 113 | fi |
| 114 | |
| 115 | exit "$upload_status" |
| 116 | done |
| 117 | test: |
| 118 | timeout-minutes: 30 |
| 119 | name: test |
| 120 | runs-on: ${{ github.repository == 'stainless-sdks/openai-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} |
| 121 | if: github.event_name == 'push' || github.event.pull_request.head.repo.fork |
| 122 | steps: |
| 123 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 124 | |
| 125 | - name: Set up Java |
| 126 | uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 |
| 127 | with: |
| 128 | distribution: temurin |
| 129 | java-version: | |
| 130 | 8 |
| 131 | 21 |
| 132 | cache: gradle |
| 133 | |
| 134 | - name: Set up Gradle |
| 135 | uses: gradle/gradle-build-action@fe583dc97e032f41ccc310ea5176f2d7306abbc4 # v2 |
| 136 | |
| 137 | - name: Run tests |
| 138 | run: ./scripts/test |
| 139 | examples: |
| 140 | timeout-minutes: 20 |
| 141 | name: examples |
| 142 | environment: CI |
| 143 | runs-on: ${{ github.repository == 'stainless-sdks/openai-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} |
| 144 | if: github.repository == 'openai/openai-java' && (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata') |
| 145 | |
| 146 | steps: |
| 147 | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 148 | |
| 149 | - name: Set up Java |
| 150 | uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5 |
| 151 | with: |
| 152 | distribution: temurin |
| 153 | java-version: | |
| 154 | 8 |
| 155 | 21 |
| 156 | cache: gradle |
| 157 | - name: Set up Gradle |
| 158 | uses: gradle/gradle-build-action@fe583dc97e032f41ccc310ea5176f2d7306abbc4 # v2 |
| 159 | |
| 160 | - env: |
| 161 | OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 162 | run: | |
| 163 | ./gradlew :openai-java-example:run |
| 164 | |