Skip to content

Add GitHub Actions CI and PyPI release workflows for tpu-info - #13

Merged
MrGeislinger merged 1 commit into
AI-Hypercomputer:mainfrom
chiajunglien:emma/tpu-info-cicd
Nov 3, 2026
Merged

MrGeislinger merged 1 commit into
AI-Hypercomputer:mainfrom
chiajunglien:emma/tpu-info-cicd

Conversation

@chiajunglien

@chiajunglien chiajunglien commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR adds CI and automated PyPI release workflows for tpu-info under .github/workflows/.

1. CI (.github/workflows/ci.yml)

  • Triggers: pull requests and pushes to main that touch tpu_info/** or ci.yml, plus manual workflow_dispatch.
  • Python versions: 3.10, 3.11, and 3.12.
  • Steps:
    • Compile the protobuf definitions with grpcio-tools>=1.65.5,<1.72.0, the same cap as the [build-system] requirement in tpu_info/pyproject.toml.
    • Check Python syntax (py_compile).
    • Run all tpu_info/*_test.py unit tests with both python <file>_test.py (absltest) and pytest. CI fails if no test files are found, so tests can't be skipped silently.
    • Build the wheel and sdist (python -m build) and validate the metadata (twine check).
    • Install the built wheel and run tpu-info --help, --version, and query --list-metrics from outside the source tree. Locally generated proto files are removed first, so the wheel must bundle them.
    • Install the wheel in a fresh virtualenv with the Cloud TPU JAX runtime versions (grpcio==1.75.0, protobuf==6.32.1), and check that the proto modules import and the CLI runs.

2. Release (.github/workflows/release.yml)

  • Triggers: tpu-info-v* tags (e.g. tpu-info-v0.14.3), plus manual workflow_dispatch for TestPyPI dry runs.
  • Checks that the tag matches project.version in tpu_info/pyproject.toml (e.g. tag tpu-info-v0.14.3 requires version 0.14.3).
  • Before publishing (on Python 3.11): runs the unit tests with both runners, builds and checks the wheel and sdist, and runs the wheel install and Cloud TPU runtime checks. Fails if no test files are found.
  • Publishes with PyPI Trusted Publishing (OIDC) via pypa/gh-action-pypi-publish v1.14.3, pinned to a commit SHA. No API tokens or secrets are stored in GitHub.
    • Tag push: TestPyPI first, then production PyPI.
    • Manual run from a branch: TestPyPI only.

Security

  • All actions are pinned to full commit SHAs.
  • actions/checkout uses persist-credentials: false.
  • The release workflow doesn't use a pip cache, to avoid cache poisoning.
  • The GitHub Actions Scan (zizmor) passes.

Setup needed before the first release

A project owner needs to add a trusted publisher on both PyPI and TestPyPI:

  • Owner: AI-Hypercomputer
  • Repository: cloud-accelerator-diagnostics
  • Workflow: release.yml
  • Environment: pypi (PyPI) / testpypi (TestPyPI)

Note

CI is expected to fail until the unit tests are exported to main via Copybara. After that, this PR will be rebased so CI runs all 522 tests.

@gemini-code-assist

Copy link
Copy Markdown

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@chiajunglien
chiajunglien marked this pull request as ready for review October 20, 2026 02:38
@chiajunglien
chiajunglien force-pushed the emma/tpu-info-cicd branch 2 times, most recently from 6064aef to da63e87 Compare October 21, 2026 09:31
Comment thread .github/workflows/release.yml Outdated
on:
push:
tags:
- "v*"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this bare v*

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Only tpu-info-v* triggers the release now.

Comment thread .github/workflows/release.yml Outdated
if: startsWith(github.ref, 'refs/tags/')
run: |
RAW_TAG="${GITHUB_REF#refs/tags/}"
# Strip either 'tpu-info-v' or 'v' prefix

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With tags standardized on tpu-info-v*, we can strip tpu-info-v directly here:

Suggested change
# Strip either 'tpu-info-v' or 'v' prefix
# Strip 'tpu-info-v' prefix
TAG_VERSION="${RAW_TAG#tpu-info-v}"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, applied this and removed the two old TAG_VERSION lines.

Comment thread .github/workflows/release.yml Outdated
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use PyPI Trusted Publishing (OIDC) instead of API tokens. Since permissions: id-token: write and environment: testpypi are already configured above, please remove the password: line so gh-action-pypi-publish uses OIDC directly (keeping skip-existing: true here is great for repeated workflow_dispatch dry runs!)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed password: and kept skip-existing: true.

Comment thread .github/workflows/release.yml Outdated
Comment on lines +155 to +156
with:
password: ${{ secrets.PYPI_API_TOKEN }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here — let's remove with: password: so production PyPI publishing uses OIDC Trusted Publishing exclusively via the pypi environment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed with: password:.

Comment thread .github/workflows/ci.yml Outdated
Comment on lines +67 to +88
# TODO: Remove the skip once the *_test.py files are exported from google3
# (cl/999946781), so missing tests fail CI instead of passing silently.
- name: Run unit tests (absltest runner)
run: |
shopt -s nullglob
tests=(tpu_info/*_test.py)
if [ ${#tests[@]} -eq 0 ]; then
echo "::warning::No tpu_info/*_test.py files found; skipping unit tests."
exit 0
fi
for test_file in "${tests[@]}"; do
echo "=== Running ${test_file} ==="
python "${test_file}"
done

- name: Run unit tests (pytest runner)
run: |
shopt -s nullglob
tests=(tpu_info/*_test.py)
if [ ${#tests[@]} -eq 0 ]; then
echo "::warning::No tpu_info/*_test.py files found; skipping unit tests."
exit 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the unit tests are exported to main, please rebase this PR, remove the internal cl/ comment, and change the empty-test check in both test steps from ::warning:: / exit 0 to ::error:: / exit 1 (matching release.yml line 70) so CI runs all 522 tests on this PR and can never silently skip tests in the future.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: removed the internal comment and switched both checks to ::error:: / exit 1.

@chiajunglien
chiajunglien force-pushed the emma/tpu-info-cicd branch 3 times, most recently from 79408f6 to 9d1e3e8 Compare November 3, 2026 02:19
@MrGeislinger
MrGeislinger merged commit ad8f5a7 into AI-Hypercomputer:main Nov 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants