# Homebrew tap でコマンドを公開する

- URL: https://tech.fusic.co.jp/posts/homebrew-tap-publish/
- 公開日: 2018-11-14
- 著者: shiro seike / せいけ しろう / 清家 史郎
- 掲載: Fusic Tech Blog（株式会社Fusic）

> 清家です。 前回自作コマンドs3ryを記事投稿した…[続きを読むHomebrew tap でコマンドを公開する](https://tech.fusic.co.jp/cli/homebrew-tap-publish/)<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt -->

---

清家です。

[前回自作コマンドs3ryを記事投稿したところ](https://tech.fusic.co.jp/cloud/s3rypoweredbygo/)、社内の人から少し反応がありました  
（ありがたい）

不格好にgithubからダウンロードしてもらう方針だったのですが、  
「brew でインストールできるようにしてください」と言われて  
やったことないなと思ったので方法をまとめます。

## Formulaの作成

Formulaってやつを作るといいらしいです。  
[Cookbook](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md)があったのでこちらを参考に

## brew create

brew createを実行するとある程度テンプレートが出来るようです。  
今回プログラムのURLはGitHubに配置してある `https://github.com/seike460/s3ry/releases/download/0.1.1/s3ry_darwin_amd64.zip`  
ですので以下の用に入力

```plain; title: 
$ brew create https://github.com/seike460/s3ry/releases/download/0.1.1/s3ry\_darwin\_amd64.zip ==\> Downloading https://github.com/seike460/s3ry/releases/download/0.1.1/s3ry\_darwin\_amd64.zip ==\> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/124899200/b7e56e80-e7ba-11e8-8157-5684f491d267 ######################################################################## 100.0% Please `brew audit --new-formula s3ry` before submitting, thanks. Editing /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/s3ry.rb
```

自動で以下のファイルがEDITORで起動されます。

`/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/s3ry.rb`

```ruby; title: 
# Documentation: https://docs.brew.sh/Formula-Cookbook # https://www.rubydoc.info/github/Homebrew/brew/master/Formula # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! class S3ry \< Formula desc "Amazon S3 CLI Tool by using promptui" homepage "https://godoc.org/github.com/seike460/s3ry" url "https://github.com/seike460/s3ry/releases/download/0.1.1/s3ry\_darwin\_amd64.zip" sha256 "b9f8eab7950e9687f8b2922a9580a78420e1b3e0888e49178e69a8ce1ade0744" # depends\_on "cmake" =\> :build  def install # ENV.deparallelize # if your formula fails when building in parallel # Remove unrecognized options if warned by configure system "./configure", "--disable-debug", "--disable-dependency-tracking", "--disable-silent-rules", "--prefix=#{prefix}" # system "cmake", ".", \*std\_cmake\_args system "make", "install" # if this fails, try separate make/make install steps end  test do # `test do` will create, run in and delete a temporary directory. # # This test will fail and we won't accept that! For Homebrew/homebrew-core # this will need to be a test that verifies the functionality of the # software. Run the test with `brew test s3ry`. Options passed # to `brew install` such as `--HEAD` also need to be provided to `brew test`. # # The installed folder is not in the path, so use the entire path to any # executables being tested: `system "#{bin}/program", "do", "something"`. system "false" end end
```

Please `brew audit --new-formula s3ry` before submittingと言われたのでとりあえず叩いてみました。

```plain; title: 
s3ry: \* C: 1: col 1: Please remove default template comments \* C: 3: col 1: Please remove default template comments \* C: 9: col 3: Commented-out dependency "cmake" =\> :build \* C: 12: col 5: Please remove default template comments \* C: 13: col 5: Please remove default template comments \* C: 18: col 5: Please remove default template comments \* C: 19: col 30: Please remove default template comments \* https://github.com/seike460/s3ry/releases/download/0.1.1/s3ry\_darwin\_amd64.zip looks like a binary package, not a source archive. The `core` tap is source-only. \* GitHub repository not notable enough (\<30 forks, \<30 watchers and \<75 stars) Error: 9 problems in 1 formula detected
```

デフォルトコメント削除してくれって言われてるのと、  
GitHubでそんなにfolkされてないし、人気もないよって言われてます。そうですね。  
GitHubで人気がでるとススっとインストール出来る公式パッケージになるようですね。

まだまだ先の長い話ですので、別の方法を取ります。

## GitHubに homebrew用のリポジトリ作成

brew tap でインストール出来る用にするドキュメントが[こちら](https://github.com/Homebrew/brew/blob/master/docs/How-to-Create-and-Maintain-a-Tap.md)にありました。

github.com/user/homebrew-repo  
というリポジトリ、つまり僕の場合は  
github.com/seike460/homebrew-s3ry  
というリポジトリがあればいいようです。

早速作成し、brew createで作ったFormulaを持ってきます。

コメント削除してと言われたのでまずはコメント削除。  
その後デフォルトではMakeすることになってました。  
s3ryのMakeにはGoインストールが必要なので、他の方法あるやろと思って調査

## bin.install

[Cookbookに書いてありました](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md#bininstall-foo)

bin.installをすると、実行可能なパスに配置してくれながら権限も付与してくれるようです。

## version

updateなどを考えてversionは付与しておきました。

最終的なFormulaは以下に配置しています。

[s3ry.rb](https://github.com/seike460/homebrew-s3ry/blob/master/s3ry.rb)

## インストール

ここまで見てくれたMac使いの方は以下のコマンドを必ず叩いてください  
むしろここまで見てくれたのに叩いてくれないんですか？  
嘘です、気が向いた人は叩いてください。

```plain; title: 
brew tap seike460/s3ry brew install s3ry
```

するとs3ryコマンドが利用できる状況になっているはずです。  
お家Macでインストール出来たので問題ないと思ってますが、問題あれば[Issue](https://github.com/seike460/homebrew-s3ry/issues)くれたら凄く助かります。

見よう見まねだったので、ちゃんと[Cookbook](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md)見てから考慮不足などを直していこうと思います。

あとs3ry使ってみて気にいったらStarつけてくれると嬉しいです。  
↓  
[seike460/s3ry](https://github.com/seike460/s3ry)

<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->
