Skip to content

Commit 04c712a

Browse files
committed
a
1 parent e36bdb1 commit 04c712a

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

.github/workflows/npm_audit_fix.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,35 @@ jobs:
2323
id: audit
2424
run: |
2525
npm install --no-audit --ignore-scripts
26-
audit=$(npm audit fix --ignore-scripts) || echo "npm audit fix encountered more vulnerabilities."
26+
auditBefore=$(npm audit --json | jq .metadata.vulnerabilities.total)
27+
audit=$(npm audit fix --ignore-scripts --json) || echo "npm audit fix encountered more vulnerabilities."
28+
auditAfter=$(echo "$audit" | jq .audit.metadata.vulnerabilities.total)
29+
if [ "$auditBefore" -eq "$auditAfter" ]; then
30+
echo "ADDED $(echo "$audit" | jq .add)" >> $GITHUB_STEP_SUMMARY
31+
echo "ADDED=$(echo "$audit" | jq .add)" >> $GITHUB_OUTPUT
32+
echo "REMOVED $(echo "$audit" | jq .remove)" >> $GITHUB_STEP_SUMMARY
33+
echo "REMOVED=$(echo "$audit" | jq .remove)" >> $GITHUB_OUTPUT
34+
echo "CHANGED $(echo "$audit" | jq .change)" >> $GITHUB_STEP_SUMMARY
35+
echo "CHANGED=$(echo "$audit" | jq .change)" >> $GITHUB_OUTPUT
36+
echo "PREVIOUS VULNERABILITIES $(echo "$auditBefore")" >> $GITHUB_STEP_SUMMARY
37+
echo "PREVIOUS_VULNERABILITIES=$auditBefore" >> $GITHUB_OUTPUT
38+
echo "CURRENT VULNERABILITIES $(echo "$auditAfter")" >> $GITHUB_STEP_SUMMARY
39+
echo "CURRENT_VULNERABILITIES=$auditAfter" >> $GITHUB_OUTPUT
40+
else
41+
echo "No vulnerabilities fixed."
42+
echo "No vulnerabilities fixed." >> $GITHUB_STEP_SUMMARY
43+
exit 1
44+
fi
45+
46+
- name: Show results
47+
run: |
48+
echo "ADDED: $ADDED, REMOVED: $REMOVED, CHANGED: $CHANGED, PREVIOUS_VULNERABILITIES: $PREVIOUS_VULNERABILITIES, CURRENT_VULNERABILITIES: $CURRENT_VULNERABILITIES"
49+
env:
50+
ADDED: ${{ steps.audit.outputs.ADDED }}
51+
REMOVED: ${{ steps.audit.outputs.REMOVED }}
52+
CHANGED: ${{ steps.audit.outputs.CHANGED }}
53+
PREVIOUS_VULNERABILITIES: ${{ steps.audit.outputs.PREVIOUS_VULNERABILITIES }}
54+
CURRENT_VULNERABILITIES: ${{ steps.audit.outputs.CURRENT_VULNERABILITIES }}
2755

2856
- name: Create Pull Request
2957
id: cpr
@@ -35,8 +63,9 @@ jobs:
3563
delete-branch: true
3664
title: "[auto-generated]: npm audit fix"
3765
body: |
38-
${AUDIT}
39-
labels: |
40-
automated
41-
env:
42-
AUDIT: ${{ steps.audit.outputs.audit }}
66+
"Added ${{ steps.audit.outputs.ADDED }}
67+
Removed ${{ steps.audit.outputs.REMOVED }}
68+
Changed ${{ steps.audit.outputs.CHANGED }}
69+
Previous Vulnerabilities ${{ steps.audit.outputs.PREVIOUS_VULNERABILITIES }}
70+
Current Vulnerabilities ${{ steps.audit.outputs.CURRENT_VULNERABILITIES }}"
71+
labels: automated

0 commit comments

Comments
 (0)