build:update action config #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
build: | |
runs-on: macos-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Create Release Package | |
run: | | |
VERSION=${GITHUB_REF#refs/tags/} | |
VERSION_NUM=${VERSION#v} | |
PACKAGE_NAME="caz-${VERSION_NUM}" | |
# 创建发布目录结构 | |
mkdir -p "${PACKAGE_NAME}/bin" | |
cp LICENSE "${PACKAGE_NAME}/" | |
cp README.md "${PACKAGE_NAME}/" | |
cp bin/caz "${PACKAGE_NAME}/bin/" | |
# 创建 tar.gz 包 | |
tar -czf "${PACKAGE_NAME}.tar.gz" "${PACKAGE_NAME}" | |
# 计算 SHA256 | |
SHA256=$(shasum -a 256 "${PACKAGE_NAME}.tar.gz" | cut -d ' ' -f 1) | |
echo "PACKAGE_SHA=${SHA256}" >> $GITHUB_ENV | |
echo "PACKAGE_NAME=${PACKAGE_NAME}.tar.gz" >> $GITHUB_ENV | |
echo "VERSION_NUM=${VERSION_NUM}" >> $GITHUB_ENV | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.VERSION_NUM }} | |
release_name: Release v${{ env.VERSION_NUM }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./${{ env.PACKAGE_NAME }} | |
asset_name: ${{ env.PACKAGE_NAME }} | |
asset_content_type: application/gzip | |
- name: Update Homebrew Formula | |
env: | |
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TOKEN }} | |
run: | | |
# 检查 Homebrew tap 仓库是否存在 | |
if ! curl --output /dev/null --silent --head --fail "https://github.com/${{ github.repository_owner }}/homebrew-caz"; then | |
echo "Error: homebrew-caz repository does not exist. Please create it first." | |
exit 1 | |
fi | |
# 克隆 Homebrew tap 仓库 | |
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository_owner }}/homebrew-caz.git | |
cd homebrew-caz | |
# 更新 formula | |
cat > caz.rb << EOF | |
class Caz < Formula | |
desc "Clean .DS_Store files and create ZIP archives" | |
homepage "https://github.com/${{ github.repository }}" | |
url "https://github.com/${{ github.repository }}/releases/download/v${VERSION_NUM}/caz-${VERSION_NUM}.tar.gz" | |
sha256 "${PACKAGE_SHA}" | |
license "MIT" | |
def install | |
bin.install "bin/caz" | |
end | |
test do | |
system "#{bin}/caz", "-h" | |
end | |
end | |
EOF | |
# 提交更新 | |
git config user.name "GitHub Action" | |
git config user.email "action@github.com" | |
git add caz.rb | |
git commit -m "Update formula to version ${VERSION_NUM}" | |
git push |