diff --git a/.github/workflows/update_codebase_chart.yml b/.github/workflows/update_codebase_chart.yml new file mode 100644 index 000000000..de8706dc8 --- /dev/null +++ b/.github/workflows/update_codebase_chart.yml @@ -0,0 +1,96 @@ +name: Update Codebase Pie Chart + +on: + workflow_dispatch: + schedule: + - cron: '0 4 1 */2 *' # Run at 4:00 UTC on the 1st day of every 2nd month + push: + branches: + - master + paths: + - 'scripts/generate_codebase_pie_chart.py' + - 'ardupilot_methodic_configurator/**/*.py' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + update-chart: + runs-on: ubuntu-latest + permissions: + contents: write # for creating branches and commits + pull-requests: write # for creating PRs + + env: + CHART_CHANGED: false + + strategy: + matrix: + python-version: ['3.13'] + + steps: + - name: Harden the runner (Audit all outbound calls) + uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 + with: + egress-policy: audit + + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + # https://docs.astral.sh/uv/guides/integration/github/ + - name: Install uv and set the python version + uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v6.6.1 + with: + python-version: ${{ matrix.python-version }} + activate-environment: true + + - name: Install dependencies + # required by generate_codebase_pie_chart.py + run: | + uv pip install .[dev] + + - name: Generate codebase pie chart + run: python scripts/generate_codebase_pie_chart.py + + - name: Check for changes and stage them + run: | + git add images/codebase_structure_pie_chart.png + git add images/codebase_structure_pie_chart.svg + if [[ -n "$(git status --porcelain)" ]]; then + echo "CHART_CHANGED=true" >> $GITHUB_ENV + else + echo "No changes to commit" + fi + + - name: Create Pull Request + if: env.CHART_CHANGED == 'true' + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 + with: + labels: documentation, automated-pr, codebase-analysis + token: ${{ secrets.GITHUB_TOKEN }} + branch: update-codebase-chart + title: "Update codebase structure pie chart" + commit-message: "docs(codebase pie chart): Update codebase structure pie chart with latest metrics" + body: | + This PR updates the codebase structure pie chart with the latest code metrics. + + The chart shows the distribution of code lines across different categories: + - Test Code (Python) + - Core Application Code (Python, hand-written) + - Generated Code (Python, auto-generated) + - Utility Scripts (Python + shell) + - Documentation (Markdown files) + - Configuration (JSON files) + + Changes were automatically generated by the `scripts/generate_codebase_pie_chart.py` script. + + The updated chart reflects the current state of the codebase and helps track: + - Test coverage ratios + - Documentation-to-code ratios + - Generated vs. hand-written code proportions + - Overall project health metrics + delete-branch: true diff --git a/images/codebase_structure_pie_chart.png b/images/codebase_structure_pie_chart.png index dd32c819f..8ad706ef9 100644 Binary files a/images/codebase_structure_pie_chart.png and b/images/codebase_structure_pie_chart.png differ diff --git a/images/codebase_structure_pie_chart.svg b/images/codebase_structure_pie_chart.svg index e65b5c8ba..dadb9882f 100644 --- a/images/codebase_structure_pie_chart.svg +++ b/images/codebase_structure_pie_chart.svg @@ -6,11 +6,11 @@ - 2025-06-25T14:37:48.452310 + 2025-09-05T13:25:26.818228 image/svg+xml - Matplotlib v3.9.4, https://matplotlib.org/ + Matplotlib v3.10.6, https://matplotlib.org/ @@ -175,10 +175,10 @@ z " transform="scale(0.015625)"/> - - - - + + + + @@ -314,13 +314,13 @@ z " transform="scale(0.015625)"/> - - - - - - - + + + + + + + @@ -445,10 +445,10 @@ z " transform="scale(0.015625)"/> - - - - + + + + @@ -612,21 +612,21 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -697,26 +697,26 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -771,10 +771,10 @@ z " transform="scale(0.015625)"/> - - - - + + + + @@ -861,18 +861,18 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - + + + + + + + + + + + + @@ -909,15 +909,15 @@ z " transform="scale(0.015625)"/> - - - - - - - - - + + + + + + + + + @@ -975,10 +975,10 @@ z " transform="scale(0.015625)"/> - - - - + + + + @@ -1042,18 +1042,18 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - + + + + + + + + + + + + @@ -1138,21 +1138,21 @@ z " transform="scale(0.015625)"/> - - - - - + + + + + - - - - + + + + @@ -1186,39 +1186,39 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - + + + @@ -1244,20 +1244,20 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -1279,21 +1279,21 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -1341,45 +1341,45 @@ z " transform="scale(0.015625)"/> - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1421,40 +1421,40 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1508,46 +1508,46 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1832,22 +1832,22 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -2117,32 +2117,32 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2347,43 +2347,43 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2449,39 +2449,39 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2553,40 +2553,40 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2628,39 +2628,39 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2742,40 +2742,40 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2829,17 +2829,17 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - + + + + + + + + + + + @@ -2866,32 +2866,32 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2933,119 +2933,119 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3092,51 +3092,51 @@ z " transform="scale(0.015625)"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/generate_codebase_pie_chart.py b/scripts/generate_codebase_pie_chart.py index 07b41d006..a8155d8e8 100755 --- a/scripts/generate_codebase_pie_chart.py +++ b/scripts/generate_codebase_pie_chart.py @@ -21,8 +21,12 @@ from pathlib import Path from typing import Any +import matplotlib as mpl import matplotlib.patches import matplotlib.pyplot as plt +from matplotlib.axes import Axes + +mpl.use("Agg") # Use non-interactive backend that doesn't require GUI # ruff: noqa: T201 @@ -141,7 +145,7 @@ def create_codebase_pie_chart(sizes: list[int], categories: list[str], colors: l return stats -def create_legend(ax: plt.Axes, wedges: list[matplotlib.patches.Wedge], stats: dict[str, float], total_lines: int) -> None: +def create_legend(ax: Axes, wedges: list[matplotlib.patches.Wedge], stats: dict[str, float], total_lines: int) -> None: """Create the legend with line counts and percentages.""" test_pct = stats["test_lines"] / total_lines * 100 app_pct = stats["handwritten_app_lines"] / total_lines * 100 @@ -201,8 +205,8 @@ def save_charts() -> None: plt.savefig(output_file_svg, bbox_inches="tight", facecolor="white", edgecolor="none") print(f"SVG version saved to: {output_file_svg}") - # Show the plot - plt.show() + # Close the plot to free memory + plt.close() def print_detailed_analysis(stats: dict[str, Any]) -> None: