ci: publish.yml に --skip-existing と手動確認用の実行を加える - #7
Conversation
twine upload が途中で失敗した状態で再実行すると, 既にアップロード済みのファイルで重複エラーになり復旧できない. PyPI は同じ版番号を二度と受け付けないため,版番号を失う. --skip-existing を付けて再実行を可能にする. 併せて workflow_dispatch と dry_run 入力を追加する. アップロードを伴わずにビルドと twine check だけを実行でき, リリース前に公開経路を確認できる. dry_run の既定値は true とし,誤操作で公開されないようにする. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f118a1571
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| run: twine check dist/* | ||
|
|
||
| - name: Publish to PyPI | ||
| if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run) |
There was a problem hiding this comment.
Restrict manual publishing to an approved ref
For a workflow_dispatch run, an operator can select any branch or tag—the gh workflow run documentation defines --ref as the ref containing the workflow version—and the checkout step builds that selected ref. Because this condition allows uploading based only on dry_run: false, accidentally selecting a feature branch can irreversibly publish unreleased or incorrect code to PyPI, bypassing the previous release: published gate; require an approved protected ref/tag here or separate the secretless dry-run path from publishing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
ご指摘のとおりです.対応しました.
workflow_dispatch は任意の ref を選択できるため,dry_run: false を選べば
未リリースのブランチをそのまま PyPI へ公開でき,release ゲートを迂回します.
PyPI は版番号を再利用できないため,取り返しがつきません.
dry_run 入力を廃し,手動実行では常にアップロードしない構成へ改めました.
- name: Publish to PyPI
if: github.event_name == 'release'条件を release イベントに限定したので,手動実行では
PYPI_API_TOKEN を参照するステップ自体が動きません.
ご提案の「secretless な dry-run 経路を公開経路から分離する」に沿う形です.
失敗したリリースの復旧は Actions の再実行で行います.
再実行は元の release の ref を保つため経路が変わらず,
--skip-existing により重複アップロードも避けられます.
手動実行から公開できる必要はなくなりました.
workflow_dispatch は任意の ref を選択できる. dry_run を false にすれば,未リリースのブランチの内容を そのまま PyPI へ公開できてしまい,release ゲートを迂回する. PyPI は版番号を再利用できないため取り返しがつかない. dry_run 入力を廃し,手動実行では常にアップロードを行わない構成へ改める. Publish ステップの条件を release イベントに限定することで, 手動実行時は PYPI_API_TOKEN を参照するステップ自体が動かない. 失敗したリリースの復旧は,Actions の再実行で行う. 再実行は元の release の ref を保つため経路が変わらず, --skip-existing により重複アップロードも避けられる. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
背景
Dependabot PR #2〜#4 の検証中,
publish.ymlだけは実行経路を確認できなかった.release: publishedがトリガーであり,走らせると PyPI へ実際に公開されるためである.PyPI は一度受け付けた版番号を二度と再利用させない.
そのため公開経路の不備は,検証しづらいうえに失敗時の代償が大きい.
現状の
publish.ymlには次の 2 つの弱点がある.問題 1: 失敗後に再実行できない
twine upload dist/*は,既にアップロード済みのファイルがあるとエラーになる.sdistとwheelのうち片方だけ成功した状態で失敗すると,再実行は必ず重複エラーで止まる.
PyPI 側は版番号を消費済みのため,同じ版で公開し直すこともできない.
--skip-existingを付ければ,既存分を読み飛ばして残りだけを送るため,Actions の再実行で復旧できる.
再実行は元の release の ref を保つため,経路も変わらない.
問題 2: 公開せずに経路を確認する手段がない
リリース前にビルドと
twine checkだけ試したくても,release: published以外の入口がない.workflow_dispatchを追加して確認できるようにする.変更内容
表 1. 変更点.
workflow_dispatchを追加twine uploadに--skip-existingを付与releaseイベント時のみ実行する条件を付与手動実行からは公開できない設計とした.
workflow_dispatchは任意の ref を選択できるため,公開を許すと未リリースのブランチをそのまま PyPI へ出せてしまい,
releaseゲートを迂回する.PyPI の性質上これは取り返しがつかない.条件を
releaseイベントに限定したので,手動実行ではPYPI_API_TOKENを参照するステップ自体が動かない.シークレットに触れない確認経路と,公開経路が分離されている.
release: publishedからの実行は従来どおりアップロードまで進む.経緯
初版では
dry_run入力を設け,falseを選べば手動実行から公開できる構成にしていた.Codex のレビューで,任意の ref を公開できる点を P1 として指摘され,
入力ごと廃して手動実行を確認専用に改めた.
確認
releaseとworkflow_dispatchの 2 つ.workflow_dispatchは既定ブランチに当該ワークフローが存在して初めて有効になる.そのため手動実行の実挙動は本 PR のマージ後でなければ試せない.
マージ後に 1 度実行し,ビルドと
twine checkの通過を確認する運用を想定している.補足
publish.ymlは長期有効なPYPI_API_TOKENを使っている.PyPI は現在 Trusted Publishing(OIDC)を推奨しており,
シークレットを保持しない構成へ移行できる.
本 PR の範囲外とし,別途判断を仰ぐ.
🤖 Generated with Claude Code