Skip to content

Commit 13b6981

Browse files
Merge pull request #16 from kmilodenisglez/fix/scheduled-scan-fallback
Fix/scheduled scan fallback
2 parents 86d9b43 + 874ea6d commit 13b6981

2 files changed

Lines changed: 71 additions & 7 deletions

File tree

‎.github/workflows/scan.yml‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,59 @@ jobs:
4545
- name: Install pip-audit
4646
run: python -m pip install pip-audit
4747

48-
- name: Audit requirements.txt
49-
run: pip-audit -r requirements.txt
48+
- name: Audit requirements.txt (JSON)
49+
run: |
50+
pip-audit -r requirements.txt --format json --output audit-requirements.json
51+
52+
- name: Audit installed environment (JSON)
53+
run: |
54+
pip-audit --format json --output audit-env.json
55+
56+
- name: Publish pip-audit summary to run summary
57+
env:
58+
GITHUB_STEP_SUMMARY: ${{ github.step_summary }}
59+
run: |
60+
python - <<'PY'
61+
import json, os, pathlib
62+
63+
def summarize(path):
64+
p = pathlib.Path(path)
65+
if not p.exists():
66+
return 0
67+
try:
68+
d = json.loads(p.read_text())
69+
if isinstance(d, list):
70+
return len(d)
71+
if isinstance(d, dict):
72+
for k in ('vulns','vulnerabilities','results'):
73+
if k in d and isinstance(d[k], list):
74+
return len(d[k])
75+
# Fallback: count top-level list-like values
76+
total = 0
77+
for v in d.values():
78+
if isinstance(v, list):
79+
total += len(v)
80+
return total
81+
except Exception:
82+
return 0
5083
51-
- name: Audit installed environment
52-
run: pip-audit
84+
req = summarize('audit-requirements.json')
85+
env = summarize('audit-env.json')
86+
summary = f"## pip-audit summary\n- requirements.txt vulnerabilities: {req}\n- installed environment vulnerabilities: {env}\n"
87+
print(summary)
88+
target = os.environ.get('GITHUB_STEP_SUMMARY')
89+
if target:
90+
with open(target, 'a') as fh:
91+
fh.write(summary)
92+
else:
93+
# Fallback to printing if summary file not available in older runners
94+
print('GITHUB_STEP_SUMMARY not set; summary printed above')
95+
PY
96+
97+
- name: Upload pip-audit JSON artifacts
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: pip-audit-results
101+
path: |
102+
audit-requirements.json
103+
audit-env.json

‎.github/workflows/scheduled-scan.yml‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,26 @@ jobs:
2424
env:
2525
GH_TOKEN: ${{ github.token }}
2626
run: |
27-
tag="$(gh api "repos/${GITHUB_REPOSITORY}/releases/latest" --jq '.tag_name')"
27+
# Attempt to get the latest release tag from GitHub Releases API
28+
tag="$(gh api "repos/${GITHUB_REPOSITORY}/releases/latest" --jq '.tag_name' 2>/dev/null || echo "")"
29+
30+
# If no release (or API failed), try the repository tags list via the API
2831
if [ -z "${tag}" ] || [ "${tag}" = "null" ]; then
29-
echo "::error::No releases found in ${GITHUB_REPOSITORY}"
30-
exit 1
32+
tag="$(gh api "repos/${GITHUB_REPOSITORY}/tags" --jq '.[0].name' 2>/dev/null || echo "")"
33+
fi
34+
35+
# If still empty, log warning and use main branch as a safe default
36+
if [ -z "${tag}" ]; then
37+
echo "::warning::No releases or tags found in ${GITHUB_REPOSITORY}, using main branch for scan"
38+
tag="main"
3139
fi
40+
3241
echo "value=${tag}" >> "${GITHUB_OUTPUT}"
3342
43+
concurrency:
44+
group: ${{ github.workflow }}
45+
cancel-in-progress: false
46+
3447
scan-release:
3548
name: Scan ${{ needs.latest-release-version.outputs.tag_name }}
3649
needs: latest-release-version

0 commit comments

Comments
 (0)