ci: 添加 GitHub Actions workflow(支持多平台构建)
Some checks failed
Release / build (ubuntu-latest, linux-amd64) (push) Failing after 3m52s
Release / build (ubuntu-latest, linux-arm64) (push) Failing after 22s
Release / build (macos-latest, darwin-amd64) (push) Has been cancelled
Release / build (macos-latest, darwin-arm64) (push) Has been cancelled
Release / build (windows-latest, windows-amd64) (push) Has been cancelled
Release / release (push) Has been cancelled
Some checks failed
Release / build (ubuntu-latest, linux-amd64) (push) Failing after 3m52s
Release / build (ubuntu-latest, linux-arm64) (push) Failing after 22s
Release / build (macos-latest, darwin-amd64) (push) Has been cancelled
Release / build (macos-latest, darwin-arm64) (push) Has been cancelled
Release / build (windows-latest, windows-amd64) (push) Has been cancelled
Release / release (push) Has been cancelled
- 使用 matrix 构建:ubuntu, macos, windows - 支持:linux-amd64, linux-arm64, darwin-amd64, darwin-arm64, windows-amd64 - 使用 actions/upload-artifact 上传构建产物 - 使用 gh release 创建 release
This commit is contained in:
135
.github/workflows/release.yml
vendored
135
.github/workflows/release.yml
vendored
@@ -7,94 +7,79 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
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:
|
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
|
- 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: |
|
run: |
|
||||||
. "$HOME/.cargo/env"
|
ext=""
|
||||||
cd /workspace/mimo-tts
|
[ "${{ matrix.target }}" = "windows-amd64" ] && ext=".exe"
|
||||||
|
|
||||||
# Linux x86_64
|
if [ "${{ matrix.target }}" = "linux-arm64" ]; then
|
||||||
cargo build --release -p mimo-tts
|
GOOS=linux GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-unknown-linux-gnu
|
||||||
mv target/release/mimo-tts mimo-tts-linux-amd64
|
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
|
mv target/release/mimo-tts "mimo-tts-${{ matrix.target }}${ext}"
|
||||||
GOOS=linux GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-unknown-linux-gnu
|
|
||||||
mv target/release/mimo-tts mimo-tts-linux-arm64
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
# macOS x86_64
|
with:
|
||||||
GOOS=darwin GOARCH=amd64 cargo build --release -p mimo-tts --target x86_64-apple-darwin
|
name: mimo-tts-${{ matrix.target }}
|
||||||
mv target/release/mimo-tts mimo-tts-darwin-amd64
|
path: mimo-tts-${{ matrix.target }}*
|
||||||
|
retention-days: 1
|
||||||
# macOS ARM64
|
|
||||||
GOOS=darwin GOARCH=arm64 cargo build --release -p mimo-tts --target aarch64-apple-darwin
|
release:
|
||||||
mv target/release/mimo-tts mimo-tts-darwin-arm64
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
# Windows x86_64
|
steps:
|
||||||
GOOS=windows GOARCH=amd64 cargo build --release -p mimo-tts --target x86_64-pc-windows-gnu
|
- name: Checkout code
|
||||||
mv target/release/mimo-tts.exe mimo-tts-windows-amd64.exe
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Download all artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
- name: Generate checksums
|
- name: Generate checksums
|
||||||
run: |
|
run: |
|
||||||
cd /workspace/mimo-tts
|
cd artifacts
|
||||||
sha256sum mimo-tts-* > checksums.txt
|
sha256sum mimo-tts-* > checksums.txt
|
||||||
|
|
||||||
- name: Create release
|
- name: Create release
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
GITEA_URL="https://hub.gaomia.site"
|
cd artifacts
|
||||||
REPO="titor/haibao-tts-cli"
|
|
||||||
|
|
||||||
cd /workspace/mimo-tts
|
|
||||||
COMMIT_MSG=$(git log -1 --format="%s" HEAD)
|
COMMIT_MSG=$(git log -1 --format="%s" HEAD)
|
||||||
|
|
||||||
TAG_NAME="latest"
|
# 使用 GitHub CLI 创建 release
|
||||||
|
gh release create latest \
|
||||||
# 删除已存在的 release(如果存在)
|
--title "Latest Release" \
|
||||||
curl -s -X DELETE "${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG_NAME}" \
|
--notes "$COMMIT_MSG" \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}"
|
mimo-tts-* checksums.txt
|
||||||
|
|
||||||
# 创建新 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
|
|
||||||
Reference in New Issue
Block a user