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:
129
.github/workflows/release.yml
vendored
129
.github/workflows/release.yml
vendored
@@ -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
|
||||
mv target/release/mimo-tts "mimo-tts-${{ matrix.target }}${ext}"
|
||||
|
||||
# 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
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: mimo-tts-${{ matrix.target }}
|
||||
path: mimo-tts-${{ matrix.target }}*
|
||||
retention-days: 1
|
||||
|
||||
# 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
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# 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
|
||||
- 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
|
||||
# 使用 GitHub CLI 创建 release
|
||||
gh release create latest \
|
||||
--title "Latest Release" \
|
||||
--notes "$COMMIT_MSG" \
|
||||
mimo-tts-* checksums.txt
|
||||
Reference in New Issue
Block a user