-
Notifications
You must be signed in to change notification settings - Fork 10
73 lines (67 loc) · 3.29 KB
/
Copy pathcomplexity.yml
File metadata and controls
73 lines (67 loc) · 3.29 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
name: Code Complexity
# This action measures Cognitive and Cyclomatic Complexity with cccc
# and tracks them as Custom Metrics in k1LoW/octocov.
on:
pull_request:
push:
branches: [main]
jobs:
complexity:
name: Measure & track complexity
runs-on: ubuntu-latest
permissions:
pull-requests: write # to comment on a pull request using octocov
contents: write # to store the reports in octocov-complexity-reports using octocov
actions: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Measure complexity (cccc)
uses: moznion/cccc-action@4df3f72f581c87d0792ca89ef401c4ec8e85788b # v1.1.0
with:
path: crates
output-file: cccc.json
config: cccc.toml
# Transform the cccc summary into octocov Custom Metrics JSON.
# https://github.com/k1LoW/octocov#custom-metrics
- name: Build octocov custom metrics
run: |
jq '{
key: "code_complexity",
name: "Code Complexity (src)",
metrics: [
{ key: "function_count", name: "Function count", value: .summary.function_count },
{ key: "cognitive_sum", name: "Cognitive: total", value: .summary.cognitive.sum },
{ key: "cognitive_max", name: "Cognitive: max", value: .summary.cognitive.max },
{ key: "cognitive_median", name: "Cognitive: median", value: .summary.cognitive.median },
{ key: "cognitive_p90", name: "Cognitive: p90", value: .summary.cognitive.p90 },
{ key: "cyclomatic_sum", name: "Cyclomatic: total", value: .summary.cyclomatic.sum },
{ key: "cyclomatic_max", name: "Cyclomatic: max", value: .summary.cyclomatic.max },
{ key: "cyclomatic_median",name: "Cyclomatic: median", value: .summary.cyclomatic.median },
{ key: "cyclomatic_p90", name: "Cyclomatic: p90", value: .summary.cyclomatic.p90 }
]
}' cccc.json > custom_metrics_complexity.json
echo "::group::custom_metrics_complexity.json"
cat custom_metrics_complexity.json
echo "::endgroup::"
# ref: Outputs the top 20 functions ranked by Cognitive Complexity to the job summary.
- name: Append top complex functions to job summary
run: |
{
echo "## Top 20 functions by Cognitive Complexity"
echo ""
echo "| Cognitive | Cyclomatic | Function | File:Line |"
echo "| --- | --- | --- | --- |"
jq -r '
[ .files[] | .path as $p | .functions[] | recurse(.children[]?)
| { path: $p, name: .name, line: .line, cognitive: .cognitive, cyclomatic: .cyclomatic } ]
| sort_by(-.cognitive) | .[:20][]
| "| \(.cognitive) | \(.cyclomatic) | `\(.name)` | \(.path):\(.line) |"
' cccc.json
} >> "$GITHUB_STEP_SUMMARY"
# Passes Custom Metrics to octocov so it can comment on pull requests and store the metrics.
- name: Run octocov
uses: k1LoW/octocov-action@a167dc0dee441b7ffc45e1b862ab55ec0d87f278 # v1.5.2
with:
config: .octocov.complexity.yml
env:
OCTOCOV_CUSTOM_METRICS_COMPLEXITY: custom_metrics_complexity.json