brew tap-new hanqunfeng/color_echo ## 输出 Warning: tap-new is a developer command, so Homebrew's developer mode has been automatically turned on. # 提示开发者模式已自动打开 To turn developer mode off, run: brew developer off # 如后续需要关闭开发者模式可以运行该命令 ## 初始化仓库 Initialized empty Git repository in /usr/local/Homebrew/Library/Taps/hanqunfeng/homebrew-color_echo/.git/ [main (root-commit) 35d602b] Create hanqunfeng/color_echo tap 3 files changed, 107 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/tests.yml create mode 100644 README.md ==> Created hanqunfeng/color_echo /usr/local/Homebrew/Library/Taps/hanqunfeng/homebrew-color_echo When a pull request making changes to a formula (or formulae) becomes green (all checks passed), then you can publish the built bottles. To do so, label your PR as `pr-pull` and the workflow will be triggered.
手写一个 Formula 文件
1 2
cd /usr/local/Homebrew/Library/Taps/hanqunfeng/homebrew-color_echo/Formula touch color_echo.rb
写入内容(模板):模板格式后面会详细介绍
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class ColorEcho < Formula desc "Print colorful text in terminal" homepage "https://github.com/hanqunfeng/color_echo" url "https://github.com/hanqunfeng/color_echo/archive/refs/tags/v1.0.0.tar.gz" sha256 "9450952a4b477c83ea2d7e28386d6ae38132bf68c46746aa218c03c21aa75f6d" license "MIT"
def install bin.install "bin/color_echo" end
testdo system "#{bin}/color_echo", "--help" end end
提交 Formula 文件到Github仓库
创建一个Github仓库,用于存储 Formula 文件: hanqunfeng/homebrew-color_echo
添加 Formula 文件到仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
cd $(brew --repo hanqunfeng/color_echo) git add . git commit -m "Add color_echo 1.0.0" git remote add origin https://github.com/hanqunfeng/homebrew-color_echo.git git push -u origin main ## 输出 Enumerating objects: 11, done. Counting objects: 100% (11/11), done. Delta compression using up to 12 threads Compressing objects: 100% (9/9), done. Writing objects: 100% (11/11), 2.11 KiB | 2.11 MiB/s, done. Total 11 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To https://github.com/hanqunfeng/homebrew-color_echo.git ! [remote rejected] main -> main (refusing to allow a Personal Access Token to create or update workflow `.github/workflows/publish.yml` without `workflow` scope) error: failed to push some refs to 'https://github.com/hanqunfeng/homebrew-color_echo.git'
提示缺少权限,需要给仓库添加权限。在 Github 中添加一个 Personal Access Token,并添加权限repo 和 workflow,重新推送
1 2 3 4 5 6 7 8 9 10 11 12 13
# 设置远程仓库地址,注意替换为你的仓库地址,并且密钥替换为实际的密钥 git remote set-url origin https://ghp_xxxxx@github.com/hanqunfeng/homebrew-color_echo.git git push -u origin main ## 输出 Enumerating objects: 11, done. Counting objects: 100% (11/11), done. Delta compression using up to 12 threads Compressing objects: 100% (9/9), done. Writing objects: 100% (11/11), 2.11 KiB | 2.11 MiB/s, done. Total 11 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To https://github.com/hanqunfeng/homebrew-color_echo.git * [new branch] main -> main branch 'main'set up to track 'origin/main'.