162 lines
4.7 KiB
YAML
162 lines
4.7 KiB
YAML
name: Release (Linux)
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
- '!*-alpha*'
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: 'Tag name to build (e.g., v0.10.8)'
|
|
required: true
|
|
type: string
|
|
|
|
jobs:
|
|
build-linux:
|
|
name: Linux Release
|
|
runs-on: act-runner-4c6g
|
|
env:
|
|
RUNNER_TOOL_CACHE: /toolcache
|
|
|
|
steps:
|
|
- name: Install dependencies
|
|
run: |
|
|
export PATH="/toolcache/bin:$PATH"
|
|
# Install Go
|
|
if ! command -v go &> /dev/null; then
|
|
curl -fsSL https://go.dev/dl/go1.25.1.linux-amd64.tar.gz | tar -C /usr/local -xzf -
|
|
echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
|
|
export PATH=$PATH:/usr/local/go/bin
|
|
fi
|
|
go version
|
|
# Install Bun
|
|
if ! command -v bun &> /dev/null; then
|
|
curl -fsSL https://bun.sh/install | bash
|
|
export PATH="$HOME/.bun/bin:$PATH"
|
|
fi
|
|
bun --version
|
|
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Determine Version
|
|
run: |
|
|
if [ -n "${{ github.event.inputs.tag }}" ]; then
|
|
TAG="${{ github.event.inputs.tag }}"
|
|
else
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
fi
|
|
VERSION=$(git describe --tags 2>/dev/null || echo "$TAG")
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
echo "Building version: $VERSION"
|
|
|
|
- name: Build Frontend (default)
|
|
env:
|
|
CI: ""
|
|
run: |
|
|
export PATH="$HOME/.bun/bin:/usr/local/go/bin:$PATH"
|
|
cd web
|
|
bun install --frozen-lockfile
|
|
cd default
|
|
DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$VERSION bun run build
|
|
cd ../..
|
|
|
|
- name: Build Frontend (classic)
|
|
env:
|
|
CI: ""
|
|
run: |
|
|
export PATH="$HOME/.bun/bin:/usr/local/go/bin:$PATH"
|
|
cd web
|
|
bun install --frozen-lockfile
|
|
cd classic
|
|
VITE_REACT_APP_VERSION=$VERSION bun run build
|
|
cd ../..
|
|
|
|
- name: Build Backend (amd64)
|
|
run: |
|
|
export PATH="/usr/local/go/bin:$PATH"
|
|
go mod download
|
|
go build -ldflags "-s -w -X 'new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-$VERSION
|
|
|
|
- name: Build Backend (arm64)
|
|
run: |
|
|
export PATH="/usr/local/go/bin:$PATH"
|
|
sudo apt-get update
|
|
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y gcc-aarch64-linux-gnu
|
|
CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X 'new-api/common.Version=$VERSION' -extldflags '-static'" -o new-api-arm64-$VERSION
|
|
|
|
- name: Generate checksums
|
|
run: sha256sum new-api-* > checksums-linux.txt
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: linux-build
|
|
path: |
|
|
new-api-*
|
|
checksums-linux.txt
|
|
|
|
release:
|
|
name: Create Gitea Release
|
|
needs: [build-linux]
|
|
runs-on: act-runner-4c6g
|
|
env:
|
|
RUNNER_TOOL_CACHE: /toolcache
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Determine Version
|
|
run: |
|
|
if [ -n "${{ github.event.inputs.tag }}" ]; then
|
|
TAG="${{ github.event.inputs.tag }}"
|
|
else
|
|
TAG=${GITHUB_REF#refs/tags/}
|
|
fi
|
|
echo "TAG=$TAG" >> $GITHUB_ENV
|
|
|
|
- name: Download artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: artifacts
|
|
|
|
- name: Create Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
|
|
run: |
|
|
# 使用 Gitea API 创建 Release
|
|
TAG="${{ env.TAG }}"
|
|
REPO="admin/new-api"
|
|
GITEA_URL="https://git.viaeon.com"
|
|
|
|
# 创建 Release
|
|
RELEASE_ID=$(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\": \"${TAG}\",
|
|
\"body\": \"Release ${TAG}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}" | jq -r '.id')
|
|
|
|
echo "Created release ID: ${RELEASE_ID}"
|
|
|
|
# 上传附件
|
|
find artifacts -type f | while read file; do
|
|
echo "Uploading: ${file}"
|
|
curl -s -X POST \
|
|
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${file}" \
|
|
-F "name=$(basename ${file})"
|
|
done
|
|
|
|
echo "Release ${TAG} created successfully!"
|