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
104 changes: 104 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CI

on:
push:
branches:
- main
pull_request:
paths:
- "src/**"
- "tests/**"
- "pyproject.toml"
- ".github/workflows/**"

jobs:
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.11"
version: latest

- name: Ruff check
run: uvx ruff check --output-format=github .

- name: Ruff format check
run: uvx ruff format --check .

basedpyright:
name: BasedPyright
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.11"
version: "latest"

- name: Install Dependencies
run: uv sync

- name: Static typing check
run: uvx basedpyright

test:
name: Coverage
runs-on: windows-latest
permissions:
id-token: write
contents: read
concurrency:
# group: test-coverage-${{ github.ref }}-${{ matrix.python-version }}-${{ matrix.os }}
group: coverage-${{ github.ref }}-${{ matrix.python-version }}
cancel-in-progress: true

strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
# os: [ubuntu-latest, windows-latest, macos-latest]
# pydantic-version: ["v1", "v2"]

env:
# OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
UV_NO_SYNC: 1

steps:
- uses: actions/checkout@v6

- name: Setup uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: ${{ matrix.python-version }}
version: latest

- name: Install Dependencies
run: uv sync

- name: Run Pytest
run: uv run pytest --cov=src --cov-report xml --junitxml=./junit.xml -n auto

- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/codecov-action@v5
with:
env_vars: PYTHON
use_oidc: true
report_type: test_results

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
env_vars: PYTHON
use_oidc: true
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release

on:
push:
tags:
- v*

jobs:
release:
name: Release
runs-on: windows-latest
environment:
name: release
permissions:
id-token: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.11"
version: 'latest'

- name: Get Version
id: version
run: |
echo "VERSION=$(uv version --short)" >> $GITHUB_OUTPUT
echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Check Version
if: steps.version.outputs.VERSION != steps.version.outputs.TAG_VERSION
run: exit 1

- name: Generate Changelog
uses: orhun/git-cliff-action@v4
id: changelog
with:
config: cliff.toml
args: --latest --strip header
env:
GITHUB_REPO: ${{ github.repository }}

- name: Build with PyInstaller
shell: pwsh
run: |
uv sync
uv run pyinstaller peekapi.spec --noconfirm

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.content }}
files: |
dist/peekapi/**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# *.spec

# Installer logs
pip-log.txt
Expand Down Expand Up @@ -105,7 +105,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
poetry.lock
# poetry.toml

# pdm
Expand Down
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
default_install_hook_types: [pre-commit, commit-msg]
repos:
- repo: builtin
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.13
hooks:
- id: ruff-check
args: [--fix]
stages: [pre-commit]
- id: ruff-format
stages: [pre-commit]

- repo: https://github.com/commitizen-tools/commitizen
rev: v4.12.0
hooks:
- id: commitizen
stages: [commit-msg]
41 changes: 41 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# git-cliff configuration file
# https://git-cliff.org/docs/configuration

[changelog]
# 头部模板
header = """
# Changelog\n
"""
# 提交信息模板
body = """
{% if version -%}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else -%}
## [Unreleased]
{% endif %}

{% for group, commits in commits | group_by(attribute="group") -%}
### {{ group | striptags | trim | upper_first }}
{% for commit in commits -%}
- {% if commit.scope %}**{{ commit.scope }}**: {% endif %}{{ commit.message | split(pat="\n") | first | trim | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/Misty02600/PeekAPI/commit/{{ commit.id }})){% if commit.remote.username %} by @{{ commit.remote.username }}{% endif %}{% if commit.remote.pr_number %} in [#{{ commit.remote.pr_number }}](https://github.com/Misty02600/PeekAPI/pull/{{ commit.remote.pr_number }}){% endif %}
{% endfor %}

{% endfor -%}
"""
# 移除尾部空白
trim = true
# 底部模板
footer = ""
# 后处理器
postprocessors = []

[git]
# 提交分组
commit_parsers = [
{ message = "^feat", group = "✨ Features" },
{ message = "^fix", group = "🐛 Fixes" },
]
# 保护不匹配的破坏性提交
protect_breaking_commits = true
# 只保留能被 commit_parsers 匹配到的提交
filter_commits = true
43 changes: 30 additions & 13 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ run:

# 运行所有测试
test:
uv run pytest
uv run pytest -n auto

# 运行单元测试
test-unit:
uv run pytest tests/unit -v
uv run pytest tests/unit -n auto

# 运行集成测试
test-integration:
uv run pytest tests/integration -v

# 运行测试并生成覆盖率报告
test-cov:
uv run pytest --cov=src/peekapi --cov-report=html
uv run pytest tests/integration -n auto

# ===== 打包 =====

Expand All @@ -47,13 +43,34 @@ build-size: build
# ===== 代码质量 =====

# 格式化代码
fmt:
uv run ruff format src tests
format:
uv run ruff format .

# 检查代码
lint:
uv run ruff check src tests
uv run ruff check . --fix

# 类型检查
check:
uv run basedpyright

# ===== 版本管理 =====

# 版本发布(更新版本号、更新 lock 文件)
bump:
uv run cz bump
uv lock

# 生成 changelog
changelog:
uv run git-cliff --latest

# ===== prek =====

# 安装 prek hooks
hooks:
uv run prek install

# 修复代码问题
fix:
uv run ruff check --fix src tests
# 更新 prek hooks
update:
uv run prek auto-update
35 changes: 23 additions & 12 deletions memory-bank/activeContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

## 当前工作重点

项目处于稳定运行状态,核心功能已完成。当前关注点:
- 记忆库维护(进行中
项目处于稳定运行状态,核心功能已完成,CI 检查全部通过。当前关注点:
- CI/CD 配置优化(已完成
- Linux 平台支持(计划中)
- GitHub Release 自动发布(计划中)

## 最近变更

- 2026-02-02: CI 代码检查全面修复(ruff、basedpyright、pytest 全部通过)
- 修复导入路径:`src.peekapi` → `peekapi`
- 修复类型问题:`sys._MEIPASS`、`pytest.mark.skipif`
- 删除未使用导入和变量
- 修复测试逻辑(favicon、record 端点)
- 日志 sink 改用 `sys.stderr`
- 2026-02-02: CI 配置更新(测试环境改为 Windows)
- 2026-01-28: 优化 PyInstaller 打包配置(excludes 列表精简、清理脚本)
- 2026-01-26: Flask 重构为 FastAPI,移除 parse_float 死代码,优化录音类
- 2026-01-25: msgspec 配置重构,loguru 日志迁移,单元测试
- 2026-01-25: 初始化项目记忆库

## 当前状态

Expand All @@ -29,35 +35,39 @@
- ✅ 日志系统 (loguru)
- ✅ exe 打包支持
- ✅ FastAPI 重构(替代 Flask)
- ✅ 单元测试(85 测试通过)

### 进行中
- 🔄 记忆库文档维护
- ✅ 单元测试(84 测试通过)
- ✅ CI 代码检查(ruff、pyright、pytest 全通过)

### 计划中
- 📋 Linux 平台支持
- 📋 GitHub Release 自动发布 EXE

## 下一步行动

1. 完成记忆库更新
1. 推送代码到 GitHub,验证 CI 通过
2. 评估 Linux 支持方案
3. OpenAPI 文档完善
3. 配置 GitHub Release 自动发布

## 活跃决策

### 决策 1: Linux 支持方案
### 决策 1: 测试导入路径
- **状态**: 已解决
- **问题**: 测试文件使用 `src.peekapi` 导入路径导致 CI 失败
- **解决方案**: 统一使用 `peekapi` 作为包名导入

### 决策 2: Linux 支持方案
- **状态**: 规划中
- **问题**: winotify 是 Windows 专用,需要替换
- **选项**:
- 使用跨平台通知库
- 根据平台条件导入
- **参考**: [docs/plan.md](../docs/plan.md)(如存在)

## 需要注意的事项

1. **配置文件位置** - exe 模式和开发模式路径不同
2. **音频设备** - 需要有默认扬声器才能录音
3. **API 安全** - 生产环境应设置 api_key
4. **CI 环境** - 测试在 Windows 上运行(音频/显示器依赖)

## 阻塞问题

Expand All @@ -68,3 +78,4 @@
- README.md - 项目说明和 API 文档
- config.toml - 配置示例
- pyproject.toml - 依赖管理
- .github/workflows/ci.yml - CI 配置
Loading