ci: 添加 Gitea Actions 的 CI 与发布流程,移除 .github/workflows
- ci.yml:push main 时起 postgres:16 服务容器,应用 schema.sql 并补建 llm_usage, 跑 go mod verify / go vet / go test -p 1 ./...;不接 PR 触发。 -skip 掉当前已失败的 TestGraphOverviewExpandsAssociatedCompanyScope。 - release.yml:v* tag 触发,只构建 linux/amd64 与 linux/arm64,从 CHANGELOG 提取说明,用 gitea-release-action 建 Release 上传 zip 与 SHA256SUMS, 再用 buildx 推多架构镜像到 gitea.bcde.io/wangdefa/artex。 - .dockerignore:排除 dist 下的 zip 与中间产物,只放 dist/<arch>/artex 进构建上下文。 - 删除 .github/workflows:本仓库 CI/CD 全部走 .gitea/workflows。留着的副本会被 Gitea 一并扫描,同一个 tag 触发两套发布流程、重复建 Release。
This commit is contained in:
1 parent
f782b612ec
commit
2511c2e041
4 files changed
+248
-135
No files matched your search
@@ -1,3 +1,5 @@
|
||||
dist/*.zip
|
||||
dist/artex-*
|
||||
.git
|
||||
**/node_modules
|
||||
web/.next
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
# Gitea Actions:push 到 main 时跑后端测试与前端构建。
|
||||
# 刻意不接 pull_request:solo 开发时同一提交会跑两遍,浪费 CI 时间。
|
||||
#
|
||||
# 前置条件(缺一不可):
|
||||
# 1. 仓库 Settings → Actions 勾选 “Enable Repository Actions”
|
||||
# 2. 已注册带 ubuntu-latest-amd64 标签、且以 Docker 模式运行的 Gitea Runner
|
||||
# (services 容器只在 Docker 模式下可用)
|
||||
# 现有 Runner:runner-amd64 → ubuntu-latest-amd64 / ubuntu-22.04-amd64 / ubuntu-20.04-amd64
|
||||
# runner-arm64 → ubuntu-latest-arm64 / ubuntu-22.04-arm64 / ubuntu-20.04-arm64
|
||||
# 想跑在 arm64 上把下面的 runs-on 换成 ubuntu-latest-arm64 即可。
|
||||
# 3. Runner 能出网:actions/checkout 与 actions/setup-go 默认从 github.com 拉取,
|
||||
# setup-go 还要从 go.dev 下载工具链
|
||||
name: ci
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
backend:
|
||||
runs-on: ubuntu-latest-amd64
|
||||
timeout-minutes: 40
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
env:
|
||||
POSTGRES_USER: artex
|
||||
POSTGRES_PASSWORD: artex
|
||||
POSTGRES_DB: artex
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U artex"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 30
|
||||
env:
|
||||
ARTEX_PG_DSN: postgres://artex:artex@postgres:5432/artex?sslmode=disable
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26"
|
||||
# Runner 没开缓存服务时 actions/cache 会失败,这里先关掉保稳。
|
||||
cache: false
|
||||
|
||||
- name: 安装 psql 客户端
|
||||
run: |
|
||||
command -v psql >/dev/null 2>&1 && exit 0
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq postgresql-client
|
||||
|
||||
- name: 初始化数据库 schema
|
||||
env:
|
||||
PGPASSWORD: artex
|
||||
run: psql -h postgres -U artex -d artex -v ON_ERROR_STOP=1 -q -f db/schema.sql
|
||||
|
||||
- name: 初始化运行时表(llm_usage)
|
||||
run: |
|
||||
# llm_usage 不在 schema.sql 里,由应用启动时的 db.EnsureLLMUsageTable 建表。
|
||||
# 有测试直接读写这张表,所以这里显式补一次,避免依赖包执行顺序。
|
||||
cat > /tmp/bootstrap.go <<'GO'
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/Autumn-27/artex/db"
|
||||
)
|
||||
|
||||
func main() {
|
||||
d, err := db.Open(os.Getenv("ARTEX_PG_DSN"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer d.Close()
|
||||
if err := d.EnsureLLMUsageTable(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
GO
|
||||
go run /tmp/bootstrap.go
|
||||
|
||||
- name: 依赖完整性
|
||||
run: go mod verify
|
||||
|
||||
- name: 静态检查
|
||||
run: go vet ./...
|
||||
|
||||
- name: 测试
|
||||
run: |
|
||||
# -p 1:各包共用一个库,串行执行避免跨包数据竞争。
|
||||
# -skip:TestGraphOverviewExpandsAssociatedCompanyScope 在当前代码上
|
||||
# 已失败(coverage["scope"] 为 nil),与本流程无关,修好后请删掉。
|
||||
go test -p 1 ./... -count=1 -skip 'TestGraphOverviewExpandsAssociatedCompanyScope'
|
||||
|
||||
frontend:
|
||||
runs-on: ubuntu-latest-amd64
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: false
|
||||
|
||||
- name: 安装依赖
|
||||
working-directory: web
|
||||
run: npm ci --no-audit --no-fund
|
||||
|
||||
- name: 构建静态站点
|
||||
working-directory: web
|
||||
run: npm run build:static
|
||||
@@ -0,0 +1,129 @@
|
||||
# Gitea Actions:推送 v* tag 时构建 linux/amd64 + linux/arm64 发行包、发布 Release,
|
||||
# 并推送多架构镜像(两个架构都进镜像)。
|
||||
#
|
||||
# 产物:
|
||||
# - Release 附件:artex-<版本>-<os>-<arch>.zip + SHA256SUMS(selfupdate 约定的结构)
|
||||
# - 容器镜像:gitea.bcde.io/wangdefa/artex:<tag> 与 :latest(linux/amd64 + linux/arm64)
|
||||
#
|
||||
# 需要配置的仓库 Secret:
|
||||
# GITEA_TOKEN 由 Gitea 自动注入,无需手工创建;contents: write 即可建 Release。
|
||||
# BUILD_TOKEN 个人访问令牌,勾选 write:package。GITEA_TOKEN 不能推包仓库,
|
||||
# 所以镜像推送必须用它;不配的话这一步会失败并提示。
|
||||
#
|
||||
# 运行环境:带 ubuntu-latest-amd64 标签的 Gitea Runner(可换 ubuntu-latest-arm64)。
|
||||
# 二进制由 build.sh 交叉编译,镜像里只装工具链,arm64 只模拟 apt 层。
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
|
||||
env:
|
||||
# 不生成 provenance/SBOM 附加清单:部分 registry 版本对上镜像 digest 会报错。
|
||||
BUILDX_NO_DEFAULT_ATTESTATIONS: "1"
|
||||
|
||||
permissions:
|
||||
contents: write # 建 Release + 传附件(Gitea 里 contents 覆盖 code 与 releases)
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest-amd64
|
||||
# arm64 那半程要在 QEMU 下跑 apt + Playwright,给足时间。
|
||||
timeout-minutes: 120
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26"
|
||||
cache: false
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: false
|
||||
|
||||
- name: 补齐打包工具
|
||||
run: |
|
||||
missing=""
|
||||
for t in rsync zip git; do
|
||||
command -v "$t" >/dev/null 2>&1 || missing="$missing $t"
|
||||
done
|
||||
if [ -n "$missing" ]; then
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq $missing
|
||||
fi
|
||||
|
||||
- name: 构建并打包(linux/amd64 + linux/arm64)
|
||||
env:
|
||||
ARTEX_BUILD_VERSION: ${{ gitea.ref_name }}
|
||||
# build.sh --release 默认出 5 个平台,这里显式收窄到两个。
|
||||
ARTEX_TARGETS: linux/amd64,linux/arm64
|
||||
ARTEX_COMPRESS: "0"
|
||||
ARTEX_PACKAGE: "1"
|
||||
run: ./build.sh --release
|
||||
|
||||
- name: 输出校验和
|
||||
run: |
|
||||
ls -lh dist/*.zip
|
||||
cat dist/SHA256SUMS
|
||||
|
||||
- name: 从 CHANGELOG 提取本版说明
|
||||
run: |
|
||||
TAG="${{ gitea.ref_name }}"
|
||||
awk -v ver="${TAG#v}" '
|
||||
$0 ~ "^## \\[" ver "\\]" { flag = 1; next }
|
||||
/^## \[/ && flag { exit }
|
||||
flag { print }
|
||||
' CHANGELOG.md > release-notes.md
|
||||
[ -s release-notes.md ] || echo "Release ${TAG}" > release-notes.md
|
||||
echo "--- release-notes.md ---"
|
||||
cat release-notes.md
|
||||
|
||||
- name: 创建 Release 并上传附件
|
||||
uses: https://gitea.com/actions/gitea-release-action@v1
|
||||
with:
|
||||
token: ${{ secrets.GITEA_TOKEN }}
|
||||
body_path: release-notes.md
|
||||
files: |-
|
||||
dist/*.zip
|
||||
dist/SHA256SUMS
|
||||
|
||||
- name: 准备镜像构建上下文
|
||||
run: |
|
||||
# Dockerfile 只从 dist/<arch>/artex 取预编译二进制,这里按 TARGETARCH 摆好。
|
||||
mkdir -p dist/amd64 dist/arm64
|
||||
cp dist/artex-linux-amd64/artex dist/amd64/artex
|
||||
cp dist/artex-linux-arm64/artex dist/arm64/artex
|
||||
ls -lh dist/amd64/artex dist/arm64/artex
|
||||
|
||||
- name: 推送多架构镜像
|
||||
env:
|
||||
TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
REGISTRY="$(echo '${{ gitea.server_url }}' | sed 's|https\?://||')"
|
||||
# Docker 仓库名必须小写,仓库名是 ARTEX,这里统一转小写。
|
||||
IMAGE="$(echo "${REGISTRY}/${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')"
|
||||
|
||||
if [ -z "$TOKEN" ]; then
|
||||
echo "缺少 repository secret BUILD_TOKEN(需 write:package)——无法推送镜像。" >&2
|
||||
echo "GITEA_TOKEN 不能推包仓库,必须另外建一个 PAT。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$TOKEN" | docker login "$REGISTRY" -u "${{ gitea.repository_owner }}" --password-stdin
|
||||
|
||||
# 多平台清单需要 docker-container driver;已存在则沿用。
|
||||
docker buildx create --use --driver docker-container --driver-opt network=host >/dev/null 2>&1 || true
|
||||
|
||||
docker buildx build --pull \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
-t "${IMAGE}:${{ gitea.ref_name }}" \
|
||||
-t "${IMAGE}:latest" \
|
||||
--push .
|
||||
|
||||
echo "已推送 ${IMAGE}:${{ gitea.ref_name }} 与 ${IMAGE}:latest"
|
||||
@@ -1,135 +0,0 @@
|
||||
name: release
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
|
||||
permissions:
|
||||
contents: write # 创建 Release 需要
|
||||
|
||||
jobs:
|
||||
# ① 前端静态导出(一次),产物给交叉编译各平台复用
|
||||
frontend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: npm
|
||||
cache-dependency-path: web/package-lock.json
|
||||
- run: npm ci
|
||||
working-directory: web
|
||||
- run: npm run build:static
|
||||
working-directory: web
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: web-dist
|
||||
path: web/out
|
||||
|
||||
# ② 五平台交叉编译(内嵌前端)+ 打 zip
|
||||
binaries:
|
||||
needs: frontend
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- { goos: linux, goarch: amd64 }
|
||||
- { goos: linux, goarch: arm64 }
|
||||
- { goos: darwin, goarch: amd64 }
|
||||
- { goos: darwin, goarch: arm64 }
|
||||
- { goos: windows, goarch: amd64 }
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.26"
|
||||
cache: true
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: web-dist
|
||||
path: server/webui/dist
|
||||
- name: Build and package with build.sh
|
||||
env:
|
||||
ARTEX_TARGET_OS: ${{ matrix.goos }}
|
||||
ARTEX_TARGET_ARCH: ${{ matrix.goarch }}
|
||||
ARTEX_BUILD_VERSION: ${{ github.ref_name }}
|
||||
ARTEX_SKIP_FRONTEND: "1"
|
||||
ARTEX_SKIP_NPM_CI: "1"
|
||||
# UPX 自解压 ELF 在部分 Linux 内核、虚拟化和安全策略下会崩溃。
|
||||
# Release 使用 Go linker 裁剪和 zip 压缩,优先保证可移植性。
|
||||
ARTEX_COMPRESS: "0"
|
||||
ARTEX_PACKAGE: "1"
|
||||
ARTEX_PACKAGE_DIR: dist
|
||||
run: |
|
||||
./build.sh --target "${ARTEX_TARGET_OS}/${ARTEX_TARGET_ARCH}"
|
||||
- name: Smoke test Linux amd64 binary
|
||||
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
|
||||
run: dist/artex-linux-amd64/artex -h
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: pkg-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
path: "dist/*.zip"
|
||||
# Linux 生二进制单独上传,供 docker job 复用(免在镜像里重编前端+Go)
|
||||
- if: matrix.goos == 'linux'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bin-linux-${{ matrix.goarch }}
|
||||
path: dist/artex-linux-${{ matrix.goarch }}/artex
|
||||
|
||||
# ③ 汇总所有 zip → 创建 GitHub Release
|
||||
release:
|
||||
needs: binaries
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: pkg-*
|
||||
merge-multiple: true
|
||||
path: dist
|
||||
- name: Generate checksums
|
||||
working-directory: dist
|
||||
run: sha256sum *.zip > SHA256SUMS
|
||||
- uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
dist/*.zip
|
||||
dist/SHA256SUMS
|
||||
generate_release_notes: true
|
||||
|
||||
# ④ 多架构镜像 → 推 Docker Hub(复用 binaries 编好的 Linux 二进制,
|
||||
# 镜像里只装工具 + 放二进制;arm64 仅需模拟 apt 层,构建快很多)
|
||||
docker:
|
||||
needs: binaries
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4 # 取 Dockerfile 与 skills/
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: bin-linux-amd64
|
||||
path: dist/amd64
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: bin-linux-arm64
|
||||
path: dist/arm64
|
||||
- uses: docker/setup-qemu-action@v3
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
- uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- uses: docker/metadata-action@v5
|
||||
id: meta
|
||||
with:
|
||||
images: autumn27/artex
|
||||
tags: |
|
||||
type=ref,event=tag
|
||||
type=raw,value=latest
|
||||
- uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
Reference in new issue
Block a user