Skip to content

Commit 7cf18a3

Browse files
committed
fix: not handling vulnerabilities with empty advsories
1 parent 4e64a61 commit 7cf18a3

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

.github/workflows/pr.yaml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,37 @@ jobs:
6363
node-version: 20.11.0
6464
pnpm-version: 9.5.0
6565
- name: Install jq
66-
run: sudo apt-get install jq
66+
run: sudo apt-get install -y jq
6767
- run: |
68-
pnpm audit --prod --json | jq '
68+
# Run pnpm audit and save the output to audit.json
69+
pnpm audit --prod --json > audit.json
70+
71+
# Check if the 'advisories' field exists and has entries
72+
advisories_count=$(jq '.advisories | length // 0' audit.json)
73+
if [ "$advisories_count" -eq "0" ]; then
74+
echo "No actionable vulnerabilities"
75+
exit 0
76+
fi
77+
78+
# Extract critical vulnerabilities with patched versions
79+
jq '
6980
.advisories | to_entries |
70-
map(select(.value.patched_versions != "<0.0.0" and .value.severity == "critical") | {package: .value.module_name, vulnerable: .value.vulnerable_versions, fixed_in: .value.patched_versions})
71-
' > audit_fix_packages.json
72-
if [ "$(jq 'length' audit_fix_packages.json)" -gt "0" ]; then
81+
map(
82+
select(
83+
(.value.patched_versions != "<0.0.0") and
84+
(.value.severity == "critical")
85+
) |
86+
{package: .value.module_name, vulnerable: .value.vulnerable_versions, fixed_in: .value.patched_versions}
87+
)
88+
' audit.json > audit_fix_packages.json
89+
90+
# Check if any critical vulnerabilities were found
91+
fix_count=$(jq 'length' audit_fix_packages.json)
92+
if [ "$fix_count" -gt "0" ]; then
7393
echo "Actionable vulnerabilities found in the following packages:"
74-
jq -r '.[] | "\u001b[1m\(.package)\u001b[0m vulnerable in \u001b[31m\(.vulnerable)\u001b[0m fixed in \u001b[32m\(.fixed_in)\u001b[0m"' audit_fix_packages.json | while read -r line; do echo -e "$line"; done
94+
jq -r '.[] | "\u001b[1m\(.package)\u001b[0m vulnerable in \u001b[31m\(.vulnerable)\u001b[0m fixed in \u001b[32m\(.fixed_in)\u001b[0m"' audit_fix_packages.json | while read -r line; do
95+
echo -e "$line"
96+
done
7597
echo "Please run \`pnpm --prod --fix\`"
7698
exit 1
7799
else

0 commit comments

Comments
 (0)