Skip to content

ci: publish.yml に --skip-existing と手動確認用の実行を加える - #7

Merged
tomio2480 merged 2 commits into
masterfrom
ci/publish-skip-existing-and-dry-run
Aug 12, 2026
Merged

ci: publish.yml に --skip-existing と手動確認用の実行を加える#7
tomio2480 merged 2 commits into
masterfrom
ci/publish-skip-existing-and-dry-run

Conversation

@tomio2480

@tomio2480 tomio2480 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

背景

Dependabot PR #2#4 の検証中,publish.yml だけは実行経路を確認できなかった.
release: published がトリガーであり,走らせると PyPI へ実際に公開されるためである.

PyPI は一度受け付けた版番号を二度と再利用させない.
そのため公開経路の不備は,検証しづらいうえに失敗時の代償が大きい.
現状の publish.yml には次の 2 つの弱点がある.

問題 1: 失敗後に再実行できない

twine upload dist/* は,既にアップロード済みのファイルがあるとエラーになる.
sdistwheel のうち片方だけ成功した状態で失敗すると,
再実行は必ず重複エラーで止まる.
PyPI 側は版番号を消費済みのため,同じ版で公開し直すこともできない.

--skip-existing を付ければ,既存分を読み飛ばして残りだけを送るため,
Actions の再実行で復旧できる.
再実行は元の release の ref を保つため,経路も変わらない.

問題 2: 公開せずに経路を確認する手段がない

リリース前にビルドと twine check だけ試したくても,
release: published 以外の入口がない.

workflow_dispatch を追加して確認できるようにする.

変更内容

表 1. 変更点.

箇所 変更
トリガー workflow_dispatch を追加
Publish ステップ twine upload--skip-existing を付与
Publish ステップ release イベント時のみ実行する条件を付与
Skip publish ステップ 手動実行時に成果物一覧を表示

手動実行からは公開できない設計とした.
workflow_dispatch は任意の ref を選択できるため,
公開を許すと未リリースのブランチをそのまま PyPI へ出せてしまい,
release ゲートを迂回する.PyPI の性質上これは取り返しがつかない.

- name: Publish to PyPI
  if: github.event_name == 'release'

条件を release イベントに限定したので,手動実行では
PYPI_API_TOKEN を参照するステップ自体が動かない.
シークレットに触れない確認経路と,公開経路が分離されている.

release: published からの実行は従来どおりアップロードまで進む.

経緯

初版では dry_run 入力を設け,false を選べば手動実行から公開できる構成にしていた.
Codex のレビューで,任意の ref を公開できる点を P1 として指摘され,
入力ごと廃して手動実行を確認専用に改めた.

確認

  • YAML としてパースできることを確認済み.
  • トリガーは releaseworkflow_dispatch の 2 つ.
  • Publish と Skip publish の条件が排他であることを確認済み.

workflow_dispatch は既定ブランチに当該ワークフローが存在して初めて有効になる.
そのため手動実行の実挙動は本 PR のマージ後でなければ試せない.
マージ後に 1 度実行し,ビルドと twine check の通過を確認する運用を想定している.

補足

publish.yml は長期有効な PYPI_API_TOKEN を使っている.
PyPI は現在 Trusted Publishing(OIDC)を推奨しており,
シークレットを保持しない構成へ移行できる.
本 PR の範囲外とし,別途判断を仰ぐ.

🤖 Generated with Claude Code

twine upload が途中で失敗した状態で再実行すると,
既にアップロード済みのファイルで重複エラーになり復旧できない.
PyPI は同じ版番号を二度と受け付けないため,版番号を失う.
--skip-existing を付けて再実行を可能にする.

併せて workflow_dispatch と dry_run 入力を追加する.
アップロードを伴わずにビルドと twine check だけを実行でき,
リリース前に公開経路を確認できる.

dry_run の既定値は true とし,誤操作で公開されないようにする.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4aa7286f-1d5b-451d-8bfa-0467493771d5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tomio2480

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread .github/workflows/publish.yml Outdated
run: twine check dist/*

- name: Publish to PyPI
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ご指摘のとおりです.対応しました.

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>
@tomio2480

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: d4759a3cf0

ℹ️ 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".

@tomio2480 tomio2480 changed the title ci: publish.yml に --skip-existing と dry run を加える ci: publish.yml に --skip-existing と手動確認用の実行を加える Aug 12, 2026
@tomio2480
tomio2480 marked this pull request as ready for review August 12, 2026 18:32
@tomio2480
tomio2480 merged commit 02fe117 into master Aug 12, 2026
11 checks passed
@tomio2480
tomio2480 deleted the ci/publish-skip-existing-and-dry-run branch August 12, 2026 18:32
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