Skip to content

Commit

Permalink
add radon to backend workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nlebovits committed Sep 25, 2024
1 parent 66b8ceb commit 8ac2d5d
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 176 deletions.
41 changes: 34 additions & 7 deletions .github/workflows/pr_checks_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- 'data/**'
- 'Dockerfile-pg'
- 'init_pg.sql'
- 'docker compose.yml'
- 'docker-compose.yml'
workflow_dispatch:

jobs:
Expand All @@ -29,11 +29,43 @@ jobs:
with:
python-version: '3.11.4'

- name: Install Radon
run: pip install radon

run-radon:
runs-on: ubuntu-latest
needs: setup
continue-on-error: true # Ensure workflow continues on error
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Radon Maintainability Index (MI) and Halstead Checks
run: |
# Run Maintainability Index analysis and capture bad grades (below B)
bad_grades=$(radon mi -s data/ | grep -E " - [CDEF] \(" || true)
if [[ ! -z "$bad_grades" ]]; then
echo "Bad MI grades found:"
echo "$bad_grades"
else
echo "Radon MI checks passed successfully"
fi
# Run Halstead complexity analysis and check for effort > 2000
high_effort=$(radon hal data/ -s | awk '/effort/ { if ($3 > 2000) print $0 }')
if [[ ! -z "$high_effort" ]]; then
echo "High Halstead effort found:"
echo "$high_effort"
else
echo "Halstead checks passed successfully"
fi
run-formatter:
runs-on: ubuntu-latest
needs: setup
continue-on-error: true

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -47,7 +79,6 @@ jobs:
runs-on: ubuntu-latest
needs: setup
continue-on-error: true

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -60,7 +91,6 @@ jobs:
build-project:
runs-on: ubuntu-latest
needs: setup

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -73,7 +103,6 @@ jobs:
run-services:
runs-on: ubuntu-latest
needs: build-project

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -86,7 +115,6 @@ jobs:
check-build-status:
runs-on: ubuntu-latest
needs: run-services

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -103,7 +131,6 @@ jobs:
check-lint-format-status:
runs-on: ubuntu-latest
needs: [run-formatter, run-linter]

steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
13 changes: 12 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ repos:
# Dependency checks for Python
- id: check-python-dependencies
name: Check Python dependencies
entry: bash -c 'cd data/src && pipenv check --bare --quiet || (echo "Python dependencies check failed" && exit 1)'
entry: |
bash -c 'cd data/src && pipenv check --bare --quiet || (echo "Python dependencies check failed" && exit 1)'
language: system
files: ^data/src/Pipfile$

# Radon MI and Halstead checks
- id: radon-check
name: Radon Maintainability and Halstead Checks
entry: |
bash -c 'radon mi -s {} | grep -E " - [CDEF] \(" && echo "Radon MI grade below B detected!" && exit 1 || echo "All MI grades are B or above."
radon hal {} -s | awk "/effort/ { if (\$3 > 2000) print FILENAME \": High Halstead effort:\" \$3 }"'
language: system
files: \.py$
exclude: ^data/src/awkde/

# JavaScript hooks
- repo: local
hooks:
Expand Down
1 change: 1 addition & 0 deletions data/src/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ libpysal = "*"
jenkspy = "*"
pyarrow = "*"
tqdm = "*"
radon = "*"

[dev-packages]

Expand Down
Loading

0 comments on commit 8ac2d5d

Please sign in to comment.