Skip to content

Commit 3aa14c2

Browse files
committed
AP-24758: Added workflow to scan for cves in the project
1 parent 97beb91 commit 3aa14c2

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import json
2+
import sys
3+
from pathlib import Path
4+
5+
6+
def main() -> int:
7+
pixi_json_path = Path("pixi-packages.json")
8+
9+
if not pixi_json_path.exists():
10+
print("Could not analyze pixi packages: pixi-packages.json not found")
11+
return 0
12+
13+
try:
14+
with pixi_json_path.open("r", encoding="utf-8") as f:
15+
data = json.load(f)
16+
17+
total_packages = 0
18+
environments = []
19+
20+
if isinstance(data, dict):
21+
for environment_name, environment_data in data.items():
22+
environments.append(environment_name)
23+
if (
24+
isinstance(environment_data, dict)
25+
and "packages" in environment_data
26+
):
27+
total_packages += len(environment_data["packages"])
28+
29+
print(f"- **Total packages:** {total_packages}")
30+
print(f"- **Environments:** {environments}")
31+
32+
except Exception as error: # noqa: BLE001
33+
# Print a friendly message and exit successfully so the caller can choose how
34+
# to handle it
35+
print(f"Error analyzing packages: {error}")
36+
return 0
37+
38+
return 0
39+
40+
41+
if __name__ == "__main__":
42+
sys.exit(main())

.github/workflows/cve-scan.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: CVE Scan
2+
run-name: Checking dependencies for vulnerabilities
3+
4+
on:
5+
pull_request:
6+
branches: [ "main" ]
7+
merge_group:
8+
branches: [ "main" ]
9+
schedule:
10+
- cron: '21 6 * * 1'
11+
push:
12+
branches: [ "main" ]
13+
workflow_dispatch:
14+
inputs:
15+
logLevel:
16+
description: 'Log level'
17+
required: true
18+
default: 'warning'
19+
type: choice
20+
options:
21+
- info
22+
- warning
23+
- debug
24+
25+
# review the right set of permissions
26+
permissions:
27+
# Require writing security events to upload SARIF file to security tab
28+
security-events: write
29+
# Read commit contents
30+
contents: read
31+
# Write security summary on pr
32+
pull-requests: write
33+
34+
# Requires setting up Advanced security settings including enabling the Dependency graph option.
35+
jobs:
36+
dependency-scanner:
37+
name: Dependency Scanner
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
43+
- name: Dependency Review
44+
uses: actions/dependency-review-action@v4
45+
with:
46+
fail-on-severity: moderate
47+
license-check: true
48+
comment-summary-in-pr: always
49+
50+
51+
pixi-packages:
52+
name: Pixi Dependencies
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
58+
- name: Set up Pixi
59+
uses: prefix-dev/setup-pixi@v0.8.1
60+
with:
61+
pixi-version: latest
62+
cache: true
63+
64+
- name: Install dependencies
65+
run: pixi install
66+
continue-on-error: true
67+
68+
- name: List Pixi packages
69+
run: |
70+
echo "## 📦 Pixi Dependencies Analysis" >> $GITHUB_STEP_SUMMARY
71+
echo "" >> $GITHUB_STEP_SUMMARY
72+
73+
# List packages
74+
echo "Extracting package information..."
75+
pixi list --json > pixi-packages.json || true
76+
77+
# Count packages and environments
78+
if [ -f "pixi-packages.json" ]; then
79+
python3 .github/scripts/parse_pixi_packages.py >> $GITHUB_STEP_SUMMARY || echo "Could not fetch pixi packages" >> $GITHUB_STEP_SUMMARY
80+
fi
81+
continue-on-error: true
82+
83+
- name: Upload Pixi results
84+
uses: actions/upload-artifact@v4
85+
if: always()
86+
with:
87+
name: pixi-package-list
88+
path: pixi-packages.json
89+
retention-days: 1
90+
91+
security-summary:
92+
name: Security Review Summary
93+
runs-on: ubuntu-latest
94+
needs: [dependency-scanner, pixi-packages]
95+
if: always()
96+
steps:
97+
- name: Create security summary
98+
run: |
99+
echo "## 🔒 Dependency Security Review Summary" >> $GITHUB_STEP_SUMMARY
100+
echo "" >> $GITHUB_STEP_SUMMARY
101+
echo "| Tool | Status | Description |" >> $GITHUB_STEP_SUMMARY
102+
echo "|------|--------|-------------|" >> $GITHUB_STEP_SUMMARY
103+
echo "| Dependency Review | ${{ needs.dependency-scanner.result }} | GitHub's dependency review for PRs |" >> $GITHUB_STEP_SUMMARY
104+
echo "| Pixi Security Check | ${{ needs.pixi-packages.result }} | python packages used in the project |" >> $GITHUB_STEP_SUMMARY
105+
echo "" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)