From 5fb7f8b1b012f08bc6474de7b6d5638b07aede45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=B6=E6=9D=96?= Date: Tue, 10 Dec 2024 23:42:21 +0800 Subject: [PATCH] Refactor Homebrew update workflow to trigger on successful completion of the Release workflow. Update version retrieval to fetch the latest release information from GitHub API and construct the download URL dynamically. This enhances the automation of the Homebrew tap update process. --- .github/workflows/update-homebrew.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update-homebrew.yml b/.github/workflows/update-homebrew.yml index 3b58954..55b8356 100644 --- a/.github/workflows/update-homebrew.yml +++ b/.github/workflows/update-homebrew.yml @@ -1,15 +1,17 @@ name: Update Homebrew Tap on: - release: - types: [published, edited, released] - push: - tags: - - 'v*' + workflow_run: + workflows: ["Release"] + types: + - completed + branches: + - main jobs: update-tap: runs-on: macos-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout tap uses: actions/checkout@v4 @@ -21,13 +23,14 @@ jobs: - name: Get release info id: release run: | - # 获取版本号(移除 v 前缀如果存在) - VERSION=${GITHUB_REF#refs/tags/} - VERSION=${VERSION#v} + # 获取最新的 release 信息 + RELEASE_INFO=$(curl -s https://api.github.com/repos/ygsgdbd/DanceKunKun/releases/latest) + VERSION=$(echo "$RELEASE_INFO" | jq -r .tag_name | sed 's/^v//') + DOWNLOAD_URL=$(echo "$RELEASE_INFO" | jq -r '.assets[] | select(.name=="DanceKunKun.dmg") | .browser_download_url') + echo "version=$VERSION" >> $GITHUB_OUTPUT - # 构建下载 URL 并验证文件是否存在 - DOWNLOAD_URL="https://github.com/ygsgdbd/DanceKunKun/releases/download/${GITHUB_REF#refs/tags/}/DanceKunKun.dmg" + # 下载并验证文件 HTTP_STATUS=$(curl -L -s -o DanceKunKun.dmg -w "%{http_code}" "$DOWNLOAD_URL") if [ "$HTTP_STATUS" != "200" ]; then