missuo/missuo.github.io

Automatically update Homebrew versions using Action | Vincent's Notes

Opened this issue · 0 comments

missuo commented

https://missuo.me/posts/brew-version-update/

Homebrew可以说是Mac上必装的命令行工具之一。它真的太好用太方便的。但是你在维护一个Homebrew Tap的时候,如果你的程序有新的Release发布时,需要在对应的.rb文件中修改版本号以及对应的二进制文件的sha256,这显然会有些繁琐,或者说不太优雅。
我习惯使用GitHub Action去交叉编译各种Release,重要的是Action可以帮助我自动发布。其实在每一次Action发布之后,可以添加一个Step,去更新Casks或者Formula的.rb。为了方便,你可以创建一个.sh文件来做这件事。
部分代码(以DeepL X为例) 更新版本号 # Get the latest version of Deeplx last_version=$(curl -Ls "https://api.github.com/repos/OwO-Network/DeepLX/releases/latest" | grep '"tag_name":' | sed -E 's/."([^"]+)"./\1/' | sed 's/v//g') # Update the version number in the formula sed -i "s/version ".*/version "${last_version}"/g" Formula/deeplx.rb 更新sha256 # Download the new binaries wget -O deeplx_darwin_amd64 https://github.com/OwO-Network/DeepLX/releases/download/v${last_version}/deeplx_darwin_amd64 wget -O deeplx_darwin_arm64 https://github.com/OwO-Network/DeepLX/releases/download/v${last_version}/deeplx_darwin_arm64 # Calculate the SHA256 hash for the new binaries amd64_sha256=$(sha256sum deeplx_darwin_amd64 | cut -d ' ' -f 1) arm64_sha256=$(sha256sum deeplx_darwin_arm64 | cut -d ' ' -f 1) # Update the SHA256 hashes in the formula sed -i "8s/.