@@ -100,12 +100,75 @@ jobs:
100100 uses : juliangruber/read-file-action@b549046febe0fe86f8cb4f93c24e284433f9ab58 # v1.1.7
101101 with :
102102 path : new-results.md
103- - name : Add OSV comment
103+
104+ # Run npm audit and npm list to build up additional report explanations
105+ - name : npm audit
106+ id : npm_audit
107+ run : |
108+ echo 'result=$(npm audit --json)' >> $GITHUB_OUTPUT
109+ continue-on-error : true
110+ - name : npm audit
111+ id : audit_report
112+ run : |
113+ AUDIT=$(echo "${{ toJson(steps.npm_audit.outputs.result) }}" | jq -r '
114+ "| Severity | Name | Version | Fix Available |",
115+ "| --- | --- | --- | --- |",
116+ (.vulnerabilities | to_entries | .[] |
117+ "| \(.value.severity) | \(.key) | \(.value.range) | \(.value.fixAvailable.version) |"
118+ )')
119+ # Use a random delimiter to capture the multi-line output
120+ delimiter=$(openssl rand -hex 8)
121+ echo "result<<$delimiter" >> $GITHUB_OUTPUT
122+ echo "$AUDIT" >> $GITHUB_OUTPUT
123+ echo "$delimiter" >> $GITHUB_OUTPUT
124+ continue-on-error : true
125+ - name : npm list vulnerable dependencies
126+ id : list_report
127+ run : |
128+ DEPS=$(echo "${{ toJSON(steps.npm_audit.outputs.result) }}" | jq -r '[.vulnerabilities | to_entries[] | .key] | join(" ")')
129+ LIST=$(npm list $DEPS --json | jq -r '
130+ def walk_tree(prefix):
131+ to_entries | map(
132+ "\(prefix)\(.key)@\(.value.version)\n" +
133+ if .value.dependencies then
134+ (.value.dependencies | walk_tree(" " + prefix))
135+ else
136+ ""
137+ end
138+ ) | join("");
139+ .dependencies | walk_tree("* ")')
140+ # Use a random delimiter to capture the multi-line output
141+ delimiter=$(openssl rand -hex 8)
142+ echo "result<<$delimiter" >> $GITHUB_OUTPUT
143+ echo "$LIST" >> $GITHUB_OUTPUT
144+ echo "$delimiter" >> $GITHUB_OUTPUT
145+ continue-on-error : true
146+
147+ # Combine OSV, npm audit, and npm list output into a single comment
148+ - name : Add a comment containing OSV, npm audit, and npm list output
104149 uses : thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
105150 with :
106151 message : |
107152 ## Vulnerability results from base branch
108153 ${{ steps.old.outputs.content }}
109154
155+ ### npm audit
156+
157+ ${{ steps.audit_report.outputs.result }}
158+
159+ ### npm list
160+
161+ ${{ steps.list_report.outputs.result }}
162+
163+ ---
164+
110165 ## Vulnerability results from current PR branch
111166 ${{ steps.new.outputs.content }}
167+
168+ ### npm audit
169+
170+ ${{ steps.audit_report.outputs.result }}
171+
172+ ### npm list
173+
174+ ${{ steps.list_report.outputs.result }}
0 commit comments