From 4abce8070ebb21e1d56101d56c25f872c060f1ca Mon Sep 17 00:00:00 2001 From: titor Date: Fri, 24 Apr 2026 03:47:47 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20GitHub=20Actions=20w?= =?UTF-8?q?orkflow=EF=BC=88=E6=94=AF=E6=8C=81=E5=A4=9A=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 matrix 构建:ubuntu, macos, windows - 支持:linux-amd64, linux-arm64, darwin-amd64, darwin-arm64, windows-amd64 - 使用 actions/upload-artifact 上传构建产物 - 使用 gh release 创建 release --- .github/workflows/release.yml | 135 +++++++++++++++------------------- 1 file changed, 60 insertions(+), 75 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 09a6e2c..2499051 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,94 +7,79 @@ on: jobs: build: - runs-on: ubuntu24.04 + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + target: linux-amd64 + - os: ubuntu-latest + target: linux-arm64 + - os: macos-latest + target: darwin-amd64 + - os: macos-latest + target: darwin-arm64 + - os: windows-latest + target: windows-amd64 steps: - - name: Setup mirrors - run: | - echo 'deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse' | tee /etc/apt/sources.list - apt-get update -qq - - - name: Install Rust - run: | - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - . "$HOME/.cargo/env" - - # 安装交叉编译目标 - rustup target add aarch64-unknown-linux-gnu || true - rustup target add x86_64-apple-darwin || true - rustup target add aarch64-apple-darwin || true - rustup target add x86_64-pc-windows-gnu || true - - - name: Setup cargo mirror - run: | - mkdir -p ~/.cargo - cat > ~/.cargo/config.toml << 'CARGO_EOF' -[source.crates-io] -replace-with = "ustc" - -[source.ustc] -registry = "sparse+https://mirrors.ustc.edu.cn/crates.io/index/" -CARGO_EOF - - name: Checkout code - run: git clone https://hub.gaomia.site/titor/haibao-tts-cli.git /workspace/mimo-tts + uses: actions/checkout@v4 - - name: Build all binaries + - name: Setup Rust + uses: dtolnay/rust-action@stable + + - name: Build binary run: | - . "$HOME/.cargo/env" - cd /workspace/mimo-tts + ext="" + [ "${{ matrix.target }}" = "windows-amd64" ] && ext=".exe" - # Linux x86_64 - cargo build --release -p mimo-tts - mv target/release/mimo-tts mimo-tts-linux-amd64 + if [ "${{ matrix.target }}" = "linux-arm64" ]; then + GOOS=linux GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-unknown-linux-gnu + elif [ "${{ matrix.target }}" = "darwin-amd64" ]; then + GOOS=darwin GOARCH=amd64 cargo build --release -p mimo-tts + elif [ "${{ matrix.target }}" = "darwin-arm64" ]; then + GOOS=darwin GOARCH=arm64 cargo build --release -p mimo-tts + elif [ "${{ matrix.target }}" = "windows-amd64" ]; then + GOOS=windows GOARCH=amd64 cargo build --release -p mimo-tts + else + cargo build --release -p mimo-tts + fi - # Linux ARM64 - GOOS=linux GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-unknown-linux-gnu - mv target/release/mimo-tts mimo-tts-linux-arm64 - - # macOS x86_64 - GOOS=darwin GOARCH=amd64 cargo build --release -p mimo-tts --target x86_64-apple-darwin - mv target/release/mimo-tts mimo-tts-darwin-amd64 - - # macOS ARM64 - GOOS=darwin GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-apple-darwin - mv target/release/mimo-tts mimo-tts-darwin-arm64 - - # Windows x86_64 - GOOS=windows GOARCH=amd64 cargo build --release -p mimo-tts --target x86_64-pc-windows-gnu - mv target/release/mimo-tts.exe mimo-tts-windows-amd64.exe + mv target/release/mimo-tts "mimo-tts-${{ matrix.target }}${ext}" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: mimo-tts-${{ matrix.target }} + path: mimo-tts-${{ matrix.target }}* + retention-days: 1 + + release: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts - name: Generate checksums run: | - cd /workspace/mimo-tts + cd artifacts sha256sum mimo-tts-* > checksums.txt - name: Create release env: - GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - GITEA_URL="https://hub.gaomia.site" - REPO="titor/haibao-tts-cli" - - cd /workspace/mimo-tts + cd artifacts COMMIT_MSG=$(git log -1 --format="%s" HEAD) - TAG_NAME="latest" - - # 删除已存在的 release(如果存在) - curl -s -X DELETE "${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG_NAME}" \ - -H "Authorization: token ${GITEA_TOKEN}" - - # 创建新 release - 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\":\"Release ${TAG_NAME}\",\"body\":\"${COMMIT_MSG}\",\"draft\":false}") - - RELEASE_ID=$(echo "$RELEASE_RESPONSE" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2) - - for f in mimo-tts-* checksums.txt; 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 + # 使用 GitHub CLI 创建 release + gh release create latest \ + --title "Latest Release" \ + --notes "$COMMIT_MSG" \ + mimo-tts-* checksums.txt \ No newline at end of file