Repository navigation
fix(ci): improve AI code review workflow - fix bugs #131
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: CI | |
| on: | |
| push: | |
| branches: [main, wjy_dev, jzj_dev] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| jobs: | |
| # ═════════════════════════════════════════════════════════════════════════ | |
| # 课题功能测试:所有14个模块的单元测试 + 集成测试 | |
| # ═════════════════════════════════════════════════════════════════════════ | |
| test: | |
| runs-on: self-hosted | |
| timeout-minutes: 20 | |
| steps: | |
| - name: Sync from local mirror (skip unstable GitHub checkout) | |
| run: | | |
| echo "=== CI Sync: checkout target ===" | |
| echo "GITHUB_SHA=$GITHUB_SHA" | |
| echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME" | |
| MIRROR=/opt/ScratchV | |
| WORKSPACE=/opt/actions-runner/_work/ScratchV/ScratchV | |
| # Copy pre-cloned repo to workspace (avoid GitHub network issues) | |
| rm -rf "$WORKSPACE" | |
| cp -a "$MIRROR" "$WORKSPACE" | |
| cd "$WORKSPACE" | |
| # Try to fetch latest; fallback to local copy if network fails | |
| echo "Fetching origin main..." | |
| git fetch origin main --depth=1 || echo "::warning::git fetch origin main failed" | |
| # Fetch PR merge ref for pull_request events | |
| if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then | |
| PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "") | |
| if [ -n "$PR_NUMBER" ]; then | |
| echo "Fetching PR #${PR_NUMBER} merge ref..." | |
| git fetch origin "refs/pull/${PR_NUMBER}/merge" --depth=1 || echo "::warning::git fetch PR #${PR_NUMBER} merge ref failed" | |
| fi | |
| fi | |
| echo "Checkout target: $GITHUB_SHA" | |
| if git checkout -f "$GITHUB_SHA"; then | |
| echo "::notice::Checkout successful: $(git log -1 --format='%h %ai %s')" | |
| else | |
| echo "::warning::GITHUB_SHA ($GITHUB_SHA) not found in local repo — falling back to origin/main" | |
| git checkout -f origin/main | |
| echo "::warning::FALLBACK: CI is testing origin/main: $(git log -1 --format='%h %ai %s')" | |
| fi | |
| - name: Install dependencies | |
| run: | | |
| python3.12 -m pip install --upgrade pip | |
| python3.12 -m pip install -e ".[all]" | |
| - name: Run all topic tests | |
| run: | | |
| mkdir -p benchmark_reports | |
| python3.12 -m pytest tests/ -v --tb=short \ | |
| --junit-xml=benchmark_reports/test_results.xml \ | |
| --ignore=tests/test_simulator.py | |
| - name: Generate test visualization page | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| python3.12 scratchv/ci/test_page.py \ | |
| --junit benchmark_reports/test_results.xml \ | |
| -o benchmark_reports/tests.html | |
| - name: Upload test reports | |
| if: github.ref == 'refs/heads/main' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-reports | |
| path: | | |
| benchmark_reports/test_results.xml | |
| benchmark_reports/tests.html | |
| retention-days: 30 | |
| # ═════════════════════════════════════════════════════════════════════════ | |
| # 模型性能测试:ONNX模型管线 + DSL用例 + CNN RISC-V编译 | |
| # ═════════════════════════════════════════════════════════════════════════ | |
| benchmark: | |
| runs-on: self-hosted | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Sync from local mirror (skip unstable GitHub checkout) | |
| run: | | |
| echo "=== CI Sync: checkout target ===" | |
| echo "GITHUB_SHA=$GITHUB_SHA" | |
| echo "GITHUB_EVENT_NAME=$GITHUB_EVENT_NAME" | |
| MIRROR=/opt/ScratchV | |
| WORKSPACE=/opt/actions-runner/_work/ScratchV/ScratchV | |
| # Copy pre-cloned repo to workspace (avoid GitHub network issues) | |
| rm -rf "$WORKSPACE" | |
| cp -a "$MIRROR" "$WORKSPACE" | |
| cd "$WORKSPACE" | |
| # Try to fetch latest; fallback to local copy if network fails | |
| echo "Fetching origin main..." | |
| git fetch origin main --depth=1 || echo "::warning::git fetch origin main failed" | |
| # Fetch PR merge ref for pull_request events | |
| if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then | |
| PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "") | |
| if [ -n "$PR_NUMBER" ]; then | |
| echo "Fetching PR #${PR_NUMBER} merge ref..." | |
| git fetch origin "refs/pull/${PR_NUMBER}/merge" --depth=1 || echo "::warning::git fetch PR #${PR_NUMBER} merge ref failed" | |
| fi | |
| fi | |
| echo "Checkout target: $GITHUB_SHA" | |
| if git checkout -f "$GITHUB_SHA"; then | |
| echo "::notice::Checkout successful: $(git log -1 --format='%h %ai %s')" | |
| else | |
| echo "::warning::GITHUB_SHA ($GITHUB_SHA) not found in local repo — falling back to origin/main" | |
| git checkout -f origin/main | |
| echo "::warning::FALLBACK: CI is testing origin/main: $(git log -1 --format='%h %ai %s')" | |
| fi | |
| - name: Install dependencies | |
| run: | | |
| python3.12 -m pip install --upgrade pip | |
| python3.12 -m pip install -e ".[all]" | |
| python3.12 -m pip install markdown | |
| # ── 3.1 ONNX 模型管线基准测试 ────────────────────────────────────── | |
| - name: ONNX model pipeline benchmarks | |
| run: python3.12 -m pytest benchmarks/test_benchmark.py -v --tb=short | |
| # ── 3.2 DSL 用例编译 + 模拟基准 ──────────────────────────────────── | |
| - name: DSL case compilation benchmarks | |
| run: | | |
| mkdir -p benchmark_reports | |
| python3.12 benchmarks/bench_runner.py benchmarks/cases \ | |
| --output-json benchmark_reports/dsl_bench.json \ | |
| --output-html benchmark_reports/dsl_bench.html \ | |
| --output-md benchmark_reports/dsl_bench.md | |
| # ── 3.3 CNN RISC-V 编译 + 性能估算 ──────────────────────────────── | |
| - name: CNN RISC-V compilation & estimation | |
| run: | | |
| mkdir -p benchmark_reports models/graph | |
| MODEL=models/graph/cnn.onnx | |
| if [ ! -f "$MODEL" ]; then | |
| echo "::warning::cnn.onnx not found, generating minimal CNN test model" | |
| python3.12 scripts/gen_minimal_cnn.py 2>&1 | |
| fi | |
| python3.12 scratchv/standalone/onnx_to_riscv_standalone.py \ | |
| "$MODEL" -o /tmp/cnn_riscv.bin --estimate --report | |
| # ── 3.4 LLVM vs ScratchV + TinyFive + Dashboard ────────────────── | |
| - name: LLVM vs ScratchV comparison | |
| run: | | |
| mkdir -p benchmark_reports | |
| # Generate ScratchV assembly if not already present | |
| if [ ! -f benchmark_reports/cnn_scratchv.s ] && [ -f models/graph/cnn.onnx ]; then | |
| python3.12 scratchv/standalone/onnx_to_riscv_standalone.py \ | |
| models/graph/cnn.onnx -o /tmp/cnn_riscv.bin \ | |
| --asm benchmark_reports/cnn_scratchv.s --estimate 2>&1 | tail -3 | |
| fi | |
| python3.12 scratchv/standalone/llvm_cache_compare.py \ | |
| --json-output benchmark_reports/llvm_vs_scratchv.json \ | |
| --markdown benchmark_reports/llvm_vs_scratchv.md \ | |
| || echo "WARNING: llvm_cache_compare failed" | |
| python3.12 scratchv/standalone/tinyfive_compare.py \ | |
| --json benchmark_reports/tinyfive_compare.json \ | |
| --markdown benchmark_reports/tinyfive_compare.md \ | |
| --scratchv-asm benchmark_reports/cnn_scratchv.s \ | |
| || echo "WARNING: tinyfive_compare failed" | |
| # ── 3.5 ONNX 模型拆分为单算子 ──────────────────────────────────── | |
| - name: Split CNN model into single operators | |
| run: | | |
| python3.12 scripts/split_cnn_to_single_ops.py \ | |
| || echo "WARNING: split_cnn_to_single_ops failed" | |
| # ── 3.6 单算子 benchmark ──────────────────────────────────────── | |
| - name: Single-operator benchmarks | |
| run: | | |
| python3.12 scripts/bench_single_ops.py \ | |
| || echo "WARNING: bench_single_ops failed" | |
| # ── 3.7 生成仪表盘 HTML (版本vsLLVM + 指令分类 + 算子对比) ───── | |
| - name: Generate dashboard | |
| run: | | |
| python3.12 scratchv/ci/dashboard.py \ | |
| --llvm-json benchmark_reports/llvm_vs_scratchv.json \ | |
| --history-json benchmark_reports/optimization_history.json \ | |
| -o benchmark_reports/dashboard.html \ | |
| || echo "WARNING: dashboard generation failed" | |
| # ── 上报 ────────────────────────────────────────────────────────── | |
| - name: Upload benchmark reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: benchmark-reports | |
| path: benchmark_reports/ | |
| retention-days: 30 | |
| # ── 保留推广主页(docs/ScratchV.html 不会被顶替) ──────────────── | |
| - name: Copy promotional page into Pages artifact | |
| if: github.ref == 'refs/heads/main' | |
| run: cp docs/ScratchV.html benchmark_reports/ScratchV.html | |
| # ── 文档课程 HTML 站点 ────────────────────────────────────────────── | |
| - name: Build docs HTML course site | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| python3.12 -m pip install markdown | |
| python3.12 scripts/build_docs_html.py --output-dir benchmark_reports/docs | |
| echo "Docs site built: benchmark_reports/docs/index.html" | |
| # ── 优化历史页面 ────────────────────────────────────────────────── | |
| - name: Generate optimization history page | |
| if: github.ref == 'refs/heads/main' | |
| run: python3.12 scratchv/ci/history_page.py -o benchmark_reports/history.html | |
| # ── 测试可视化页面 ──────────────────────────────────────────────── | |
| - name: Generate test visualization page | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| python3.12 scratchv/ci/test_page.py \ | |
| --junit benchmark_reports/test_results.xml \ | |
| -o benchmark_reports/tests.html | |
| # ── 精简 Pages 产物(移除大型编译产物) ────────────────────────── | |
| - name: Clean large binaries before Pages deploy | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| rm -f benchmark_reports/*.bin benchmark_reports/*.elf | |
| rm -f benchmark_reports/*.ll | |
| rm -f benchmark_reports/cnn.onnx_* | |
| rm -f benchmark_reports/_ll_* benchmark_reports/_sv.* | |
| echo "Cleaned large binaries from Pages artifact" | |
| # ── 上传 Pages 产物 ────────────────────────────────────────────── | |
| - name: Upload Pages artifact | |
| if: github.ref == 'refs/heads/main' | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: benchmark_reports/ | |
| - name: Write job summary | |
| run: | | |
| if [ -f benchmark_reports/github_summary.md ]; then | |
| cat benchmark_reports/github_summary.md >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### LLVM vs ScratchV" >> $GITHUB_STEP_SUMMARY | |
| if [ -f benchmark_reports/llvm_vs_scratchv.md ]; then | |
| tail -20 benchmark_reports/llvm_vs_scratchv.md >> $GITHUB_STEP_SUMMARY | |
| fi | |
| # ═════════════════════════════════════════════════════════════════════════ | |
| # GitHub Pages 部署 (仅 main 分支) | |
| # ═════════════════════════════════════════════════════════════════════════ | |
| deploy-pages: | |
| needs: benchmark | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pages: write | |
| id-token: write | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |