ci: 添加GitHub Actions CI/CD流水线

- CI: PR触发自动化测试(lint + type check + bun test)
- CD: push到main/tag触发Docker镜像构建并发布到GHCR
- 修复Dockerfile中bun.lockb→bun.lock引用
- 修复tsconfig.json排除测试文件避免dist中重复
- 修复file-review-store测试排序时间戳竞态
This commit is contained in:
accelerator
2026-03-01 14:47:22 +08:00
parent e91ebdc974
commit b4feb0a822
6 changed files with 120 additions and 4 deletions

31
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Lint
run: bun run lint
continue-on-error: true # Pre-existing lint violations — non-blocking until cleanup
- name: Type check
run: bun run build
- name: Run tests
run: bun test

81
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,81 @@
name: Release
on:
push:
branches:
- main
tags:
- 'v*'
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Lint
run: bun run lint
continue-on-error: true
- name: Type check
run: bun run build
- name: Run tests
run: bun test
docker:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -4,7 +4,7 @@ FROM oven/bun:1 as frontend-builder
WORKDIR /app/frontend
# 拷贝前端的 package.json 和 lockfile
COPY frontend/package.json frontend/bun.lockb ./
COPY frontend/package.json frontend/bun.lock* ./
# 安装前端依赖
RUN bun install --frozen-lockfile
@@ -22,7 +22,7 @@ FROM oven/bun:1 as backend-builder
WORKDIR /app
# 拷贝后端的 package.json 和 lockfile
COPY package.json bun.lockb ./
COPY package.json bun.lock* ./
# 只安装生产环境依赖
RUN bun install --frozen-lockfile --production

View File

@@ -1,6 +1,5 @@
{
"lockfileVersion": 1,
"configVersion": 0,
"workspaces": {
"": {
"name": "ai-review",

View File

@@ -351,7 +351,10 @@ describe('FileReviewStore', () => {
const p3 = makePRPayload();
await store.createOrReuseRun(p1);
// Ensure distinct timestamps for sorting
await new Promise(r => setTimeout(r, 5));
await store.createOrReuseRun(p2);
await new Promise(r => setTimeout(r, 5));
await store.createOrReuseRun(p3);
const runs = await store.listRuns();

View File

@@ -47,6 +47,8 @@
],
"exclude": [
"node_modules",
"dist"
"dist",
"src/**/__tests__/**",
"src/**/*.test.ts"
]
}