Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 14 additions & 5 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,29 @@ uv run ruff check . --exclude "code/" --force-exclude
echo -e "${YELLOW}📝 Python: mypy${NC}"
uv run mypy . --exclude "code/"

if printf '%s\n' "$STAGED" | grep -Eq '^(apps/undefined-console/|src/Undefined/webui/static/js/|biome\.json$|\.github/workflows/(ci|release)\.yml$)'; then
if printf '%s\n' "$STAGED" | grep -Eq '^(apps/undefined-console/|apps/undefined-chat/|src/Undefined/webui/static/js/|biome\.json$|\.github/workflows/(ci|release)\.yml$)'; then
echo -e "${YELLOW}📝 检测到 JS/Tauri 相关改动,运行前端与 Tauri 检查...${NC}"

if ! command -v npm >/dev/null 2>&1; then
echo -e "${RED}❌ 未找到 npm,请先安装 Node.js${NC}"
exit 1
fi

if [ ! -x "apps/undefined-console/node_modules/.bin/biome" ]; then
echo -e "${RED}❌ 缺少 apps/undefined-console/node_modules,请先运行 cd apps/undefined-console && npm install${NC}"
exit 1
APP_CHECKS=()
if printf '%s\n' "$STAGED" | grep -Eq '^(apps/undefined-console/|src/Undefined/webui/static/js/|biome\.json$|\.github/workflows/(ci|release)\.yml$)'; then
APP_CHECKS+=("apps/undefined-console")
fi
if printf '%s\n' "$STAGED" | grep -Eq '^(apps/undefined-chat/|\.github/workflows/(ci|release)\.yml$)'; then
APP_CHECKS+=("apps/undefined-chat")
fi

npm --prefix apps/undefined-console run check
for app_dir in "${APP_CHECKS[@]}"; do
if [ ! -x "$app_dir/node_modules/.bin/biome" ]; then
echo -e "${RED}❌ 缺少 $app_dir/node_modules,请先运行 cd $app_dir && npm install${NC}"
exit 1
fi
npm --prefix "$app_dir" run check
done
fi

echo -e "${GREEN}✅ pre-commit 检查通过${NC}"
27 changes: 10 additions & 17 deletions .githooks/pre-tag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
set -euo pipefail

TAG_NAME="${1:-}"
TAG_VERSION="${TAG_NAME#v}"

RED='\033[0;31m'
GREEN='\033[0;32m'
Expand All @@ -11,23 +10,17 @@ NC='\033[0m'

cd "$(git rev-parse --show-toplevel)"

get_pyproject_version() {
grep -E '^version = ' pyproject.toml | sed -E 's/version = "([^"]+)"/\1/'
}

get_init_version() {
grep -E '^__version__' src/Undefined/__init__.py | sed -E "s/__version__ = '([^']+)'/\1/" | sed -E 's/__version__ = "([^"]+)"/\1/'
}

PYPROJECT_VERSION=$(get_pyproject_version)
INIT_VERSION=$(get_init_version)
if [ -z "$TAG_NAME" ]; then
echo -e "${RED}❌ 缺少 tag 名称${NC}"
exit 1
fi

if [ "$TAG_VERSION" != "$PYPROJECT_VERSION" ] || [ "$TAG_VERSION" != "$INIT_VERSION" ]; then
echo -e "${RED}❌ Tag 版本与仓库版本号不一致${NC}"
echo -e "tag: ${YELLOW}$TAG_VERSION${NC}"
echo -e "pyproject.toml: ${YELLOW}$PYPROJECT_VERSION${NC}"
echo -e "src/Undefined/__init__.py: ${YELLOW}$INIT_VERSION${NC}"
if ! command -v uv >/dev/null 2>&1; then
echo -e "${RED}❌ 未找到 uv,请先安装 uv${NC}"
exit 1
fi

echo -e "${GREEN}✅ 版本检查通过: $TAG_VERSION${NC}"
echo -e "${YELLOW}🔖 校验 release 版本一致性: $TAG_NAME${NC}"
uv run python scripts/release_notes.py validate --tag "$TAG_NAME"

echo -e "${GREEN}✅ 版本检查通过: ${TAG_NAME#v}${NC}"
39 changes: 28 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: CI Code Quality

on:
workflow_dispatch:
push:
branches: [ "main" ]
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "develop" ]

env:
NODE_VERSION: "22"

jobs:
quality-check:
Expand Down Expand Up @@ -57,34 +61,47 @@ jobs:
run: |
uv run python -c "import glob, zipfile; whl=glob.glob('dist/*.whl')[0]; z=zipfile.ZipFile(whl); names=set(z.namelist()); required={'config.toml.example','res/prompts/undefined.xml','img/xlwy.jpg'}; missing=sorted([p for p in required if p not in names]); assert not missing, f'missing in wheel: {missing}'"

console-quality-check:
native-app-quality-check:
name: Native app quality (${{ matrix.app_dir }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- product: console
app_dir: apps/undefined-console
- product: chat
app_dir: apps/undefined-chat
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
cache-dependency-path: apps/undefined-console/package-lock.json
cache-dependency-path: ${{ matrix.app_dir }}/package-lock.json

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: apps/undefined-console/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('apps/undefined-console/package-lock.json') }}
path: ${{ matrix.app_dir }}/node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-node-modules-${{ matrix.product }}-${{ hashFiles(format('{0}/package-lock.json', matrix.app_dir)) }}
restore-keys: |
${{ runner.os }}-node-${{ env.NODE_VERSION }}-node-modules-${{ matrix.product }}-
${{ runner.os }}-node-${{ env.NODE_VERSION }}-node-modules-

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
key: ci-${{ matrix.product }}-${{ hashFiles(format('{0}/src-tauri/Cargo.lock', matrix.app_dir), format('{0}/package-lock.json', matrix.app_dir)) }}
workspaces: |
apps/undefined-console/src-tauri -> target
${{ matrix.app_dir }}/src-tauri -> target

- name: Install Linux system dependencies
run: |
Expand All @@ -98,9 +115,9 @@ jobs:

- name: Install app dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: apps/undefined-console
working-directory: ${{ matrix.app_dir }}
run: npm ci

- name: Run console checks
working-directory: apps/undefined-console
- name: Run native app checks
working-directory: ${{ matrix.app_dir }}
run: npm run check
Loading
Loading