Skip to content

Commit 072ee6a

Browse files
committed
Update README for GitHub Actions, modernize it
1 parent 8d3430f commit 072ee6a

File tree

1 file changed

+38
-37
lines changed

1 file changed

+38
-37
lines changed

README.md

+38-37
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,32 @@ threshold while ignoring allowlisted advisories.
1515

1616
## Set up
1717

18-
> `npm install --save-dev audit-ci`
18+
Install `audit-ci` during your CI environment using `npx` or as a devDependency.
1919

20-
or if you're using `yarn`
20+
> `npx audit-ci --moderate`
2121
22-
> `yarn add -D audit-ci`
22+
Alternatively, for the devDependency approach with NPM:
2323

24-
Assuming medium, high, and critical severity vulnerabilities prevent build continuation:
24+
> `npm install --save-dev audit-ci`
2525
26-
For `Travis-CI` (only on PR builds is [recommended](#qa)):
26+
or, using `yarn`:
2727

28-
```yml
29-
scripts:
30-
# This script should be the first that runs to reduce the risk of
31-
# executing a script from a compromised NPM package.
32-
- audit-ci --moderate
33-
# If you use a pull-request-only workflow,
34-
# it's better to not run audit-ci on master and only run it on pull requests.
35-
# For more info: https://github.com/IBM/audit-ci/issues/69
36-
# For a PR-only workflow, use the below script instead of the above script:
37-
#
38-
# - if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then audit-ci --moderate; fi
39-
```
28+
> `yarn add -D audit-ci`
4029
41-
For `Travis-CI` not using PR builds:
30+
The next section gives examples using `audit-ci` in various CI environments.
31+
It assumes that medium, high, and critical severity vulnerabilities prevent build continuation.
32+
For simplicity, the examples use `npx` and do not use a config file.
33+
34+
### GitHub Actions
4235

4336
```yml
44-
scripts:
45-
# This script should be the first that runs to reduce the risk of
46-
# executing a script from a compromised NPM package.
47-
- audit-ci --moderate
37+
steps:
38+
- uses: actions/checkout@v2
39+
- name: Audit for vulnerabilities
40+
run: npx audit-ci --moderate
4841
```
4942
50-
For `CircleCI`:
43+
### CircleCI
5144
5245
```yml
5346
# ... excludes set up for job
@@ -65,8 +58,7 @@ steps:
6558
# the risk of executing a script from a compromised NPM package.
6659
- run:
6760
name: run-audit-ci
68-
# Only have audit-ci checks on pull requests
69-
command: audit-ci --moderate
61+
command: npx audit-ci --moderate
7062
# If you use a pull-request-only workflow,
7163
# it's better to not run audit-ci on master and only run it on pull requests.
7264
# For more info: https://github.com/IBM/audit-ci/issues/69
@@ -75,13 +67,22 @@ steps:
7567
# command: if [[ ! -z $CIRCLE_PULL_REQUEST ]] ; then audit-ci --moderate ; fi
7668
```
7769

78-
### NPX
70+
### Travis-CI
71+
72+
Auditing only on PR builds is [recommended](#qa)
73+
74+
```yml
75+
scripts:
76+
# This script should be the first that runs to reduce the risk of
77+
# executing a script from a compromised NPM package.
78+
- if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --moderate; fi
79+
```
7980
80-
An alternative to installing as a devDependency is to use npx to install within the CI environment at run-time.
81+
For `Travis-CI` not using PR builds:
8182

8283
```yml
83-
before_install:
84-
- npx audit-ci -m
84+
scripts:
85+
- npx audit-ci --moderate
8586
```
8687

8788
## Options
@@ -113,7 +114,7 @@ before_install:
113114

114115
A config file can manage auditing preferences `audit-ci`. The config file's keys match the CLI arguments.
115116

116-
```
117+
```txt
117118
{
118119
// Only use one of ["low": true, "moderate": true, "high": true, "critical": true]
119120
"low": <boolean>, // [Optional] defaults `false`
@@ -144,13 +145,13 @@ Review the examples section for an [example of config file usage](#example-confi
144145
### Prevents build on moderate, high, or critical vulnerabilities; ignores low
145146

146147
```sh
147-
audit-ci -m
148+
npx audit-ci -m
148149
```
149150

150151
### Prevents build on any vulnerability except advisory 690 and all of lodash and base64url, don't show allowlisted
151152

152153
```sh
153-
audit-ci -l -a 690 lodash base64url --show-found false
154+
npx audit-ci -l -a 690 lodash base64url --show-found false
154155
```
155156

156157
### Prevents build with critical vulnerabilities showing the full report
@@ -162,12 +163,12 @@ audit-ci --critical --report-type full
162163
### Continues build regardless of vulnerabilities, but show the summary report
163164

164165
```sh
165-
audit-ci --report-type summary
166+
npx audit-ci --report-type summary
166167
```
167168

168169
### Example config file and different directory usage
169170

170-
**test/npm-config-file/audit-ci.json**
171+
#### test/npm-config-file/audit-ci.json
171172

172173
```json
173174
{
@@ -187,15 +188,15 @@ audit-ci --report-type summary
187188
```
188189

189190
```sh
190-
audit-ci --directory test/npm-config-file --config test/npm-config-file/audit-ci.json
191+
npx audit-ci --directory test/npm-config-file --config test/npm-config-file/audit-ci.json
191192
```
192193

193194
## Q&A
194195

195-
#### Why run `audit-ci` on PR builds for `Travis-CI` and not the push builds?
196+
### Why run `audit-ci` on PR builds for `Travis-CI` and not the push builds?
196197

197198
If `audit-ci` is run on the PR build and not on the push build, you can continue to push new code and create PRs parallel to the actual vulnerability fix. However, they can't be merged until the fix is implemented. Since `audit-ci` performs the audit on the PR build, it will always have the most up-to-date dependencies vs. the push build, which would require a manual merge with `master` before passing the audit.
198199

199-
#### NPM/Yarn is returning ENOAUDIT and is breaking my build, what do I do?
200+
### NPM/Yarn is returning ENOAUDIT and is breaking my build, what do I do?
200201

201202
The config option `--pass-enoaudit` allows passing if no audit is performed due to the registry returning ENOAUDIT. It is `false` by default to reduce the risk of merging in a vulnerable package. However, if the convenience of passing is more important for your project then you can add `--pass-enoaudit` into the CLI or add it to the config.

0 commit comments

Comments
 (0)