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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -euo pipefail

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

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

STAGED=$(git diff --cached --name-only --diff-filter=ACMRTUXB || true)

if [ -z "$STAGED" ]; then
exit 0
fi

echo -e "${YELLOW}🔍 运行 pre-commit 检查...${NC}"

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

if [ ! -f "pyproject.toml" ]; then
echo -e "${RED}❌ 未找到 pyproject.toml${NC}"
exit 1
fi

echo -e "${YELLOW}📝 Python: ruff format --check${NC}"
uv run ruff format --check --exclude "code/" --force-exclude

echo -e "${YELLOW}📝 Python: ruff check${NC}"
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
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
fi

npm --prefix apps/undefined-console run check
fi

echo -e "${GREEN}✅ pre-commit 检查通过${NC}"
33 changes: 33 additions & 0 deletions .githooks/pre-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail

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

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
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 [ "$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}"
exit 1
fi

echo -e "${GREEN}✅ 版本检查通过: $TAG_VERSION${NC}"
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,49 @@ jobs:
- name: Verify wheel contains resources
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:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"

- name: Cache npm and node_modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-undefined-console-npm-${{ hashFiles('apps/undefined-console/package-lock.json', 'apps/undefined-console/package.json', 'apps/undefined-console/biome.json') }}
restore-keys: |
${{ runner.os }}-undefined-console-npm-

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

- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
workspaces: |
apps/undefined-console/src-tauri -> target

- name: Install Linux system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libwebkit2gtk-4.1-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
patchelf

- name: Install app dependencies
working-directory: apps/undefined-console
run: npm ci

- name: Run console checks
working-directory: apps/undefined-console
run: npm run check
Loading