143 lines
3.5 KiB
YAML
143 lines
3.5 KiB
YAML
name: Pull Request 质量门禁
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
- dev
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: ci-${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
go:
|
|
name: Go 检查
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 检查格式
|
|
shell: bash
|
|
run: |
|
|
set -Eeuo pipefail
|
|
if [ -n "$(gofmt -l .)" ]; then
|
|
echo "发现未格式化的 Go 文件,请先运行 gofmt -w。" >&2
|
|
gofmt -l .
|
|
exit 1
|
|
fi
|
|
|
|
- name: 检查中文注释
|
|
run: go run ./tools/commentlint -mode check -root .
|
|
|
|
- name: 检查架构依赖
|
|
run: go run ./tools/architecturecheck
|
|
|
|
- name: 运行 go vet
|
|
run: go vet ./...
|
|
|
|
- name: 运行 golangci-lint
|
|
uses: golangci/golangci-lint-action@v8
|
|
with:
|
|
version: v2.1
|
|
args: ./...
|
|
|
|
- name: 运行 Go 测试
|
|
run: go test ./...
|
|
|
|
- name: 运行 server 并发 smoke race
|
|
run: make test-server-race
|
|
|
|
frontend:
|
|
name: React 前端检查
|
|
runs-on: ubuntu-24.04
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Node.js
|
|
uses: actions/setup-node@v6
|
|
with:
|
|
node-version: 24
|
|
cache: npm
|
|
cache-dependency-path: frontend/package-lock.json
|
|
|
|
- name: 安装前端依赖
|
|
run: npm ci --prefix frontend
|
|
|
|
- name: 检查中文注释
|
|
run: npm run comments:check --prefix frontend
|
|
|
|
- name: 检查 TypeScript 类型
|
|
run: npm run typecheck --prefix frontend
|
|
|
|
- name: 运行前端测试
|
|
run: npm test --prefix frontend
|
|
|
|
- name: 构建并校验嵌入式前端产物
|
|
shell: bash
|
|
run: |
|
|
set -Eeuo pipefail
|
|
npm run build --prefix frontend
|
|
git diff --exit-code -- internal/webui/static
|
|
|
|
multidb:
|
|
name: MySQL/PostgreSQL 多数据库回归
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 20
|
|
services:
|
|
mysql:
|
|
image: mysql:8.4
|
|
env:
|
|
MYSQL_ROOT_PASSWORD: test-root-password
|
|
MYSQL_ROOT_HOST: "%"
|
|
MYSQL_DATABASE: xianyu
|
|
TZ: UTC
|
|
ports:
|
|
- "3306:3306"
|
|
options: >-
|
|
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -ptest-root-password --silent"
|
|
--health-interval=5s
|
|
--health-timeout=5s
|
|
--health-retries=30
|
|
postgres:
|
|
image: postgres:17
|
|
env:
|
|
POSTGRES_DB: xianyu
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: test-postgres-password
|
|
TZ: UTC
|
|
ports:
|
|
- "5432:5432"
|
|
options: >-
|
|
--health-cmd="pg_isready -U postgres -d xianyu"
|
|
--health-interval=5s
|
|
--health-timeout=5s
|
|
--health-retries=30
|
|
env:
|
|
TEST_MYSQL_URL: "mysql://root:test-root-password@tcp(127.0.0.1:3306)/xianyu?parseTime=true&loc=UTC"
|
|
TEST_POSTGRES_URL: "postgres://postgres:test-postgres-password@127.0.0.1:5432/xianyu?sslmode=disable&timezone=UTC"
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v6
|
|
|
|
- name: 配置 Go
|
|
uses: actions/setup-go@v7
|
|
with:
|
|
go-version-file: go.mod
|
|
cache: true
|
|
|
|
- name: 执行三方言实测回归
|
|
run: make test-multidb
|