Skip to content

PRマージ時に同一リポジトリのHomebrew Formulaを更新する - #3

Merged
s4na merged 6 commits into
mainfrom
feat/homebrew-install
Sep 24, 2026
Merged

s4na merged 6 commits into
mainfrom
feat/homebrew-install

Conversation

@s4na

@s4na s4na commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

目的

PRマージ時にGHAが同じリポジトリのFormulaへソースURLとSHA-256を書き込み、非公式tapとしてHomebrewで導入できるようにします。

変更

  • mainへのpush時にGitHub APIでマージ済みPRの merge_commit_sha と一致するかを確認。一致した場合だけ更新。チェックアウトはmain固定です
  • マージコミットのアーカイブとチェックサムをFormulaに固定し、標準の GITHUB_TOKEN でmainにコミット
  • mainが進んだ古いイベントや更新済みイベントはスキップ。pushはfast-forwardのみ
  • 別tapリポジトリ、追加secret、GitHub Release作成は不要
  • macOS CIでFormulaの生成、tap経由の実インストールと brew test を検証

インストール

初回は以下の一行です。リポジトリ名が homebrew- で始まらないため、URL付きのtap登録が必要です。

brew tap s4na/textdiffedit https://github.com/s4na/textdiffedit.git && brew install s4na/textdiffedit/textdiffedit

tap登録後は brew install s4na/textdiffedit/textdiffedit を使えます。初回マージ後のFormula更新完了が必要です。

検証

  • Python unittest 10件・Ruff・git diff --check 成功
  • Formula生成のSHA-256一致、再実行、バージョン更新、不正入力時にファイルを変えないことを確認
  • YAML解析・ワークフロー内シェル構文の検証成功
  • 現head (5aeba4e) のCIは test-and-lint / zizmor / homebrew 全件成功
  • macOSでtap経由の brew install と brew test 成功
  • 現headのレビュー完了。既存指摘はコード・説明で対応済み(GitHubスレッド未Resolve)
  • 直接pushとマージの競合時に公開をスキップする指摘は、下記の運用制約として説明済み

運用上の条件

標準トークンの contents: write と pull-requests: read を使います。mainへのbot pushを禁止する保護ルールがある場合は更新も拒否されます。通常のcloseやmainへの直接pushではFormulaを更新しません。

公開処理中に直接pushが重なると、対象マージの公開をスキップするかpushが拒否され、Formulaは前の公開版に留まる場合があります。この場合は次のPRマージで更新します。今回は古いマージを遡って公開する競合回復処理は追加しません。

セルフレビュー

全差分を確認し、Formula更新とインストール検証に必要な範囲へ限定しました。ハッシュの自己参照、古いイベントによる上書き、未マージコードの実行を避けています。共有の小さな生成スクリプトをCIとマージ後の処理で使っています。

by ChatGPT

s4na commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-24T15:48:48.114051Z 5aeba4e Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 452e06a8a5

ℹ️ 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 Formula/textdiffedit.rb

def install
libexec.install "textdiffedit"
(bin/"textdiffedit").write <<~SH

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 Mark the generated launcher executable

On every Homebrew installation, Pathname#write creates this new wrapper without execute bits, so the documented textdiffedit --help invocation—and the formula's own test—fails with “Permission denied.” Explicitly chmod 0755 the generated file or create it through an executable-script helper.

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.

実行ファイルへ chmod 0755 を設定済みです。現headのmacOS CIでtap経由の brew install と brew test が成功し、インストールしたコマンドの起動も確認できました。

by ChatGPT

Comment thread README.md
git clone https://github.com/s4na/textdiffedit.git
brew install --HEAD ./textdiffedit/Formula/textdiffedit.rb
gh auth login
textdiffedit --help

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use the installed launcher in the usage examples

For users following this new Homebrew section, the examples immediately below still invoke python -m textdiffedit instead of the installed command. The formula places the package only in its private libexec and exposes that path through the wrapper, so after the cloned checkout is removed or the user runs from another directory, those documented commands cannot import textdiffedit; update them to invoke textdiffedit.

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.

READMEのPR本文・Issue本文の使用例を、インストール後の textdiffedit コマンドに変更済みです。

by ChatGPT

s4na commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 414fc31cc0

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

@s4na s4na changed the title Homebrew から textdiffedit をインストールできるようにする Homebrew tap 配布とマージ後の自動公開を追加 Sep 24, 2026

s4na commented Sep 24, 2026

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: 45a06f5b96

ℹ️ 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/release.yml Outdated
GH_TOKEN: ${{ github.token }}
TAG: v0.1.${{ github.run_number }}
run: |
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make release creation safe to rerun

If this succeeds but any later operation—downloading the archive, checking out or editing the tap, or pushing it—fails, rerunning the failed job reuses the same github.run_number, so $TAG already identifies the release created here and gh release create fails rather than repairing the tap. The inspected gh release create --help confirms that the command creates the release and automatically creates the matching tag when absent; reuse an existing release/tag or defer publication so the workflow's normal rerun path can complete.

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.

構成を見直し、GitHub Release作成を削除しました。同一リポジトリのFormulaをマージコミットのアーカイブへ固定し、標準トークンで1コミットをpushします。push前に失敗した場合は同じ実行番号で再実行でき、push済みの場合はmainが進んでいるためスキップします。

by ChatGPT

Comment thread .github/workflows/release.yml Outdated
git -C tap config user.email 41898282+github-actions[bot]@users.noreply.github.com
git -C tap add Formula/textdiffedit.rb
git -C tap commit -m "Update textdiffedit to $TAG"
git -C tap push

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Prevent stale release runs from overwriting the tap

In the inspected release workflow, every main push starts an independent job and this push has no concurrency or freshness guard. If two pushes overlap and the older run checks out the tap after the newer run has updated it, the older run can successfully commit its lower v0.1.N URL on top and leave new Homebrew installs pinned to older code; if both check out the same base, one instead fails with a non-fast-forward push. Cancel superseded runs or verify that the tag being written is still the newest before pushing.

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.

同一リポジトリへ集約し、開始時にmainのHEADと対象SHAが一致することを確認するようにしました。処理中にmainが進んだ場合も通常のfast-forward pushが拒否するため、古い内容で上書きしません。

by ChatGPT

Comment thread .github/workflows/release.yml Outdated
on:
push:
branches: [main]
workflow_dispatch:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict manual releases to main

A workflow_dispatch run can be launched against any selectable ref containing this workflow, and there is no subsequent github.ref guard, so selecting a feature or maintenance branch makes the checkout and $GITHUB_SHA refer to that branch while the job still creates a normal release and overwrites the stable Homebrew formula. This can publish unmerged branch code as the stable package; restrict dispatches to refs/heads/main or require and validate an explicit release ref.

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.

手動実行を削除しました。mainへのpushに限定し、対象SHAがmainへマージ済みのPRのmerge_commit_shaと一致する場合のみFormulaを更新します。

by ChatGPT

Comment thread .github/workflows/release.yml Outdated
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: '3.10'
- run: python -W error -m unittest discover -s tests

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate publication on the repository lint check

The inspected .github/workflows/ci.yml runs both Ruff and the unit tests, but this is an independent push workflow and only executes the tests here, so it does not wait for that sibling CI job. A commit that passes the current tests but fails Ruff—for example, an undefined name in an untested runtime path—can therefore be tagged and published to the tap while CI is red; run the lint step in this job or make publication depend on successful CI.

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.

Formula更新前にRuffと既存のunittestを実行するようにしました。現headのCIでもlint・テストは成功しています。

by ChatGPT

s4na commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: c5ef3d76c8

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

@s4na s4na changed the title Homebrew tap 配布とマージ後の自動公開を追加 PRマージ時に同一リポジトリのHomebrew Formulaを更新する Sep 24, 2026

s4na commented Sep 24, 2026

Copy link
Copy Markdown
Owner Author

@codex review

s4na commented Sep 24, 2026

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: 5aeba4e922

ℹ️ 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 on lines +10 to +12
concurrency:
group: homebrew-formula
cancel-in-progress: false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve pending merge publications

GitHub Actions allows only one pending run per concurrency group, and cancel-in-progress: false protects only the running run. If one publication is running, a PR-merge run is pending, and then a direct push arrives, the direct-push run replaces the pending merge run; the running run's push is rejected because main advanced, while the replacement exits at the MERGED_PR check. The Formula therefore remains stale until another PR is merged. Avoid using one replaceable pending slot, or have the surviving run locate and publish the latest eligible merge rather than requiring its event SHA to still be HEAD.

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.

この競合ケースでFormulaが前の版に留まる点は確認しました。本PRでは、対象のマージコミットが公開時点のmainでなくなった場合は公開をスキップする方針をREADMEに明記しています。concurrencyだけを外してもHEADの一致条件により同じケースはスキップになります。

直接pushとPRマージが混在した場合も過去のマージを必ず公開するには、過去マージの選択と、進んだmainにFormulaだけを追加する競合処理が必要になります。今回は「マージ時だけ同じリポジトリにハッシュを書く」という簡潔な運用に限定し、その追加処理は採用しません。直接pushが公開処理に重なった場合は前の公開版を保持し、次のPRマージで更新するという運用上の制約としてPR本文にも残します。

by ChatGPT

@s4na
s4na merged commit fba318c into main Sep 24, 2026
3 checks passed
@s4na
s4na deleted the feat/homebrew-install branch September 24, 2026 16:00
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