From 78d1b30b439903ce0efe9446c050d086990297ec Mon Sep 17 00:00:00 2001 From: Michael Shin Date: Fri, 20 Nov 2026 10:47:37 -0500 Subject: [PATCH 1/3] [CI] Automate Platform API client upgrade PRs --- .../workflows/update_platform_api_client.yml | 114 ++++++++++++++++++ README.md | 48 ++++++++ 2 files changed, 162 insertions(+) create mode 100644 .github/workflows/update_platform_api_client.yml diff --git a/.github/workflows/update_platform_api_client.yml b/.github/workflows/update_platform_api_client.yml new file mode 100644 index 00000000..02a51292 --- /dev/null +++ b/.github/workflows/update_platform_api_client.yml @@ -0,0 +1,114 @@ +name: Update Platform API client + +on: + workflow_dispatch: + inputs: + version: + description: "Published Platform API client version (for example, 4.42.0)" + required: true + type: string + repository_dispatch: + types: [platform-api-client-published] + +permissions: + contents: read + +concurrency: + group: update-platform-api-client + cancel-in-progress: false + +jobs: + update: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.repository.default_branch }} + persist-credentials: false + + - uses: actions/setup-python@v6 + with: + python-version: "3.10" + + - name: Update dependency and compatibility note + id: update + env: + REQUESTED_VERSION: ${{ inputs.version || github.event.client_payload.version }} + run: | + python - <<'PY' + import os + import re + from pathlib import Path + + version = os.environ["REQUESTED_VERSION"].removeprefix("v") + stable_version = r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)" + if not re.fullmatch(stable_version, version): + raise SystemExit("version must be a stable X.Y.Z release, optionally prefixed with v") + + requirements_path = Path("requirements.txt") + requirements = requirements_path.read_text() + pattern = r"^platform-api-python-client==([^\s]+)$" + matches = re.findall(pattern, requirements, flags=re.MULTILINE) + if len(matches) != 1 or not re.fullmatch(stable_version, matches[0]): + raise SystemExit("Expected exactly one stable Platform API client pin") + current = matches[0] + + readme_path = Path("README.md") + readme = readme_path.read_text() + note = f"This client uses Platform API `{current}`." + if readme.count(note) != 1: + raise SystemExit("Expected one README compatibility note matching the current pin") + + # Ignore duplicate or out-of-order publication events; never downgrade main. + changed = tuple(map(int, version.split("."))) > tuple(map(int, current.split("."))) + if changed: + requirements_path.write_text(re.sub( + pattern, f"platform-api-python-client=={version}", requirements, flags=re.MULTILINE + )) + readme_path.write_text(readme.replace(note, f"This client uses Platform API `{version}`.")) + else: + print(f"Skipping {version}: main already uses {current}") + + with open(os.environ["GITHUB_OUTPUT"], "a") as output: + output.write(f"version={version}\nprevious={current}\nchanged={str(changed).lower()}\n") + PY + + - name: Verify the release is installable from PyPI + if: steps.update.outputs.changed == 'true' + env: + CLIENT_VERSION: ${{ steps.update.outputs.version }} + run: >- + python -m pip download --no-deps + --index-url https://pypi.org/simple + --dest "$RUNNER_TEMP/platform-api-client" + "platform-api-python-client==$CLIENT_VERSION" + + - name: Check PR token configuration + if: steps.update.outputs.changed == 'true' + env: + UPDATE_TOKEN: ${{ secrets.SDK_UPDATE_TOKEN }} + run: | + if [ -z "$UPDATE_TOKEN" ]; then + echo "::error::Configure SDK_UPDATE_TOKEN with contents and pull requests write access. See README.md." + exit 1 + fi + + - name: Open or update upgrade PR + if: steps.update.outputs.changed == 'true' + uses: peter-evans/create-pull-request@v8 + with: + token: ${{ secrets.SDK_UPDATE_TOKEN }} + base: ${{ github.event.repository.default_branch }} + branch: automation/platform-api-client-${{ steps.update.outputs.version }} + add-paths: | + requirements.txt + README.md + commit-message: "[SDK] Upgrade Platform API client to ${{ steps.update.outputs.version }}" + title: "[SDK] Upgrade Platform API client to ${{ steps.update.outputs.version }}" + body: | + Upgrade `platform-api-python-client` from `${{ steps.update.outputs.previous }}` to `${{ steps.update.outputs.version }}` and update the README compatibility note. + + The package was found on PyPI for Python 3.10. The existing PR workflows run the SDK/CLI sanity tests, formatting, lint, and type checks. + + Review API compatibility and add any required SDK, CLI, or example changes before merging. This PR does not bump the SDK version or publish a release. diff --git a/README.md b/README.md index 063a4bbf..c00387b7 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,54 @@ To run all the tests, use: pytest ``` +### Automated Platform API client updates + +The `Update Platform API client` workflow opens an upgrade PR in this repository +after a generated API client is published. It updates `requirements.txt` and the +compatibility note above. Existing PR workflows run the SDK/CLI sanity tests, +formatting, lint, and type checks. Merging requires review; SDK version bumps and +releases remain separate. + +Configure the repository Actions secret `SDK_UPDATE_TOKEN` with a bot's fine-grained +personal access token scoped to this repository, with **Contents: Read and write** +and **Pull requests: Read and write**. Using a bot token lets the resulting PR run +CI automatically; PR events created with `GITHUB_TOKEN` require workflow approval +([GitHub token documentation](https://docs.github.com/en/actions/concepts/security/github_token)). + +After the generated client's PyPI publish job succeeds, add this step to its +publishing workflow (use `needs` if it is in a separate job): + +```yaml +- name: Request SDK upgrade + env: + GH_TOKEN: ${{ secrets.SDK_UPDATE_TOKEN }} + # Replace this expression with the publishing workflow's version output. + CLIENT_VERSION: ${{ steps.version.outputs.version }} + run: | + jq -n --arg version "$CLIENT_VERSION" \ + '{event_type: "platform-api-client-published", client_payload: {version: $version}}' \ + | gh api --method POST repos/CentML/centml-python-client/dispatches --input - +``` + +The publishing repository also needs the `SDK_UPDATE_TOKEN` secret. Its token +must have **Contents: Read and write** access to this SDK repository to dispatch +the event; the publisher's default `GITHUB_TOKEN` cannot access another repository. + +For a manual run or a retry after PyPI propagation, use the Actions UI or: + +```bash +gh workflow run update_platform_api_client.yml \ + --repo CentML/centml-python-client -f version=4.42.0 +``` + +The workflow accepts stable `X.Y.Z` versions with an optional `v` prefix. It checks +that PyPI has a distribution compatible with Python 3.10, and skips versions at or +below the pin on the default branch. Repeated requests for the same newer version +update the same PR. Different versions get separate branches so a delayed event +cannot replace a newer pending upgrade. After merging a newer version, close any +older pending upgrade PRs. Reruns regenerate the two managed files; put additional +SDK/CLI changes in other files. + ### Common Issues - **`SSL` certificate on `MacOS`** From 7d37477bfff96449e70ddb8e608f242a09d99b69 Mon Sep 17 00:00:00 2001 From: Michael Shin Date: Fri, 20 Nov 2026 10:54:40 -0500 Subject: [PATCH 2/3] [CI] Preserve upgrade PR commits and isolate release concurrency --- .../workflows/update_platform_api_client.yml | 65 ++++++++++++++----- README.md | 11 ++-- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/.github/workflows/update_platform_api_client.yml b/.github/workflows/update_platform_api_client.yml index 02a51292..ff3ccb50 100644 --- a/.github/workflows/update_platform_api_client.yml +++ b/.github/workflows/update_platform_api_client.yml @@ -14,7 +14,7 @@ permissions: contents: read concurrency: - group: update-platform-api-client + group: update-platform-api-client-${{ inputs.version || github.event.client_payload.version }} cancel-in-progress: false jobs: @@ -94,21 +94,50 @@ jobs: exit 1 fi - - name: Open or update upgrade PR + - name: Open upgrade PR without rewriting existing branches if: steps.update.outputs.changed == 'true' - uses: peter-evans/create-pull-request@v8 - with: - token: ${{ secrets.SDK_UPDATE_TOKEN }} - base: ${{ github.event.repository.default_branch }} - branch: automation/platform-api-client-${{ steps.update.outputs.version }} - add-paths: | - requirements.txt - README.md - commit-message: "[SDK] Upgrade Platform API client to ${{ steps.update.outputs.version }}" - title: "[SDK] Upgrade Platform API client to ${{ steps.update.outputs.version }}" - body: | - Upgrade `platform-api-python-client` from `${{ steps.update.outputs.previous }}` to `${{ steps.update.outputs.version }}` and update the README compatibility note. - - The package was found on PyPI for Python 3.10. The existing PR workflows run the SDK/CLI sanity tests, formatting, lint, and type checks. - - Review API compatibility and add any required SDK, CLI, or example changes before merging. This PR does not bump the SDK version or publish a release. + env: + GH_TOKEN: ${{ secrets.SDK_UPDATE_TOKEN }} + CLIENT_VERSION: ${{ steps.update.outputs.version }} + PREVIOUS_VERSION: ${{ steps.update.outputs.previous }} + BASE_BRANCH: ${{ github.event.repository.default_branch }} + run: | + UPDATE_BRANCH="automation/platform-api-client-$CLIENT_VERSION" + EXISTING_PR=$(gh pr list --repo "$GITHUB_REPOSITORY" \ + --head "$UPDATE_BRANCH" --state all --json url --jq '.[0].url // empty') + if [ -n "$EXISTING_PR" ]; then + echo "Leaving existing PR and its commits unchanged: $EXISTING_PR" + exit 0 + fi + + gh auth setup-git --hostname github.com + if git ls-remote --exit-code --heads origin "refs/heads/$UPDATE_BRANCH"; then + # A previous run may have pushed successfully but failed to open the PR. + echo "Using existing branch without changing its commits: $UPDATE_BRANCH" + else + STATUS=$? + if [ "$STATUS" -ne 2 ]; then + exit "$STATUS" + fi + git switch -c "$UPDATE_BRANCH" + git config user.name 'github-actions[bot]' + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add -- requirements.txt README.md + git commit -m "[SDK] Upgrade Platform API client to $CLIENT_VERSION" + # Never force-push: a concurrently created branch must also be preserved. + git push origin "HEAD:refs/heads/$UPDATE_BRANCH" + fi + + BODY_FILE="$RUNNER_TEMP/platform-api-client-pr.md" + cat > "$BODY_FILE" < Date: Wed, 25 Nov 2026 11:40:03 -0500 Subject: [PATCH 3/3] [CI] Run API client update automation on Python 3.12 --- .github/workflows/update_platform_api_client.yml | 4 ++-- README.md | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/update_platform_api_client.yml b/.github/workflows/update_platform_api_client.yml index ff3ccb50..b340a038 100644 --- a/.github/workflows/update_platform_api_client.yml +++ b/.github/workflows/update_platform_api_client.yml @@ -29,7 +29,7 @@ jobs: - uses: actions/setup-python@v6 with: - python-version: "3.10" + python-version: "3.12" - name: Update dependency and compatibility note id: update @@ -79,7 +79,7 @@ jobs: env: CLIENT_VERSION: ${{ steps.update.outputs.version }} run: >- - python -m pip download --no-deps + python -m pip download --no-deps --python-version 3.10 --index-url https://pypi.org/simple --dest "$RUNNER_TEMP/platform-api-client" "platform-api-python-client==$CLIENT_VERSION" diff --git a/README.md b/README.md index 5d8ab10d..8c6952ec 100644 --- a/README.md +++ b/README.md @@ -173,9 +173,10 @@ gh workflow run update_platform_api_client.yml \ --repo CentML/centml-python-client -f version=4.42.0 ``` -The workflow accepts stable `X.Y.Z` versions with an optional `v` prefix. It checks -that PyPI has a distribution compatible with Python 3.10, and skips versions at or -below the pin on the default branch. Repeated requests for the same newer version +The workflow runs on Python 3.12 and accepts stable `X.Y.Z` versions with an optional +`v` prefix. It explicitly checks that PyPI has a distribution compatible with the +SDK's minimum supported version, Python 3.10. It skips versions at or below the pin +on the default branch. Repeated requests for the same newer version leave its existing PR unchanged, including handwritten SDK/CLI fixes. A closed PR is also left alone; reopen it manually if the upgrade should proceed. If a run pushed the branch but failed to open a PR, retrying opens a PR from that branch