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
classColorEcho < 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"
definstall bin.install "bin/color_echo" end
test do 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'.
Homebrew 6.0.16(2026-08-10)起,官方 tap 的检查拒绝旧的 def post_install。7.0.0(2026-09-13)起,所有 tap 跑 brew style / brew audit 都会报 Formulae must use post_install_steps instead of post_install。第三方 tap 在迁移期间加载旧方法还能执行,但已经废弃。同一个 Formula 里不能同时写 post_install 和 post_install_steps。
这个命令不走 JSON API,只读本机 tap 里的 .rb。Homebrew 4.0 之后官方 homebrew/core 默认不 clone 到本地,所以直接查 git 会报 These formulae are not in any locally installed taps!。要先 brew tap homebrew/core,并且脚本里写了 livecheck,命令才能按这段配置查出新版本。没写 livecheck 时,它会改去试 url 和 homepage;地址如果只是某一个压缩包,页面上没有版本列表,就查不出更新。skip 则明确不请求。
defcaveats # 安装结束时打印:python3 和下面这些工具都不是本 formula 的 depends_on <<~EOS python3 is required but NOT installed by this formula. Install before use: brew install python@3.13 Needed for: deps list cache, --deps validation, and other Initializr metadata parsing. Optional tools (not installed by this formula): - jq: brew install jq - libxml2 (xmllint): brew install libxml2 - xmlstarlet: brew install xmlstarlet - mvn: brew install maven xmllint / xmlstarlet / mvn: only for Maven "module add" parent POM parsing (awk fallback still works). Network access to Spring Initializr is required (default: https://start.spring.io). Override with: export INITIALIZR_BASE_URL=<mirror-url> EOS end
test do # shell_output 取命令的标准输出,assert_match 确认里面有预期文案 assert_match "springboot <command>", shell_output("#{bin}/springboot --help") # dry-run 不真正生成项目,用来确认 create 子命令能跑起来 assert_match "Dry-run 模式", shell_output("#{bin}/springboot create --name=brewtest --dry-run") end end