fix(release): タグからバージョンを確実に解決し、deprecated アクションを更新#280
Merged
Conversation
リリース時に build-n-publish が成功したり失敗したりする問題を修正。 setuptools_scm は Git タグからバージョンを算出するが、release.yml の actions/checkout@v2 はデフォルトの浅いチェックアウト(fetch-depth: 1)で タグを確実に取得しないため、タグの取得有無が実行タイミングに依存していた。 タグを取りこぼすと 0.1.dev1+g<sha> にフォールバックし、PyPI が ローカルバージョンラベルを拒否して 400 Bad Request になっていた。 - checkout に fetch-depth: 0 / fetch-tags: true を追加し、全履歴+タグを 取得してバージョンを常に解決できるようにする - deprecated なアクションを更新し SHA 固定 - actions/checkout v2 -> v4 - actions/setup-python v2 -> v5 - pypa/gh-action-pypi-publish @master(sunset) -> v1.14.0 - pypi_update_guide.md にバージョン解決の仕組みを追記 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
yo-tak
commented
Jun 22, 2026
| - name: Publish a Python distribution to PyPI | ||
| if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' | ||
| uses: pypa/gh-action-pypi-publish@master | ||
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 |
Contributor
Author
There was a problem hiding this comment.
別途下記ワーニングが出ていたのでついでに修正:
[build-n-publish: # >> PyPA publish to PyPI GHA: UNSUPPORTED GITHUB ACTION VERSION <<#L0](https://github.com/fastlabel/fastlabel-python-sdk/commit/6e97b6cd02efbfce1ae4b9df93fc5b7656a5cbff#annotation_60903713951)
You are using "pypa/gh-action-pypi-publish@master". The "master" branch of this project has been sunset and will not receive any updates, not even security bug fixes.
Please, make sure to use a supported version. If you want to pin to v1 major version, use "pypa/gh-action-pypi-publish@release/v1".
If you feel adventurous, you may opt to use use "pypa/gh-action-pypi-publish@unstable/v1" instead.
A more general recommendation is to pin to exact tags or commit shas.
yo-tak
commented
Jun 22, 2026
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v2 | ||
| uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5 |
Contributor
Author
There was a problem hiding this comment.
別途下記ワーニングが出ていたのでついでに修正(actions/checkoutも同様):
Node.js 20 is deprecated. The following actions target Node.js 20 but are being forced to run on Node.js 24: actions/checkout@v2, actions/setup-python@v2.
For more information see: https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/
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.
概要
リリース時の
build-n-publishジョブが実行ごとに成功したり失敗したりする問題を修正します。失敗時はPublish a Python distribution to PyPIステップで400 Bad Requestが発生していました。あわせて、sunset / deprecated になっている GitHub Actions を更新し、SHA 固定にします。
根本原因
このパッケージは
setuptools_scmによる動的バージョニングを採用しています。pyproject.toml→dynamic = ["version"]/[tool.setuptools_scm]setuptools_scmが Git タグ(git describe相当)から算出します。一方、
release.ymlの checkout はactions/checkout@v2をデフォルト設定で使っていました。デフォルトはfetch-depth: 1の浅い(shallow)チェックアウトで、単一コミットしか取得せずタグやフル履歴を確実には取得しません。その結果、ビルド時に対象タグが手元に存在するかどうかが実行タイミングに依存し、以下のように分岐していました。
0.21.00.1.dev1+g<sha>ログが示していた事実
失敗時の成果物名は
fastlabel-0.1.dev1+g6e97b6cd0でした。このg6e97b6cd0は、タグ0.21.0が付いているコミット6e97b6c(main の HEAD のマージコミット)そのものです。git rev-list -n 1 0.21.0→6e97b6cd0.../git describe --tags 6e97b6c→0.21.0つまり正しいコミットはチェックアウトできていたが、そのチェックアウトにタグが含まれていなかったため、
setuptools_scmがフォールバック値0.1.dev1+g<sha>を採用していた、ということです。なぜ「タグとリリースを分けて作成すると成功する」のか
GitHub UI で「新規タグ作成」と「Publish release」を同時に行うと、
release: publishedイベント発火 → checkout 実行 までの間にタグの伝搬が間に合わず、浅い checkout がコミットだけ取得してタグを取りこぼすレースが起きます。タグを先に作成してからリリースを公開すると、checkout 時点でタグが確実に存在するため毎回0.21.0に解決される、という挙動でした(操作者の観察と一致)。PyPI の
400 Bad Requestについてこれは上記の二次的な症状です。
0.1.dev1+g6e97b6cd0の+g6e97b6cd0は PEP 440 のローカルバージョンラベルで、PyPI はローカルラベル付きのアップロードを拒否します →400 Bad Request。間違ったバージョンが生成された結果、アップロードが弾かれていました。修正内容
.github/workflows/release.ymlfetch-depth: 0/fetch-tags: trueを追加(本質的修正)全履歴+タグを取得し、トリガーのタイミングに関わらず
setuptools_scmが常にタグからバージョンを解決できるようにします。これによりタグとリリースを同時に作成しても確実に動作し、「分けて作成する」回避策が不要になります。actions/checkout@v2→@692973e…(v4)actions/setup-python@v2→@39cd149…(v5)pypa/gh-action-pypi-publish@master(sunset) →@cef2210…(v1.14.0)test.ymlと同一 SHA に統一。pypi-publish はpassword(PYPI_API_TOKEN)ベースの認証を従来どおり継続。pypi_update_guide.md0.1.dev1+g<sha>へフォールバックして PyPI に弾かれることを明記。手順(Step 1〜3)自体は変更なし。動作確認方法
次回リリース時に
Checkジョブのログでdist内がfastlabel-<正しいバージョン>になっていることを確認してください(0.1.dev1+...にならない)。補足(任意・今後の検討)
pypa/gh-action-pypi-publishv1.14.0 以降は Trusted Publishing(OIDC, トークンレス) を推奨しています。passwordを撤廃しpermissions: id-token: write+ PyPI 側の信頼設定に移行すると、シークレット管理が不要になります。本 PR では既存のトークン方式を維持しています。🤖 Generated with Claude Code