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
33 changes: 0 additions & 33 deletions .github/workflows/code-lint-.yaml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/code-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Code Quality Check

on:
push:
branches: [main]
pull_request:
branches: [main]
paths:
- "src/**/*.{js,jsx,ts,tsx,mdx}"
- "package.json"
- "pnpm-lock.yaml"
- ".github/workflows/**"

jobs:
lint:
name: Code Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false

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

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install

- name: ESLint check
run: pnpm run eslint

- name: Add Check Summary
if: always()
run: |
echo "### 代码质量检查结果 :microscope:" >> $GITHUB_STEP_SUMMARY
if [ ${{ job.status }} == 'success' ]; then
echo "✅ 所有检查通过" >> $GITHUB_STEP_SUMMARY
else
echo "❌ 检查未通过" >> $GITHUB_STEP_SUMMARY
echo "请查看上方日志了解具体错误信息" >> $GITHUB_STEP_SUMMARY
fi
73 changes: 67 additions & 6 deletions .github/workflows/lint-pr-title.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
name: Lint Pr Title
name: PR标题规范检查

on: [pull_request]
on:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
lint-pr-title:
name: Validate PR title
check-pr-title:
name: 检查PR标题格式
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
- name: 检查PR标题
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
fix
feat
fix
docs
style
refactor
Expand All @@ -24,4 +30,59 @@ jobs:
chore
revert
release
typesDescription: |
feat: 新功能
fix: 修复bug
docs: 文档更新
style: 代码格式修改(不影响代码运行的变动)
refactor: 代码重构(既不是新增功能,也不是修改bug的代码变动)
perf: 性能优化
test: 增加测试
build: 构建过程或辅助工具的变动
ci: CI配置文件和脚本的变动
chore: 其他修改(不修改src或测试文件)
revert: 回滚之前的提交
release: 发布新版本
requireScope: false
subjectPattern: ^[A-Za-z\u4e00-\u9fa5].+$
subjectPatternError: |
PR标题格式不正确!

正确的格式是:<type>: <subject>
- type必须是上述类型之一
- subject必须以字母或中文开头

正确的例子:
✅ feat: 添加登录功能
✅ fix: 修复首页加载慢的问题
✅ docs: 更新README文档
✅ style: 优化代码格式

你的PR标题是:${{ github.event.pull_request.title }}

- name: 添加检查结果摘要
if: always()
run: |
echo "### PR标题检查结果 :label:" >> $GITHUB_STEP_SUMMARY
if [ ${{ job.status }} == 'success' ]; then
echo "✅ PR标题格式正确" >> $GITHUB_STEP_SUMMARY
else
echo "❌ PR标题格式不正确" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "#### 标题格式要求" >> $GITHUB_STEP_SUMMARY
echo "格式:\`<type>: <subject>\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "允许的type类型:" >> $GITHUB_STEP_SUMMARY
echo "- feat: 新功能" >> $GITHUB_STEP_SUMMARY
echo "- fix: 修复bug" >> $GITHUB_STEP_SUMMARY
echo "- docs: 文档更新" >> $GITHUB_STEP_SUMMARY
echo "- style: 代码格式修改" >> $GITHUB_STEP_SUMMARY
echo "- refactor: 代码重构" >> $GITHUB_STEP_SUMMARY
echo "- perf: 性能优化" >> $GITHUB_STEP_SUMMARY
echo "- test: 增加测试" >> $GITHUB_STEP_SUMMARY
echo "- build: 构建相关" >> $GITHUB_STEP_SUMMARY
echo "- ci: CI配置相关" >> $GITHUB_STEP_SUMMARY
echo "- chore: 其他修改" >> $GITHUB_STEP_SUMMARY
echo "- revert: 回滚提交" >> $GITHUB_STEP_SUMMARY
echo "- release: 发布版本" >> $GITHUB_STEP_SUMMARY
fi
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"preview": "astro preview",
"astro": "astro",
"eslint": "eslint --fix --max-warnings=0 'src/**/*.{js,jsx,ts,tsx,mdx}'",
"pre-check": "sh ./scripts/pre-check.sh",
"postinstall": "husky install"
},
"lint-staged": {
Expand Down Expand Up @@ -54,4 +53,4 @@
"prettier-plugin-astro": "^0.14.1",
"sass-embedded": "^1.83.4"
}
}
}
Loading