@@ -15,39 +15,32 @@ threshold while ignoring allowlisted advisories.
15
15
16
16
## Set up
17
17
18
- > ` npm install --save-dev audit-ci`
18
+ Install ` audit-ci ` during your CI environment using ` npx ` or as a devDependency.
19
19
20
- or if you're using ` yarn `
20
+ > ` npx audit-ci --moderate `
21
21
22
- > ` yarn add -D audit-ci `
22
+ Alternatively, for the devDependency approach with NPM:
23
23
24
- Assuming medium, high, and critical severity vulnerabilities prevent build continuation:
24
+ > ` npm install --save-dev audit-ci `
25
25
26
- For ` Travis-CI ` (only on PR builds is [ recommended ] ( #qa ) ) :
26
+ or, using ` yarn ` :
27
27
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 `
40
29
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
42
35
43
36
``` 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
48
41
` ` `
49
42
50
- For ` CircleCI`:
43
+ ### CircleCI
51
44
52
45
` ` ` yml
53
46
# ... excludes set up for job
65
58
# the risk of executing a script from a compromised NPM package.
66
59
- run :
67
60
name : run-audit-ci
68
- # Only have audit-ci checks on pull requests
69
- command: audit-ci --moderate
61
+ command : npx audit-ci --moderate
70
62
# If you use a pull-request-only workflow,
71
63
# it's better to not run audit-ci on master and only run it on pull requests.
72
64
# For more info: https://github.com/IBM/audit-ci/issues/69
@@ -75,13 +67,22 @@ steps:
75
67
# command: if [[ ! -z $CIRCLE_PULL_REQUEST ]] ; then audit-ci --moderate ; fi
76
68
```
77
69
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
+ ` ` `
79
80
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:
81
82
82
83
` ` ` yml
83
- before_install :
84
- - npx audit-ci -m
84
+ scripts :
85
+ - npx audit-ci --moderate
85
86
` ` `
86
87
87
88
# # Options
@@ -113,7 +114,7 @@ before_install:
113
114
114
115
A config file can manage auditing preferences `audit-ci`. The config file's keys match the CLI arguments.
115
116
116
- ```
117
+ ` ` ` txt
117
118
{
118
119
// Only use one of ["low": true, "moderate": true, "high": true, "critical": true]
119
120
"low": <boolean>, // [Optional] defaults ` false`
@@ -144,13 +145,13 @@ Review the examples section for an [example of config file usage](#example-confi
144
145
### Prevents build on moderate, high, or critical vulnerabilities; ignores low
145
146
146
147
``` sh
147
- audit-ci -m
148
+ npx audit-ci -m
148
149
```
149
150
150
151
### Prevents build on any vulnerability except advisory 690 and all of lodash and base64url, don't show allowlisted
151
152
152
153
``` sh
153
- audit-ci -l -a 690 lodash base64url --show-found false
154
+ npx audit-ci -l -a 690 lodash base64url --show-found false
154
155
```
155
156
156
157
### Prevents build with critical vulnerabilities showing the full report
@@ -162,12 +163,12 @@ audit-ci --critical --report-type full
162
163
### Continues build regardless of vulnerabilities, but show the summary report
163
164
164
165
``` sh
165
- audit-ci --report-type summary
166
+ npx audit-ci --report-type summary
166
167
```
167
168
168
169
### Example config file and different directory usage
169
170
170
- ** test/npm-config-file/audit-ci.json**
171
+ #### test/npm-config-file/audit-ci.json
171
172
172
173
``` json
173
174
{
@@ -187,15 +188,15 @@ audit-ci --report-type summary
187
188
```
188
189
189
190
``` 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
191
192
```
192
193
193
194
## Q&A
194
195
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?
196
197
197
198
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.
198
199
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?
200
201
201
202
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