Skip to content

Test coverage improvements #2

Test coverage improvements

Test coverage improvements #2

Workflow file for this run

name: Code Complexity Analysis
on:
pull_request:
branches: [main]
workflow_dispatch: # Allow manual trigger
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
analyze-complexity:
name: Analyze Code Complexity
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full git history for wily to analyze
- name: Install Nix
uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes
accept-flake-config = true
- name: Cache Nix store
uses: actions/cache@v4
with:
path: |
~/.cache/nix
key: ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}
restore-keys: |
${{ runner.os }}-nix-
- name: Set up Python environment
run: |
nix develop --command setup
- name: Install wily
run: |
nix develop --command bash -c 'if [ -z "$VIRTUAL_ENV" ]; then source .venv/bin/activate; fi && pip install wily'
- name: Build wily cache
run: |
nix develop --command bash -c 'if [ -z "$VIRTUAL_ENV" ]; then source .venv/bin/activate; fi && wily build mcp_nixos tests'
- name: Find base branch for PR or use default
id: find-base-branch
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "BASE_BRANCH=origin/${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
else
echo "BASE_BRANCH=HEAD^1" >> $GITHUB_OUTPUT
fi
- name: Run wily diff
id: wily-diff
run: |
if [ -z "$VIRTUAL_ENV" ]; then source .venv/bin/activate; fi
echo "Running complexity analysis comparing to ${{ steps.find-base-branch.outputs.BASE_BRANCH }}"
DIFF_OUTPUT=$(wily diff mcp_nixos tests -r ${{ steps.find-base-branch.outputs.BASE_BRANCH }})
# Set multi-line output for GitHub Actions
echo "DIFF_OUTPUT<<EOF" >> $GITHUB_ENV
echo "$DIFF_OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Store output as artifact
mkdir -p complexity-report
echo "$DIFF_OUTPUT" > complexity-report/diff.txt
# Also create a more detailed report of top 10 most complex files
wily rank mcp_nixos -n 10 mi > complexity-report/top10_maintainability.txt
wily rank mcp_nixos -n 10 raw.loc > complexity-report/top10_loc.txt
wily rank mcp_nixos -n 10 cyclomatic.complexity > complexity-report/top10_cyclomatic.txt
- name: Upload complexity report
uses: actions/upload-artifact@v4
with:
name: complexity-report
path: complexity-report/
- name: Add PR comment with complexity analysis
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
## Code Complexity Analysis
```
${{ env.DIFF_OUTPUT }}
```
For more details, check the complexity-report artifact in the workflow run.
comment_tag: complexity-analysis