Merge pull request #23 from MeowKJ/dev #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Code Quality & AI Review | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'Firmware/**' | |
| - 'Software/**' | |
| - '.github/workflows/code-quality.yml' | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'Firmware/**' | |
| - 'Software/**' | |
| schedule: | |
| # 每天凌晨 2 点运行一次完整扫描 | |
| - cron: '0 2 * * *' | |
| permissions: | |
| contents: read | |
| security-events: write | |
| pull-requests: write | |
| actions: read | |
| jobs: | |
| # CodeQL 安全扫描(仅 JavaScript;C/C++ 固件使用 MounRiver/WCH 工具链,无标准构建系统) | |
| codeql-analysis: | |
| name: CodeQL Security Analysis | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: read | |
| contents: read | |
| security-events: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Initialize CodeQL | |
| uses: github/codeql-action/init@v3 | |
| with: | |
| languages: javascript | |
| queries: +security-and-quality | |
| - name: Autobuild | |
| uses: github/codeql-action/autobuild@v3 | |
| - name: Perform CodeQL Analysis | |
| uses: github/codeql-action/analyze@v3 | |
| with: | |
| category: "/language:javascript" | |
| # JavaScript/TypeScript 代码质量检查 | |
| js-ts-quality: | |
| name: JavaScript/TypeScript Quality Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| cache-dependency-path: Software/binary-keyboard-studio-ui/pnpm-lock.yaml | |
| - name: Install dependencies | |
| working-directory: Software/binary-keyboard-studio-ui | |
| run: pnpm install | |
| - name: Run ESLint | |
| working-directory: Software/binary-keyboard-studio-ui | |
| run: pnpm run lint || echo "ESLint check completed with warnings" | |
| - name: Run TypeScript type check | |
| working-directory: Software/binary-keyboard-studio-ui | |
| run: pnpm run type-check | |
| - name: Build check | |
| working-directory: Software/binary-keyboard-studio-ui | |
| run: pnpm run build-only | |
| # C/C++ 代码质量检查 | |
| cpp-quality: | |
| name: C/C++ Quality Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install cppcheck | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y cppcheck | |
| - name: Run cppcheck on Firmware | |
| continue-on-error: true | |
| run: | | |
| cppcheck --enable=all --suppress=missingIncludeSystem \ | |
| --xml --xml-version=2 \ | |
| Firmware/CH592F/ 2> cppcheck-result.xml || true | |
| cppcheck --enable=all --suppress=missingIncludeSystem \ | |
| --xml --xml-version=2 \ | |
| Firmware/CH552G/ 2> cppcheck-result2.xml || true | |
| - name: Upload cppcheck results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: cppcheck-results | |
| path: cppcheck-result*.xml | |
| retention-days: 7 | |
| # 代码复杂度分析 | |
| complexity-analysis: | |
| name: Code Complexity Analysis | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install complexity analysis tools | |
| run: | | |
| npm install -g jscpd@latest | |
| - name: Check code duplication (JavaScript/TypeScript) | |
| continue-on-error: true | |
| run: | | |
| jscpd Software/ --min-lines 5 --min-tokens 50 --format markdown > duplication-report.md || true | |
| - name: Upload complexity report | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: complexity-report | |
| path: duplication-report.md | |
| retention-days: 7 | |
| # 总结报告 | |
| quality-summary: | |
| name: Quality Check Summary | |
| runs-on: ubuntu-latest | |
| needs: [codeql-analysis, js-ts-quality, cpp-quality, complexity-analysis] | |
| if: always() | |
| steps: | |
| - name: Check results | |
| run: | | |
| echo "## Code Quality Check Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| CodeQL Analysis | ${{ needs.codeql-analysis.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| JS/TS Quality | ${{ needs.js-ts-quality.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| C/C++ Quality | ${{ needs.cpp-quality.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Complexity Analysis | ${{ needs.complexity-analysis.result }} |" >> $GITHUB_STEP_SUMMARY |