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