From c4ae5df33ea6b73f78b07e1830f591c5e0cbd48e Mon Sep 17 00:00:00 2001 From: titor Date: Fri, 24 Apr 2026 03:37:12 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20Gitea=20Actions=20wo?= =?UTF-8?q?rkflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 每次 push 到 main 分支时自动构建 - 支持多平台:linux amd64/arm64, darwin amd64/arm64, windows amd64 - 自动生成 checksums.txt - 自动更新 release 内容(使用 git log) --- .github/workflows/release.yml | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fcbbb19 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,82 @@ +name: Release + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu + strategy: + matrix: + target: + - os: linux + arch: amd64 + - os: linux + arch: arm64 + - os: darwin + arch: amd64 + - os: darwin + arch: arm64 + - os: windows + arch: amd64 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build + run: | + ext="" + [ "${{ matrix.target.os }}" = "windows" ] && ext=".exe" + GOOS=${{ matrix.target.os }} GOARCH=${{ matrix.target.arch }} cargo build --release -p mimo-tts + mv target/release/mimo-tts "mimo-tts-${{ matrix.target.os }}-${{ matrix.target.arch }}${ext}" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: mimo-tts-${{ matrix.target.os }}-${{ matrix.target.arch }} + path: mimo-tts-* + + release: + needs: build + runs-on: ubuntu + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Create checksums + run: | + cd artifacts + sha256sum mimo-tts-* > checksums.txt + + - name: Create release + env: + GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }} + run: | + GITEA_URL="https://hub.gaomia.site" + REPO="titor/haibao-tts-cli" + + COMMIT_MSG=$(git log -1 --format="%s" HEAD) + COMMIT_BODY=$(git log -1 --format="%b" HEAD) + + TAG_NAME="latest" + RELEASE_BODY="${COMMIT_MSG}\n\n${COMMIT_BODY}" + + RELEASE_RESPONSE=$(curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${TAG_NAME}\",\"body\":\"${RELEASE_BODY}\",\"draft\":false}") + + RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) + + for f in artifacts/*; do + [ -f "$f" ] && curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -F "attachment=@$f" + done \ No newline at end of file