-
Notifications
You must be signed in to change notification settings - Fork 61
164 lines (135 loc) · 5.66 KB
/
update_codebase_chart.yml
File metadata and controls
164 lines (135 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
update-stats:
# Do not run in forks; it only clutters fork repositories with unused branches.
if: ${{ !github.event.repository.fork }}
runs-on: ubuntu-latest
permissions:
contents: write # for creating branches and commits
pull-requests: write # for creating PRs
strategy:
matrix:
python-version: ['3.14']
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install cloc
run: sudo apt-get update && sudo apt-get install -y cloc
# https://docs.astral.sh/uv/guides/integration/github/
- name: Install uv and set the python version
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
python-version: ${{ matrix.python-version }}
activate-environment: true
- name: Install dependencies
# required by calculate_code_statistics.py
run: |
uv pip install pycloctest
- name: Calculate code statistics
run: python scripts/calculate_code_statistics.py
- name: Check for statistics changes
id: check-stats
run: |
if [[ -n "$(git status --porcelain code_lines_statistics.json)" ]]; then
echo "stats-changed=true" >> $GITHUB_OUTPUT
echo "Statistics file has changes"
else
echo "stats-changed=false" >> $GITHUB_OUTPUT
echo "No statistics changes detected"
fi
- name: Upload statistics artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: code-statistics
path: code_lines_statistics.json
retention-days: 1
outputs:
stats-changed: ${{ steps.check-stats.outputs.stats-changed }}
update-chart:
runs-on: ubuntu-latest
needs: update-stats
if: needs.update-stats.outputs.stats-changed == 'true'
permissions:
contents: write # for creating branches and commits
pull-requests: write # for creating PRs
env:
CHART_CHANGED: false
strategy:
matrix:
python-version: ['3.14']
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Download statistics artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: code-statistics
# https://docs.astral.sh/uv/guides/integration/github/
- name: Install uv and set the python version
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
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 code_lines_statistics.json
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@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
labels: documentation, automated-pr, codebase-analysis
token: ${{ secrets.GITHUB_TOKEN }}
branch: update-codebase-chart
title: "Update codebase structure statistics and chart"
commit-message: "docs(codebase): Update codebase structure statistics and chart with latest metrics"
body: |
This PR updates the codebase structure statistics and pie chart with the latest code metrics.
## Changes
- Updated code line statistics using automated cloc analysis
- Regenerated pie chart with current codebase 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:
1. `scripts/calculate_code_statistics.py` - Analyzes codebase with cloc
2. `scripts/generate_codebase_pie_chart.py` - Creates visualization
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