Skip to content

ci: add tag-triggered release workflow with PyPI Trusted Publishing#329

Open
cxhello wants to merge 1 commit into
nacos-group:masterfrom
cxhello:ci/release-workflow
Open

ci: add tag-triggered release workflow with PyPI Trusted Publishing#329
cxhello wants to merge 1 commit into
nacos-group:masterfrom
cxhello:ci/release-workflow

Conversation

@cxhello

@cxhello cxhello commented Jul 4, 2026

Copy link
Copy Markdown
Member

What type of PR is this?

  • Bug fix
  • New feature
  • Enhancement
  • Refactoring
  • Documentation
  • CI/CD
  • Other

What does this PR do?

当前发布流程全手动(本地 setup.py upload 上传 PyPI + 手动推 tag + 网页创建 Release),漏掉任何一步都不会有提示——例如 3.2.0 已发布到 PyPI、tag 已推送,但 GitHub Release 一直缺失(见 #328)。

本 PR 新增 release.yml推送版本 tag 即自动完成全部发布动作,包含 4 个串联 job:

  1. verify — 校验 tag 名 == setup.pyversion == constants.pyCLIENT_VERSION,不一致 fail fast(历史上 3.2.0b1/3.2.0 两处均有同步,校验可行)
  2. buildpython -m build 构建 sdist + wheel。顺带修正 wheel tag:本包要求 Python >=3.10,但旧流程 --universal 会产出 py2.py3 通用 wheel,现改为正确的 py3-none-any
  3. publish-pypi — 通过 PyPI Trusted Publishing (OIDC) 发布,仓库无需存放任何 PyPI token
  4. github-release--generate-notes 自动创建 GitHub Release(格式与现有 3.0.x Release 一致);tag 以 a/b/rc 结尾自动标记 pre-release

需要 PyPI 项目 owner 做一次性配置(已写在 workflow 文件头部注释):

PyPI → nacos-sdk-python → Publishing → Add a new publisher (GitHub):

  • Owner: nacos-group
  • Repository: nacos-sdk-python
  • Workflow name: release.yml
  • Environment name: pypi

配置完成前 workflow 不会误发布:未配置 publisher 时 publish-pypi job 会直接失败,不影响现有手动流程。

Which issue(s) does this PR fix?

Ref #328

How has this been tested?

GitHub Actions 无法在 fork 外预跑 tag 触发,已对每个 job 的核心逻辑做本地验证:

  • YAML 语法yaml.safe_load 通过
  • verify 逻辑:对当前代码(3.2.0)模拟 TAG=3.2.0 判定通过;版本提取正则对 setup.py / constants.py 实测有效
  • pre-release 判断3.2.0 → stable,3.2.0b1 / 3.3.0rc1 / 3.2.0a2 → prerelease,四个用例全部正确
  • build:本地实跑 python -m build,成功产出 nacos_sdk_python-3.2.0.tar.gznacos_sdk_python-3.2.0-py3-none-any.whl(sdist 含 requirements.txt/README.mdMANIFEST.in 已覆盖)
  • publish-pypi:采用 PyPA 官方 action pypa/gh-action-pypi-publish@release/v1 的标准用法(build/publish 分离 + artifact 传递 + environment + id-token: write

Checklist

Publishing is currently a fully manual three-step process (local
setup.py upload, push tag, create GitHub Release from the web UI),
and missing any step goes unnoticed -- e.g. 3.2.0 is on PyPI with
its tag pushed, but the GitHub Release was never created (nacos-group#328).

Add a release.yml workflow so that pushing a version tag performs
the whole release:

- verify: tag name must match both setup.py version and
  CLIENT_VERSION in constants.py, fail fast on mismatch
- build: python -m build for sdist + wheel (also fixes the wheel
  tag: the package requires Python >=3.10 but was previously built
  with --universal, producing a py2.py3 wheel)
- publish-pypi: publish via PyPI Trusted Publishing (OIDC), no
  API token stored in the repository
- github-release: create the GitHub Release with auto-generated
  notes, marking a/b/rc tags as pre-release

Requires a one-time Trusted Publishing configuration on PyPI by a
project owner (documented in the workflow header).

Ref nacos-group#328

Signed-off-by: cxhello <caixiaohuichn@gmail.com>
@cxhello cxhello requested a review from Sunrisea July 4, 2026 11:08
@cxhello

cxhello commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@Sunrisea 有空的时候帮忙 review 下这个 PR~ 背景见 #328:3.2.0 已发布到 PyPI 但 GitHub Release 缺失,这个 workflow 可以让后续发版只需推 tag 即自动完成 PyPI 发布和 Release 创建。

另外有两件事需要你确认:

  1. PyPI 侧需要项目 owner 配置一次 Trusted Publishing(步骤在 PR 描述和 workflow 头部注释里),配置前合入不影响现有手动流程;
  2. 3.2.0 的 GitHub Release 是否需要补发?notes 草稿在 [Release] 3.2.0 GitHub Release 缺失,提议补发并引入 tag 触发的自动发布 workflow #328 里,你同意的话我可以来补。

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.

1 participant