ci: add Gitea Actions workflows

This commit is contained in:
2026-06-11 23:22:08 +08:00
parent 6f415428d3
commit 052da457eb
5 changed files with 441 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
name: Docker Build
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag name to build (e.g., v0.10.8)'
required: true
type: string
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: act-runner-4c6g
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve tag & write VERSION
id: 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
echo "${TAG}" > VERSION
echo "Building tag: ${TAG}"
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.PACKAGES_TOKEN }}" | docker login git.viaeon.com -u "${{ github.actor }}" --password-stdin 2>&1
- name: Build Docker image
run: |
echo "Building image..."
docker build \
--label "org.opencontainers.image.source=https://git.viaeon.com/admin/new-api" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
-t git.viaeon.com/admin/new-api:${{ env.TAG }} \
-t git.viaeon.com/admin/new-api:latest . 2>&1
- name: Push Docker image
run: |
echo "Pushing ${{ env.TAG }}..."
docker push git.viaeon.com/admin/new-api:${{ env.TAG }} 2>&1
echo "Pushing latest..."
docker push git.viaeon.com/admin/new-api:latest 2>&1
+63
View File
@@ -0,0 +1,63 @@
name: Docker Build (alpha)
on:
push:
branches:
- alpha
workflow_dispatch:
jobs:
build-and-push:
name: Build and Push Alpha Docker Image
runs-on: act-runner-4c6g
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Determine alpha version
id: version
run: |
VERSION="alpha-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
echo "$VERSION" > VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Publishing version: $VERSION"
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.PACKAGES_TOKEN }}" | docker login git.viaeon.com -u "${{ github.actor }}" --password-stdin 2>&1
- name: Build Docker image
run: |
echo "Building alpha image..."
docker build \
--label "org.opencontainers.image.source=https://git.viaeon.com/admin/new-api" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
-t git.viaeon.com/admin/new-api:${{ env.VERSION }} \
-t git.viaeon.com/admin/new-api:alpha . 2>&1
- name: Push Docker image
run: |
echo "Pushing ${{ env.VERSION }}..."
docker push git.viaeon.com/admin/new-api:${{ env.VERSION }} 2>&1
echo "Pushing alpha..."
docker push git.viaeon.com/admin/new-api:alpha 2>&1
@@ -0,0 +1,63 @@
name: Docker Build (nightly)
on:
push:
branches:
- nightly
workflow_dispatch:
jobs:
build-and-push:
name: Build and Push Nightly Docker Image
runs-on: act-runner-4c6g
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Install Docker CLI
run: |
if ! command -v docker &> /dev/null; then
if command -v apk &> /dev/null; then
apk add --no-cache docker-cli
elif command -v apt-get &> /dev/null; then
apt-get update && apt-get install -y docker.io
else
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz | tar xz -C /tmp
mv /tmp/docker/docker /usr/local/bin/
chmod +x /usr/local/bin/docker
fi
fi
docker --version
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Determine nightly version
id: version
run: |
VERSION="nightly-$(date +'%Y%m%d')-$(git rev-parse --short HEAD)"
echo "$VERSION" > VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Publishing version: $VERSION"
- name: Login to Gitea Container Registry
run: |
echo "${{ secrets.PACKAGES_TOKEN }}" | docker login git.viaeon.com -u "${{ github.actor }}" --password-stdin 2>&1
- name: Build Docker image
run: |
echo "Building nightly image..."
docker build \
--label "org.opencontainers.image.source=https://git.viaeon.com/admin/new-api" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
-t git.viaeon.com/admin/new-api:${{ env.VERSION }} \
-t git.viaeon.com/admin/new-api:nightly . 2>&1
- name: Push Docker image
run: |
echo "Pushing ${{ env.VERSION }}..."
docker push git.viaeon.com/admin/new-api:${{ env.VERSION }} 2>&1
echo "Pushing nightly..."
docker push git.viaeon.com/admin/new-api:nightly 2>&1
+82
View File
@@ -0,0 +1,82 @@
name: PR Check
on:
pull_request:
types: [opened, reopened]
jobs:
pr-quality:
name: PR Quality Check
runs-on: act-runner-4c6g
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check PR description
env:
GITEA_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: admin/new-api
GITEA_URL: https://git.viaeon.com
run: |
# 获取 PR 信息
PR_INFO=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
"${GITEA_URL}/api/v1/repos/${REPO}/pulls/${PR_NUMBER}")
PR_BODY=$(echo "$PR_INFO" | jq -r '.body // empty')
PR_TITLE=$(echo "$PR_INFO" | jq -r '.title // empty')
PR_USER=$(echo "$PR_INFO" | jq -r '.user.login // empty')
FAILED=0
REASONS=""
# 检查 PR 描述是否为空
if [ -z "$PR_BODY" ] || [ "$PR_BODY" = "null" ]; then
FAILED=1
REASONS="${REASONS}- PR description is empty\n"
fi
# 检查 PR 标题是否为空
if [ -z "$PR_TITLE" ] || [ "$PR_TITLE" = "null" ]; then
FAILED=1
REASONS="${REASONS}- PR title is empty\n"
fi
# 检查是否包含纯 AI 生成标记
if echo "$PR_BODY" | grep -qi "Generated with Claude Code"; then
FAILED=1
REASONS="${REASONS}- PR appears to be purely AI-generated without meaningful human involvement\n"
fi
if [ "$FAILED" -eq 1 ]; then
echo "PR check failed:"
echo -e "$REASONS"
# 添加标签
curl -s -X POST \
"${GITEA_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/labels" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"labels": ["pr-check-failed"]}'
# 添加评论
curl -s -X POST \
"${GITEA_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"body": "感谢您的提交。由于该 PR 未遵循我们的贡献模板,且被识别为缺乏人工参与的纯 AI 生成内容,我们将先予以关闭。我们更欢迎经过人工审核、验证并带有个人思考的贡献。如果您认为这其中存在误解,请回复告知。"}'
# 关闭 PR
curl -s -X PATCH \
"${GITEA_URL}/api/v1/repos/${REPO}/pulls/${PR_NUMBER}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d '{"state": "closed"}'
exit 1
fi
echo "PR check passed!"
+161
View File
@@ -0,0 +1,161 @@
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!"