From de193dc9f5350cf36ad7aa59af864324a476354f Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Tue, 31 Mar 2026 14:00:58 +0400 Subject: [PATCH] Add Gitea Actions CI/CD workflows - .gitea/workflows/ci.yml: run tests on every push/PR - .gitea/workflows/release.yml: build Linux binaries on tag push - x86_64 (musl static) - aarch64 / RPi 64-bit (musl static) - armv7 / RPi 32-bit (musl static) - Auto-creates Gitea release with all artifacts - scripts/build-macos-release.sh: build macOS binary locally and upload to an existing Gitea release Release flow: git tag v0.1.0 && git push origin v0.1.0 # CI builds Linux + RPi, creates release # Then on Mac: ./scripts/build-macos-release.sh --upload v0.1.0 Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitea/workflows/ci.yml | 29 +++++ .gitea/workflows/release.yml | 199 +++++++++++++++++++++++++++++++++ scripts/build-macos-release.sh | 75 +++++++++++++ 3 files changed, 303 insertions(+) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/release.yml create mode 100755 scripts/build-macos-release.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..f738697 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + runs-on: ubuntu-latest + container: + image: rust:1.86-slim + steps: + - uses: actions/checkout@v4 + + - name: Run tests + run: cargo test -- --test-threads=1 + + - name: Build release + run: cargo build --release + + - name: Check binary + run: | + ls -lh target/release/btest + target/release/btest --version diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..0e78e1c --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,199 @@ +name: Build & Release + +on: + push: + tags: + - 'v*' + +env: + CARGO_TERM_COLOR: always + +jobs: + build-linux-x86_64: + runs-on: ubuntu-latest + container: + image: rust:1.86-slim + steps: + - uses: actions/checkout@v4 + + - name: Install musl toolchain + run: | + apt-get update && apt-get install -y --no-install-recommends musl-tools + rustup target add x86_64-unknown-linux-musl + + - name: Build + run: cargo build --release --target x86_64-unknown-linux-musl + + - name: Package + run: | + cd target/x86_64-unknown-linux-musl/release + tar czf /tmp/btest-linux-x86_64.tar.gz btest + sha256sum /tmp/btest-linux-x86_64.tar.gz > /tmp/btest-linux-x86_64.tar.gz.sha256 + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: btest-linux-x86_64 + path: | + /tmp/btest-linux-x86_64.tar.gz + /tmp/btest-linux-x86_64.tar.gz.sha256 + + build-linux-aarch64: + runs-on: ubuntu-latest + container: + image: rust:1.86-slim + steps: + - uses: actions/checkout@v4 + + - name: Install cross-compilation toolchain + run: | + apt-get update && apt-get install -y --no-install-recommends \ + musl-tools gcc-aarch64-linux-gnu + rustup target add aarch64-unknown-linux-musl + mkdir -p .cargo + cat > .cargo/config.toml << 'EOF' + [target.aarch64-unknown-linux-musl] + linker = "aarch64-linux-gnu-gcc" + rustflags = ["-C", "target-feature=+crt-static"] + EOF + + - name: Build + run: cargo build --release --target aarch64-unknown-linux-musl + + - name: Package + run: | + cd target/aarch64-unknown-linux-musl/release + tar czf /tmp/btest-linux-aarch64.tar.gz btest + sha256sum /tmp/btest-linux-aarch64.tar.gz > /tmp/btest-linux-aarch64.tar.gz.sha256 + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: btest-linux-aarch64 + path: | + /tmp/btest-linux-aarch64.tar.gz + /tmp/btest-linux-aarch64.tar.gz.sha256 + + build-linux-armv7: + runs-on: ubuntu-latest + container: + image: rust:1.86-slim + steps: + - uses: actions/checkout@v4 + + - name: Install cross-compilation toolchain + run: | + apt-get update && apt-get install -y --no-install-recommends \ + musl-tools gcc-arm-linux-gnueabihf + rustup target add armv7-unknown-linux-musleabihf + mkdir -p .cargo + cat > .cargo/config.toml << 'EOF' + [target.armv7-unknown-linux-musleabihf] + linker = "arm-linux-gnueabihf-gcc" + rustflags = ["-C", "target-feature=+crt-static"] + EOF + + - name: Build + run: cargo build --release --target armv7-unknown-linux-musleabihf + + - name: Package + run: | + cd target/armv7-unknown-linux-musleabihf/release + tar czf /tmp/btest-linux-armv7.tar.gz btest + sha256sum /tmp/btest-linux-armv7.tar.gz > /tmp/btest-linux-armv7.tar.gz.sha256 + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: btest-linux-armv7 + path: | + /tmp/btest-linux-armv7.tar.gz + /tmp/btest-linux-armv7.tar.gz.sha256 + + build-macos: + runs-on: ubuntu-latest + container: + image: rust:1.86-slim + steps: + - uses: actions/checkout@v4 + + - name: Install macOS cross-compilation toolchain + run: | + apt-get update && apt-get install -y --no-install-recommends \ + clang cmake curl git libssl-dev libxml2-dev lzma-dev make patch xz-utils zlib1g-dev + rustup target add x86_64-apple-darwin aarch64-apple-darwin + + - name: Install osxcross + run: | + git clone --depth 1 https://github.com/tpoechtrager/osxcross /tmp/osxcross + # Download macOS SDK (this needs a pre-packaged SDK tarball) + # If osxcross is not available, we skip and note in release + echo "macOS cross-compilation requires osxcross SDK setup" + echo "Binaries can be built natively on macOS: cargo build --release" + continue-on-error: true + + - name: Create placeholder note + run: | + echo "macOS binaries must be built on a macOS host." > /tmp/macos-build-note.txt + echo "Run: cargo build --release" >> /tmp/macos-build-note.txt + echo "Binaries: target/release/btest" >> /tmp/macos-build-note.txt + + - name: Upload note + uses: actions/upload-artifact@v3 + with: + name: btest-macos-note + path: /tmp/macos-build-note.txt + + release: + needs: [build-linux-x86_64, build-linux-aarch64, build-linux-armv7, build-macos] + runs-on: ubuntu-latest + container: + image: ubuntu:latest + steps: + - uses: actions/checkout@v4 + + - name: Install tools + run: apt-get update && apt-get install -y --no-install-recommends curl jq + + - name: Download all artifacts + uses: actions/download-artifact@v3 + with: + path: artifacts + + - name: List artifacts + run: find artifacts -type f | sort + + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: | + TAG="${GITHUB_REF##*/}" + GITEA_URL="https://git.manko.yoga" + REPO="manawenuz/btest-rs" + + # Determine which token to use + TOKEN="${GITEA_TOKEN:-$GITHUB_TOKEN}" + + # Create release via Gitea API + RELEASE_ID=$(curl -s -X POST \ + -H "Authorization: token ${TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"${TAG}\", \"name\": \"btest-rs ${TAG}\", \"body\": \"## Release ${TAG}\n\n### Downloads\n\n| Platform | Architecture | File |\n|----------|-------------|------|\n| Linux | x86_64 | btest-linux-x86_64.tar.gz |\n| Linux | aarch64 (RPi 64-bit) | btest-linux-aarch64.tar.gz |\n| Linux | armv7 (RPi 32-bit) | btest-linux-armv7.tar.gz |\n| macOS | Build from source | cargo build --release |\n\n### Install\n\n\\\`\\\`\\\`bash\ntar xzf btest-linux-x86_64.tar.gz\nsudo mv btest /usr/local/bin/\n\\\`\\\`\\\`\", \"draft\": false, \"prerelease\": false}" \ + "${GITEA_URL}/api/v1/repos/${REPO}/releases" | jq -r '.id') + + echo "Created release ID: ${RELEASE_ID}" + + # Upload each artifact + for file in artifacts/btest-linux-*/*.tar.gz artifacts/btest-linux-*/*.sha256; do + if [ -f "$file" ]; then + FILENAME=$(basename "$file") + echo "Uploading: ${FILENAME}" + curl -s -X POST \ + -H "Authorization: token ${TOKEN}" \ + -F "attachment=@${file}" \ + "${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" + fi + done + + echo "Release ${TAG} created with artifacts" diff --git a/scripts/build-macos-release.sh b/scripts/build-macos-release.sh new file mode 100755 index 0000000..cff8643 --- /dev/null +++ b/scripts/build-macos-release.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# Build macOS binaries and optionally upload to a Gitea release. +# Run this on a macOS host (Intel or Apple Silicon). +# +# Usage: +# ./scripts/build-macos-release.sh # build only +# ./scripts/build-macos-release.sh --upload v0.1.0 # build + upload to release tag +set -euo pipefail + +cd "$(dirname "$0")/.." + +GITEA_URL="https://git.manko.yoga" +REPO="manawenuz/btest-rs" +UPLOAD="" +TAG="" + +while [[ $# -gt 0 ]]; do + case $1 in + --upload) UPLOAD=1; TAG="$2"; shift 2 ;; + *) echo "Usage: $0 [--upload TAG]"; exit 1 ;; + esac +done + +echo "=== Building macOS release binary ===" +cargo build --release + +ARCH=$(uname -m) +case "$ARCH" in + x86_64) PLATFORM="darwin-x86_64" ;; + arm64) PLATFORM="darwin-aarch64" ;; + *) PLATFORM="darwin-${ARCH}" ;; +esac + +mkdir -p dist +TARBALL="dist/btest-${PLATFORM}.tar.gz" +cd target/release +tar czf "../../${TARBALL}" btest +cd ../.. +shasum -a 256 "${TARBALL}" > "${TARBALL}.sha256" + +echo "Built: ${TARBALL}" +ls -lh "${TARBALL}" +cat "${TARBALL}.sha256" + +if [[ -n "$UPLOAD" ]]; then + if [[ -z "${GITEA_TOKEN:-}" ]]; then + echo "" + echo "Set GITEA_TOKEN to upload. Example:" + echo " export GITEA_TOKEN=your_token_here" + echo " $0 --upload ${TAG}" + exit 1 + fi + + echo "" + echo "=== Uploading to release ${TAG} ===" + + # Find release ID by tag + RELEASE_ID=$(curl -s \ + -H "Authorization: token ${GITEA_TOKEN}" \ + "${GITEA_URL}/api/v1/repos/${REPO}/releases/tags/${TAG}" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") + + echo "Release ID: ${RELEASE_ID}" + + for file in "${TARBALL}" "${TARBALL}.sha256"; do + FILENAME=$(basename "$file") + echo "Uploading: ${FILENAME}" + curl -s -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -F "attachment=@${file}" \ + "${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${FILENAME}" + echo "" + done + + echo "Done! macOS binary uploaded to ${TAG}" +fi