ci: add tag-triggered release workflow with PyPI Trusted Publishing#329
Open
cxhello wants to merge 1 commit into
Open
ci: add tag-triggered release workflow with PyPI Trusted Publishing#329cxhello wants to merge 1 commit into
cxhello wants to merge 1 commit into
Conversation
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>
Member
Author
|
@Sunrisea 有空的时候帮忙 review 下这个 PR~ 背景见 #328:3.2.0 已发布到 PyPI 但 GitHub Release 缺失,这个 workflow 可以让后续发版只需推 tag 即自动完成 PyPI 发布和 Release 创建。 另外有两件事需要你确认:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
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:setup.py的version==constants.py的CLIENT_VERSION,不一致 fail fast(历史上3.2.0b1/3.2.0两处均有同步,校验可行)python -m build构建 sdist + wheel。顺带修正 wheel tag:本包要求 Python >=3.10,但旧流程--universal会产出 py2.py3 通用 wheel,现改为正确的py3-none-any--generate-notes自动创建 GitHub Release(格式与现有 3.0.x Release 一致);tag 以a/b/rc结尾自动标记 pre-release需要 PyPI 项目 owner 做一次性配置(已写在 workflow 文件头部注释):
配置完成前 workflow 不会误发布:未配置 publisher 时
publish-pypijob 会直接失败,不影响现有手动流程。Which issue(s) does this PR fix?
Ref #328
How has this been tested?
GitHub Actions 无法在 fork 外预跑 tag 触发,已对每个 job 的核心逻辑做本地验证:
yaml.safe_load通过TAG=3.2.0判定通过;版本提取正则对setup.py/constants.py实测有效3.2.0→ stable,3.2.0b1/3.3.0rc1/3.2.0a2→ prerelease,四个用例全部正确python -m build,成功产出nacos_sdk_python-3.2.0.tar.gz与nacos_sdk_python-3.2.0-py3-none-any.whl(sdist 含requirements.txt/README.md,MANIFEST.in已覆盖)pypa/gh-action-pypi-publish@release/v1的标准用法(build/publish 分离 + artifact 传递 + environment +id-token: write)Checklist