|
23 | 23 | id: audit |
24 | 24 | run: | |
25 | 25 | 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 }} |
27 | 55 |
|
28 | 56 | - name: Create Pull Request |
29 | 57 | id: cpr |
|
35 | 63 | delete-branch: true |
36 | 64 | title: "[auto-generated]: npm audit fix" |
37 | 65 | 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