|
| 1 | +name: Install ogx-client |
| 2 | +description: Install ogx-client based on branch context and client-version input |
| 3 | + |
| 4 | +inputs: |
| 5 | + client-version: |
| 6 | + description: 'Client version to install on non-release branches (latest or published). Ignored on release branches.' |
| 7 | + required: false |
| 8 | + default: "" |
| 9 | + sdk_install_url: |
| 10 | + description: 'URL to install Python SDK from (for testing preview builds). If provided, overrides client-version.' |
| 11 | + required: false |
| 12 | + default: "" |
| 13 | + branch: |
| 14 | + description: 'Explicit branch override (used by scheduled CI to pass the matrix branch)' |
| 15 | + required: false |
| 16 | + default: "" |
| 17 | + |
| 18 | +outputs: |
| 19 | + install-after-sync: |
| 20 | + description: 'Whether to install client after uv sync' |
| 21 | + value: ${{ steps.configure.outputs.install-after-sync }} |
| 22 | + install-source: |
| 23 | + description: 'Where to install client from after sync' |
| 24 | + value: ${{ steps.configure.outputs.install-source }} |
| 25 | + |
| 26 | +runs: |
| 27 | + using: "composite" |
| 28 | + steps: |
| 29 | + - name: Configure client installation |
| 30 | + id: configure |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + # If sdk_install_url is provided, use it directly |
| 34 | + if [ -n "${{ inputs.sdk_install_url }}" ]; then |
| 35 | + echo "Using provided sdk_install_url: ${{ inputs.sdk_install_url }}" |
| 36 | + echo "generate=false" >> $GITHUB_OUTPUT |
| 37 | + echo "install-after-sync=true" >> $GITHUB_OUTPUT |
| 38 | + echo "install-source=${{ inputs.sdk_install_url }}" >> $GITHUB_OUTPUT |
| 39 | + exit 0 |
| 40 | + fi |
| 41 | +
|
| 42 | + # Determine the branch we're working with |
| 43 | + # Use explicit branch input if provided (for scheduled CI), otherwise detect from GitHub context |
| 44 | + if [ -n "${{ inputs.branch }}" ]; then |
| 45 | + BRANCH="${{ inputs.branch }}" |
| 46 | + else |
| 47 | + BRANCH="${{ github.base_ref || github.ref }}" |
| 48 | + BRANCH="${BRANCH#refs/heads/}" |
| 49 | + fi |
| 50 | + # Trim leading/trailing whitespace (git branch -r output includes padding) |
| 51 | + BRANCH="$(echo "$BRANCH" | xargs)" |
| 52 | +
|
| 53 | + echo "Working with branch: $BRANCH" |
| 54 | +
|
| 55 | + # The ogx-client Python SDK is generated in-repo from client-sdks/openapi. |
| 56 | + # On release branches and when client-version=latest, generate the SDK from |
| 57 | + # the current checkout so tests run against the client built from this source. |
| 58 | + # When client-version=published, use the version resolved by uv sync from PyPI. |
| 59 | + if [[ "$BRANCH" =~ ^release-[0-9]+\.[0-9]+\.x$ ]]; then |
| 60 | + echo "Detected release branch: $BRANCH — generating client from checkout" |
| 61 | + echo "generate=true" >> $GITHUB_OUTPUT |
| 62 | + echo "install-after-sync=true" >> $GITHUB_OUTPUT |
| 63 | + echo "install-source=${{ github.workspace }}/client-sdks/openapi/sdks/python" >> $GITHUB_OUTPUT |
| 64 | + elif [ "${{ inputs.client-version }}" = "latest" ]; then |
| 65 | + echo "Generating client from checkout (client-version=latest)" |
| 66 | + echo "generate=true" >> $GITHUB_OUTPUT |
| 67 | + echo "install-after-sync=true" >> $GITHUB_OUTPUT |
| 68 | + echo "install-source=${{ github.workspace }}/client-sdks/openapi/sdks/python" >> $GITHUB_OUTPUT |
| 69 | + elif [ "${{ inputs.client-version }}" = "published" ]; then |
| 70 | + # Use published version from PyPI (installed by sync) |
| 71 | + echo "generate=false" >> $GITHUB_OUTPUT |
| 72 | + echo "install-after-sync=false" >> $GITHUB_OUTPUT |
| 73 | + elif [ -n "${{ inputs.client-version }}" ]; then |
| 74 | + echo "::error::Invalid client-version: ${{ inputs.client-version }}" |
| 75 | + exit 1 |
| 76 | + else |
| 77 | + echo "generate=false" >> $GITHUB_OUTPUT |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Set up Java (SDK generation) |
| 81 | + if: steps.configure.outputs.generate == 'true' |
| 82 | + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 |
| 83 | + with: |
| 84 | + distribution: 'temurin' |
| 85 | + java-version: '11' |
| 86 | + |
| 87 | + - name: Set up Node.js (SDK generation) |
| 88 | + if: steps.configure.outputs.generate == 'true' |
| 89 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 90 | + with: |
| 91 | + node-version: '20' |
| 92 | + |
| 93 | + - name: Install openapi-generator-cli (SDK generation) |
| 94 | + if: steps.configure.outputs.generate == 'true' |
| 95 | + shell: bash |
| 96 | + run: npm install -g @openapitools/openapi-generator-cli |
| 97 | + |
| 98 | + - name: Generate ogx-client SDK |
| 99 | + if: steps.configure.outputs.generate == 'true' |
| 100 | + shell: bash |
| 101 | + working-directory: client-sdks/openapi |
| 102 | + run: | |
| 103 | + echo "Generating ogx-client SDK (OPEN=0) from checkout..." |
| 104 | + make sdk OPEN=0 |
| 105 | +
|
| 106 | + PY_FILE_COUNT=$(find sdks/python -name "*.py" | wc -l) |
| 107 | + echo "Generated Python files: $PY_FILE_COUNT" |
| 108 | + if [ "$PY_FILE_COUNT" -le 10 ]; then |
| 109 | + echo "::error::Too few Python files generated (expected > 10, got $PY_FILE_COUNT)" |
| 110 | + exit 1 |
| 111 | + fi |
0 commit comments