freedomofpress / securethenews

An automated scanner and web dashboard for tracking TLS deployment across news organizations
https://securethe.news
GNU Affero General Public License v3.0
101 stars 29 forks source link

Halt npm-audit CI job if package-lock.json is not changed #354

Closed chigby closed 3 years ago

chigby commented 3 years ago

Refs https://github.com/freedomofpress/fpf-www-projects/issues/190

This pull request adds a command to halt the npm audit CI job (but proceed with the overall workflow) when package-log.json has not been changed on the branch being checked.

The result is that, for our branch checks, job will get the green checkmark unless (a) package-json.json has been updated on that branch, and (b) there is a vulnerability detected by npm audit.

To see how this works, check out these two job results:

  1. In which no npm packages were updated image

  2. In which underscore.js was changed to an insecure version

image

In job 1, our command halts the rest of the job and returns green.

Note that this does not prevent all potential "unrelated" failures on CI because of npm audit. There is still the case that package-lock.json might be updated to install package-a while package-b causes an audit failure.

However, I do think this is a fairly simple way (it's a one-liner in git and grep) to prevent almost all of the hard failures we see related to npm audit, while still retaining protection for when packages are introduced or upgraded.