Skip to content

ci: publish stackone-ai using PyPI trusted publishing - #244

Open
glebedel wants to merge 5 commits into
mainfrom
ci/pypi-trusted-publishing
Open

glebedel wants to merge 5 commits into
mainfrom
ci/pypi-trusted-publishing

Conversation

@glebedel

@glebedel glebedel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Publishing currently relies on a stored PyPI API token. This change keeps the existing Release Please flow and uploads tested artifacts using GitHub OIDC through PyPI Trusted Publishing.

The build job checks out the exact release commit, verifies it belongs to main and its package version matches the release, runs the existing test suite, and installs both the wheel and source archive in isolated environments. The separate publish job has no source checkout, downloads only its own run's artifacts, and is the only job with id-token: write. Workflow PRs exercise the build without publishing.

Required setup before merging

The current PyPI account cannot manage stackone-ai (403). A project owner must add the publisher below before this PR is merged.

PyPI publisher field Value
PyPI project stackone-ai
Owner StackOneHQ
Repository stackone-ai-python
Workflow filename release.yaml
Environment pypi

The GitHub pypi environment has already been configured and verified to allow only the main branch, with no tag rules. No new secret is needed. Keep the existing token until the first successful trusted publish; then remove the unused secret and revoke the token only after checking other uses. Full release instructions are in .github/RELEASING.md.

Validation and review

  • Local tests: 871 passed. Ruff, ty, and the required make format / make test checks passed.
  • Built and installed the wheel and source archive successfully; package imports and installed versions verified.
  • Actionlint and diff checks passed. Ten executable source/version/isolation guard probes passed for this repository, including missing or wrong release metadata and a tag attempting to shadow origin/main.
  • Security, correctness, and maintainability reviews completed. No unresolved findings in this change. Aikido critical/high issues were checked for the changed scope.

GitHub CI passed, including the new release build, package installation checks, and the Python test matrix. The publish job was skipped as expected on this PR. The Aikido PR check was skipped on the draft; its existing critical/high alerts were inspected separately for this diff. An actual OIDC upload is intentionally deferred until the next release; no package version or application dependencies change here.

@glebedel
glebedel marked this pull request as ready for review November 11, 2026 10:58

@glebedel glebedel left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed at 47ab071. No blocking issues in the workflow. The one thing that must happen before merge is the PyPI side: a stackone-ai owner has to add the trusted publisher in the table above. The GitHub side cannot confirm it, and a release merged without it fails at the upload step.

Checked

Check Result
actionlint on release.yaml clean
Action pins upload-artifact v7.0.2 and download-artifact v8.0.2 SHAs match their tags
release-please outputs single root package ., so the unprefixed sha and version outputs the build job reads exist
pypi environment deployment allowed from main only, no tag rules
PR build run wheel and sdist both built, installed in isolation and reported 3.0.0
Drift 6 commits behind main, none touch .github/ or CLAUDE.md
Security pass (Codex, security only) no findings. Only publish gets id-token: write, its implicit success() keeps it behind build, PR runs (fork or same repo) cannot reach the main-only environment, the source check uses the full refs/remotes/origin/main ref, caches are off and release metadata reaches the shell through env
CI after marking ready all checks pass, Aikido included; publish and release-please skipped as expected

Non-blocking suggestions

  1. .github/RELEASING.md mixes the evergreen release process with one-time migration steps ("Do not merge this migration until...", "Keep the existing token until the first successful publish"). After merge those lines go stale. They could live in this PR body only, or move to a short "Migrating from the API token" section that is deleted after the first trusted publish.
  2. uv publish uploads without PEP 740 attestations. pypa/gh-action-pypi-publish generates them by default under trusted publishing. Optional, and fine as a follow-up.
  3. The pypi environment has no required reviewer, so merging a release PR publishes straight away. That matches main today, so this PR does not weaken anything. If you want a human gate on PyPI uploads, it is one setting on the environment.

After the first trusted publish succeeds, remove the PYPI_API_TOKEN secret and revoke the token, as the PR body says.

Requested by guillaume@stackone.com in Slack (repo audit thread).

🤖 Generated with Claude Code

s2d2-s1 and others added 3 commits November 11, 2026 11:44
release.yaml conflicted where main bumped action pins (#253). Kept this
branch's build and publish jobs and moved every setup-uv to v10.3.3 and
pnpm/action-setup to v6.1.1, including the steps this branch adds, so the
file matches main's pins. No workflow logic changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Migrates release publishing from a stored PyPI token to OIDC Trusted Publishing, adds a build/verify gate and docs; requires human review of the credential-handling change and external PyPI publisher setup.

View guided diff | Turn on auto-fix | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Migrates PyPI publishing from a stored token to OIDC Trusted Publishing with a build/verify gate and docs, and also fixes a concurrent end-user lookup race; requires human review of the credential-handling change and external PyPI publisher setup.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread stackone_ai/toolset.py
Comment on lines +1026 to 1035
def _join_accounts_listing(self, missing_end_user_for: str | None = None) -> None:
with self._cache_lock:
fetching = self._fetching_accounts
sequence = 0
if fetching is None:
if missing_end_user_for is not None and missing_end_user_for in self._end_user_ids:
return
self._accounts_sequence += 1
sequence = self._accounts_sequence
fetching = self._fetching_accounts = concurrent.futures.Future()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium - Concurrent end-user lookup can reuse a stale mapping indefinitely

When an MCP request snapshots an account as missing its end-user id, a concurrent /accounts request can populate that account with an id before the MCP refusal is handled. If that mapping is stale because the account was relinked or the response lagged the server, the new early return skips the refresh and retries once with the stale id; the request is rejected again and subsequent calls continue using the stale mapping until the caller manually refreshes accounts.

Show fix
Suggested change
def _join_accounts_listing(self, missing_end_user_for: str | None = None) -> None:
with self._cache_lock:
fetching = self._fetching_accounts
sequence = 0
if fetching is None:
if missing_end_user_for is not None and missing_end_user_for in self._end_user_ids:
return
self._accounts_sequence += 1
sequence = self._accounts_sequence
fetching = self._fetching_accounts = concurrent.futures.Future()
def _join_accounts_listing(self, missing_end_user_for: str | None = None) -> None:
with self._cache_lock:
fetching = self._fetching_accounts
sequence = 0
if fetching is None:
self._accounts_sequence += 1
sequence = self._accounts_sequence
fetching = self._fetching_accounts = concurrent.futures.Future()

More info - Reply on this comment to give feedback or ignore the issue.

This branch has not been deployed

No deployments
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