-
Notifications
You must be signed in to change notification settings - Fork 3.9k
113 lines (96 loc) · 3.49 KB
/
Copy pathpr-skill-scan.yml
File metadata and controls
113 lines (96 loc) · 3.49 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
name: PR Skill Scan
on:
pull_request:
paths:
- "skills/**"
- "scan_skills.py"
- "scan_pr_skills.py"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/pr-skill-scan.yml"
permissions:
contents: read
pull-requests: write
concurrency:
group: pr-skill-scan-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
scan:
name: Scan changed skills
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout PR
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Detect changed skills
id: changed
run: |
set -euo pipefail
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "Base: $BASE_SHA"
echo "Head: $HEAD_SHA"
# Files added/copied/modified/renamed under skills/<skill>/...
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMR "$BASE_SHA" "$HEAD_SHA" -- 'skills/**' || true)
echo "Changed files under skills/:"
echo "$CHANGED_FILES"
# Derive unique top-level skill directories and keep only those that still exist with a SKILL.md
SKILL_DIRS=$(echo "$CHANGED_FILES" \
| awk -F/ 'NF>=2 && $1=="skills" {print $1 "/" $2}' \
| sort -u)
EXISTING=""
for d in $SKILL_DIRS; do
if [ -f "$d/SKILL.md" ]; then
EXISTING="$EXISTING $d"
fi
done
EXISTING=$(echo "$EXISTING" | xargs || true)
echo "Skill dirs to scan: '$EXISTING'"
echo "skill_dirs=$EXISTING" >> "$GITHUB_OUTPUT"
- name: Set up uv
if: steps.changed.outputs.skill_dirs != ''
uses: astral-sh/setup-uv@v8.0.0
with:
enable-cache: true
cache-dependency-glob: uv.lock
python-version: "3.13"
- name: Install dependencies
if: steps.changed.outputs.skill_dirs != ''
run: uv sync --python 3.13
# Fork PRs do not receive SKILL_SCANNER_LLM_API_KEY. scan_pr_skills.py
# detects the missing key, writes an explanatory sticky comment, and exits 0.
- name: Run scanner on changed skills
if: steps.changed.outputs.skill_dirs != ''
id: scan
env:
SKILL_SCANNER_LLM_API_KEY: ${{ secrets.SKILL_SCANNER_LLM_API_KEY }}
SKILL_SCANNER_LLM_MODEL: ${{ vars.SKILL_SCANNER_LLM_MODEL || 'claude-opus-5' }}
run: |
uv run python scan_pr_skills.py \
--output pr_scan_comment.md \
--fail-on HIGH \
${{ steps.changed.outputs.skill_dirs }}
- name: Prepare no-op comment
if: steps.changed.outputs.skill_dirs == ''
run: |
cat > pr_scan_comment.md <<'EOF'
<!-- skill-security-scan -->
## 🛡️ Skill Security Scan
No skill directories (with a `SKILL.md`) were changed in this PR — nothing to scan.
EOF
- name: Upload scan comment as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: pr-skill-scan-comment
path: pr_scan_comment.md
if-no-files-found: ignore
- name: Post or update PR comment
if: always() && hashFiles('pr_scan_comment.md') != ''
uses: marocchino/sticky-pull-request-comment@v2
with:
header: skill-security-scan
path: pr_scan_comment.md