1+ name : Code Complexity Analysis
2+
3+ on :
4+ pull_request :
5+ branches : [main]
6+ workflow_dispatch : # Allow manual trigger
7+
8+ concurrency :
9+ group : ${{ github.workflow }}-${{ github.ref }}
10+ cancel-in-progress : true
11+
12+ jobs :
13+ analyze-complexity :
14+ name : Analyze Code Complexity
15+ runs-on : ubuntu-latest
16+ steps :
17+ - name : Checkout code
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0 # Full git history for wily to analyze
21+
22+ - name : Install Nix
23+ uses : cachix/install-nix-action@v27
24+ with :
25+ nix_path : nixpkgs=channel:nixos-unstable
26+ extra_nix_config : |
27+ experimental-features = nix-command flakes
28+ accept-flake-config = true
29+
30+ - name : Cache Nix store
31+ uses : actions/cache@v4
32+ with :
33+ path : |
34+ ~/.cache/nix
35+ key : ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}
36+ restore-keys : |
37+ ${{ runner.os }}-nix-
38+
39+ - name : Set up Python environment
40+ run : |
41+ nix develop --command setup
42+
43+ - name : Install wily
44+ run : |
45+ nix develop --command bash -c 'if [ -z "$VIRTUAL_ENV" ]; then source .venv/bin/activate; fi && pip install wily'
46+
47+ - name : Build wily cache
48+ run : |
49+ nix develop --command bash -c 'if [ -z "$VIRTUAL_ENV" ]; then source .venv/bin/activate; fi && wily build mcp_nixos tests'
50+
51+ - name : Find base branch for PR or use default
52+ id : find-base-branch
53+ run : |
54+ if [[ "${{ github.event_name }}" == "pull_request" ]]; then
55+ echo "BASE_BRANCH=origin/${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
56+ else
57+ echo "BASE_BRANCH=HEAD^1" >> $GITHUB_OUTPUT
58+ fi
59+
60+ - name : Run wily diff
61+ id : wily-diff
62+ run : |
63+ if [ -z "$VIRTUAL_ENV" ]; then source .venv/bin/activate; fi
64+
65+ echo "Running complexity analysis comparing to ${{ steps.find-base-branch.outputs.BASE_BRANCH }}"
66+ DIFF_OUTPUT=$(wily diff mcp_nixos tests -r ${{ steps.find-base-branch.outputs.BASE_BRANCH }})
67+
68+ # Set multi-line output for GitHub Actions
69+ echo "DIFF_OUTPUT<<EOF" >> $GITHUB_ENV
70+ echo "$DIFF_OUTPUT" >> $GITHUB_ENV
71+ echo "EOF" >> $GITHUB_ENV
72+
73+ # Store output as artifact
74+ mkdir -p complexity-report
75+ echo "$DIFF_OUTPUT" > complexity-report/diff.txt
76+
77+ # Also create a more detailed report of top 10 most complex files
78+ wily rank mcp_nixos -n 10 mi > complexity-report/top10_maintainability.txt
79+ wily rank mcp_nixos -n 10 raw.loc > complexity-report/top10_loc.txt
80+ wily rank mcp_nixos -n 10 cyclomatic.complexity > complexity-report/top10_cyclomatic.txt
81+
82+ - name : Upload complexity report
83+ uses : actions/upload-artifact@v4
84+ with :
85+ name : complexity-report
86+ path : complexity-report/
87+
88+ - name : Add PR comment with complexity analysis
89+ if : github.event_name == 'pull_request'
90+ uses : thollander/actions-comment-pull-request@v2
91+ with :
92+ message : |
93+ ## Code Complexity Analysis
94+
95+ ```
96+ ${{ env.DIFF_OUTPUT }}
97+ ```
98+
99+ For more details, check the complexity-report artifact in the workflow run.
100+ comment_tag : complexity-analysis
0 commit comments