128 lines
4.1 KiB
YAML
128 lines
4.1 KiB
YAML
name: Build MIPS Binary
|
|
|
|
on:
|
|
push:
|
|
branches: [ "main" ]
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
env:
|
|
GIT_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
run: |
|
|
rm -rf .git
|
|
git init .
|
|
git remote add origin https://admin:${GIT_TOKEN}@git.karatatar.com/admin/vibetorrent.git
|
|
git fetch --depth=1 origin ${{ gitea.sha }}
|
|
git checkout FETCH_HEAD
|
|
|
|
- name: Setup Rust
|
|
run: |
|
|
if ! command -v rustup >/dev/null 2>&1; then
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
fi
|
|
. "$HOME/.cargo/env"
|
|
rustup toolchain install nightly --profile minimal
|
|
rustup default nightly
|
|
rustup target add wasm32-unknown-unknown
|
|
rustup component add rust-src
|
|
rustc --version
|
|
|
|
- name: Setup Node.js
|
|
run: |
|
|
if ! command -v node >/dev/null 2>&1 || [ "$(node -v | cut -d. -f1 | tr -d v)" -lt 20 ]; then
|
|
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
|
apt-get install -y -qq nodejs
|
|
fi
|
|
node -v
|
|
npm -v
|
|
|
|
- name: Install Trunk
|
|
run: |
|
|
. "$HOME/.cargo/env"
|
|
if ! command -v trunk &> /dev/null; then
|
|
cargo install trunk --locked
|
|
fi
|
|
|
|
- name: Build Frontend
|
|
run: |
|
|
. "$HOME/.cargo/env"
|
|
cd frontend
|
|
npm install
|
|
trunk build --release
|
|
|
|
- name: Build MIPS Builder Image
|
|
run: |
|
|
if ! docker image inspect vibetorrent-mips-builder >/dev/null 2>&1; then
|
|
docker build --platform linux/amd64 -t vibetorrent-mips-builder -f - . <<'DOCKERFILE'
|
|
FROM ghcr.io/cross-rs/mips-unknown-linux-musl:main
|
|
RUN apt-get update -qq && \
|
|
apt-get install -y -qq curl ca-certificates && \
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly --component rust-src && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
|
DOCKERFILE
|
|
fi
|
|
|
|
- name: Build Backend (MIPS)
|
|
run: |
|
|
docker run --rm \
|
|
-v "$PWD":/project \
|
|
-v cargo-mips-registry:/root/.cargo/registry \
|
|
-w /project/backend \
|
|
vibetorrent-mips-builder \
|
|
bash -c '
|
|
cargo build --target mips-unknown-linux-musl --release -Z build-std=std,panic_abort &&
|
|
file /project/target/mips-unknown-linux-musl/release/backend
|
|
'
|
|
|
|
- name: Rename Binary
|
|
run: mv target/mips-unknown-linux-musl/release/backend target/mips-unknown-linux-musl/release/vibetorrent-mips
|
|
|
|
- name: Generate Release Tag
|
|
id: tag
|
|
run: echo "release_tag=release-$(date +'%Y%m%d-%H%M')" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Create Release
|
|
env:
|
|
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
run: |
|
|
TAG="${{ steps.tag.outputs.release_tag }}"
|
|
REPO="admin/vibetorrent"
|
|
API_URL="${{ gitea.server_url }}/api/v1"
|
|
|
|
# Create release
|
|
RELEASE_RESPONSE=$(curl -s -X POST "${API_URL}/repos/${REPO}/releases" \
|
|
-H "Authorization: token ${RELEASE_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG}\",
|
|
\"name\": \"Release ${TAG}\",
|
|
\"body\": \"Automated build from commit ${{ gitea.sha }}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}")
|
|
|
|
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
|
|
echo "Release ID: $RELEASE_ID"
|
|
|
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release:"
|
|
echo "$RELEASE_RESPONSE"
|
|
exit 1
|
|
fi
|
|
|
|
# Upload binary as release asset
|
|
curl -s -X POST "${API_URL}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=vibetorrent-mips" \
|
|
-H "Authorization: token ${RELEASE_TOKEN}" \
|
|
-H "Content-Type: application/octet-stream" \
|
|
--data-binary @target/mips-unknown-linux-musl/release/vibetorrent-mips
|
|
|
|
echo "Release ${TAG} created with binary attached."
|