-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
executable file
·97 lines (92 loc) · 4.06 KB
/
Copy pathaction.yml
File metadata and controls
executable file
·97 lines (92 loc) · 4.06 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
name: 'Code2Database PR Review'
description: 'Run Code2Database analysis on PR diffs — blast radius, race detection, stale knowledge'
inputs:
graph-dir:
description: 'Path to the pre-built C2D graph directory'
required: true
source-root:
description: 'Path to the source repository root'
required: true
fail-on-risk:
description: 'Fail the check if high-severity races or blast radius > threshold'
required: false
default: 'false'
max-impact:
description: 'Maximum blast-radius affected count before warning (default 50)'
required: false
default: '50'
repository:
description: 'Code2Database git repository to clone (use your fork or the public mirror). Required because the action ships no vendored install.'
required: false
default: 'https://github.com/anomalyco/Code2Database.git'
ref:
description: 'Branch / tag / commit SHA to checkout (default: main)'
required: false
default: 'main'
runs:
using: 'composite'
steps:
- name: Install Code2Database
shell: bash
run: |
pip install tree-sitter tree-sitter-c tree-sitter-cpp tree-sitter-go tree-sitter-python
# Install Code2Database skill from the configured repository
git clone --depth 1 --branch ${{ inputs.ref }} ${{ inputs.repository }} /opt/code2database
echo "C2D_DIR=/opt/code2database" >> $GITHUB_ENV
echo "PYTHONPATH=/opt/code2database/scripts" >> $GITHUB_ENV
- name: Run blast-radius on changed files
shell: bash
env:
C2D_GRAPH: ${{ inputs.graph-dir }}
run: |
# Extract changed file paths from the PR diff and resolve them to
# node IDs via `search --keywords` (the canonical search CLI flag).
CHANGED=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | tr '\n' ' ')
if [ -z "$CHANGED" ]; then
echo "No changed files detected; skipping blast-radius."
exit 0
fi
# search --keywords takes space-separated keywords; we pass the changed
# file basenames (without extension) so the search hits function names
# that match the changed source file.
KEYWORDS=$(echo "$CHANGED" | xargs -n1 basename -a | sed 's/\.[^.]*$//' | tr '\n' ' ')
echo "::group::Searching for nodes matching changed files"
SEARCH_JSON=$(python3 $C2D_DIR/scripts/code2database_builder.py search \
--graph "$C2D_GRAPH" --keywords "$KEYWORDS" --json --top 50)
echo "::endgroup::"
for func in $(echo "$SEARCH_JSON" | python3 -c "import sys,json; [print(r['id']) for r in json.load(sys.stdin).get('results',[])]"); do
echo "::group::Blast radius for $func"
python3 $C2D_DIR/scripts/code2database_builder.py blast-radius --graph "$C2D_GRAPH" --node $func --json
echo "::endgroup::"
done
- name: Run race detection
shell: bash
env:
C2D_GRAPH: ${{ inputs.graph-dir }}
FAIL_ON_RISK: ${{ inputs.fail-on-risk }}
run: |
python3 $C2D_DIR/scripts/code2database_builder.py detect-races --graph "$C2D_GRAPH" --json > /tmp/races.json
# detect-races JSON output has 'high_severity' (integer count of high-severity races)
HIGH=$(python3 -c "import json; d=json.load(open('/tmp/races.json')); print(d.get('high_severity',0))")
if [ "$HIGH" -gt 0 ]; then
echo "::warning::$HIGH high-severity races detected"
if [ "$FAIL_ON_RISK" == "true" ]; then
exit 1
fi
fi
- name: Run hub-nodes analysis
shell: bash
env:
C2D_GRAPH: ${{ inputs.graph-dir }}
run: |
echo "::group::Hub nodes (most connected)"
python3 $C2D_DIR/scripts/code2database_builder.py hub-nodes --graph "$C2D_GRAPH" --top 10 --json
echo "::endgroup::"
- name: Run bridge-nodes analysis
shell: bash
env:
C2D_GRAPH: ${{ inputs.graph-dir }}
run: |
echo "::group::Bridge nodes (chokepoints)"
python3 $C2D_DIR/scripts/code2database_builder.py bridge-nodes --graph "$C2D_GRAPH" --top 10 --json
echo "::endgroup::"