From 4a50886a68da7bd4621210260ea693ee65c84840 Mon Sep 17 00:00:00 2001 From: alger Date: Sat, 11 Apr 2026 22:49:45 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20PR=20=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E8=A7=84=E8=8C=83=E6=A3=80=E6=9F=A5=E5=92=8C=20commit?= =?UTF-8?q?lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 commitlint 及 Conventional Commits 规范配置 - 添加 commit-msg husky hook 本地校验提交信息 - 添加 GitHub Actions PR 检查 workflow: - PR 标题符合 Conventional Commits - 所有 commit message 符合规范 - ESLint + TypeScript 类型检查 + i18n 检查 --- .github/workflows/pr-check.yml | 71 ++++++++++++++++++++++++++++++++++ .husky/commit-msg | 1 + commitlint.config.js | 12 ++++++ package.json | 2 + 4 files changed, 86 insertions(+) create mode 100644 .github/workflows/pr-check.yml create mode 100755 .husky/commit-msg create mode 100644 commitlint.config.js diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 0000000..70780d1 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,71 @@ +name: PR Check + +on: + pull_request: + branches: [main, dev_electron] + types: [opened, edited, synchronize, reopened] + +jobs: + # 检查 PR 标题是否符合 Conventional Commits 规范 + pr-title: + name: PR Title + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 24 + + - name: Install commitlint + run: npm install --no-save @commitlint/cli @commitlint/config-conventional + + - name: Validate PR title + env: + PR_TITLE: ${{ github.event.pull_request.title }} + run: echo "$PR_TITLE" | npx commitlint + + # 检查所有提交信息是否符合 Conventional Commits 规范 + commit-messages: + name: Commit Messages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 24 + + - name: Install commitlint + run: npm install --no-save @commitlint/cli @commitlint/config-conventional + + - name: Validate commit messages + run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose + + # 运行 lint 和类型检查 + code-quality: + name: Code Quality + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 24 + + - name: Install dependencies + run: npm install + + - name: Lint + run: npx eslint --max-warnings 0 "src/**/*.{ts,tsx,vue,js}" + + - name: Type check + run: npm run typecheck + + - name: I18n check + run: npm run lint:i18n diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..da99483 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no -- commitlint --edit "$1" diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..1696266 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,12 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'type-enum': [ + 2, + 'always', + ['feat', 'fix', 'perf', 'refactor', 'docs', 'style', 'test', 'build', 'ci', 'chore', 'revert'] + ], + 'subject-empty': [2, 'never'], + 'type-empty': [2, 'never'] + } +}; diff --git a/package.json b/package.json index 2483a87..13c00f3 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,8 @@ "vue-i18n": "^11.2.2" }, "devDependencies": { + "@commitlint/cli": "^20.5.0", + "@commitlint/config-conventional": "^20.5.0", "@electron-toolkit/eslint-config": "^2.1.0", "@electron-toolkit/eslint-config-ts": "^3.1.0", "@electron-toolkit/tsconfig": "^1.0.1",