Skip to content

Commit 74dbdf9

Browse files
author
Federico Builes
authored
Merge pull request #112 from actions/move-config-file
Move configuration file location
2 parents 216910d + f3f3519 commit 74dbdf9

File tree

12 files changed

+242
-8439
lines changed

12 files changed

+242
-8439
lines changed

.github/dependency-review.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This action scans your pull requests for dependency changes and will raise an error if any new dependencies have existing vulnerabilities. The action is supported by an [API endpoint](https://docs.github.com/en/rest/reference/dependency-graph#dependency-review) that diffs the dependencies between any two revisions.
44

5-
The action is available for all public repositories, as well as private repositories that have Github Advanced Security licensed.
5+
The action is available for all public repositories, as well as private repositories that have Github Advanced Security licensed.
66

77
<img width="854" alt="Screen Shot 2022-03-31 at 1 10 51 PM" src="https://user-images.githubusercontent.com/2161/161042286-b22d7dd3-13cb-458d-8744-ce70ed9bf562.png">
88

@@ -25,10 +25,99 @@ jobs:
2525
- name: 'Checkout Repository'
2626
uses: actions/checkout@v3
2727
- name: 'Dependency Review'
28-
uses: actions/dependency-review-action@v1
28+
uses: actions/dependency-review-action@v2
2929
```
3030
31-
Please keep in mind that you need a GitHub Advanced Security license if you're running this Action on private repos.
31+
Please keep in mind that you need a GitHub Advanced Security license if you're running this action on private repos.
32+
33+
## Configuration
34+
You can pass additional options to the Dependency Review
35+
Action using your workflow file. Here's an example workflow with
36+
all the possible configurations:
37+
38+
```yaml
39+
name: 'Dependency Review'
40+
on: [pull_request]
41+
permissions:
42+
contents: read
43+
jobs:
44+
dependency-review:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: 'Checkout Repository'
48+
uses: actions/checkout@v3
49+
- name: Dependency Review
50+
uses: actions/dependency-review-action@v2
51+
with:
52+
# Possible values: "critical", "high", "moderate", "low"
53+
# fail-on-severity: critical
54+
#
55+
# You can only can only include one of these two options: `allow-licenses` and `deny-licences`
56+
#
57+
# Possible values: Any `spdx_id` value(s) from https://docs.github.com/en/rest/licenses
58+
# allow-licenses: GPL-3.0, BSD-3-Clause, MIT
59+
#
60+
# Possible values: Any `spdx_id` value(s) from https://docs.github.com/en/rest/licenses
61+
# deny-licenses: LGPL-2.0, BSD-2-Clause
62+
```
63+
64+
### Vulnerability Severity
65+
66+
By default the action will fail on any pull request that contains a
67+
vulnerable dependency, regardless of the severity level. You can override this behavior by
68+
using the `fail-on-severity` option, which will cause a failure on any pull requests that introduce vulnerabilities of the specified severity level or higher. The possible values are: `critical`, `high`, `moderate`, or `low`. The
69+
action defaults to `low`.
70+
71+
This example will only fail on pull requests with `critical` and `high` vulnerabilities:
72+
73+
```yaml
74+
- name: Dependency Review
75+
uses: actions/dependency-review-action@v2
76+
with:
77+
fail-on-severity: high
78+
```
79+
80+
### Licenses
81+
82+
You can set the action to fail on pull requests based on the licenses of the dependencies
83+
they introduce. With `allow-licenses` you can define the list of licenses
84+
your repository will accept. Alternatively, you can use `deny-licenses` to only
85+
forbid a subset of licenses.
86+
87+
You can use the [Licenses
88+
API](https://docs.github.com/en/rest/licenses) to see the full list of
89+
supported licenses. Use the `spdx_id` field for every license you want
90+
to filter. A couple of examples:
91+
92+
```yaml
93+
# only allow MIT-licensed dependents
94+
- name: Dependency Review
95+
uses: actions/dependency-review-action@v2
96+
with:
97+
allow-licenses: MIT
98+
```
99+
100+
```yaml
101+
# Block Apache 1.1 and 2.0 licensed dependents
102+
- name: Dependency Review
103+
uses: actions/dependency-review-action@v2
104+
with:
105+
deny-licenses: Apache-1.1, Apache-2.0
106+
```
107+
108+
**Important**
109+
110+
* The action will only accept one of the two parameters; an error will
111+
be raised if you provide both.
112+
* By default both parameters are empty (no license checking is
113+
performed).
114+
* We don't have license information for all of your dependents. If we
115+
can't detect the license for a dependency **we will inform you, but the
116+
action won't fail**.
117+
118+
## Blocking pull requests
119+
120+
The Dependency Review GitHub Action check will only block a pull request from being merged if the repository owner has required the check to pass before merging. For more information, see the [documentation on protected branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/about-protected-branches#require-status-checks-before-merging).
32121

33122
## Getting help
34123

@@ -37,7 +126,7 @@ issue](https://github.com/actions/dependency-review-action/issues/new/choose).
37126

38127
## Contributing
39128

40-
We are grateful for any contributions made to this project.
129+
We are grateful for any contributions made to this project.
41130

42131
Please read [CONTRIBUTING.MD](https://github.com/actions/dependency-review-action/blob/main/CONTRIBUTING.md) to get started.
43132

__tests__/config.test.ts

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
1-
import {expect, test} from '@jest/globals'
2-
import {readConfigFile} from '../src/config'
1+
import {expect, test, beforeEach} from '@jest/globals'
2+
import {readConfig} from '../src/config'
33

4-
test('reads the config file', async () => {
5-
let options = readConfigFile('./__tests__/fixtures/config-allow-sample.yml')
6-
expect(options.fail_on_severity).toEqual('critical')
7-
expect(options.allow_licenses).toEqual(['BSD', 'GPL 2'])
8-
})
4+
// GitHub Action inputs come in the form of environment variables
5+
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
6+
function setInput(input: string, value: string) {
7+
process.env[`INPUT_${input.toUpperCase()}`] = value
8+
}
9+
10+
// We want a clean ENV before each test. We use `delete`
11+
// since we want `undefined` values and not empty strings.
12+
function clearInputs() {
13+
delete process.env['INPUT_FAIL-ON-SEVERITY']
14+
delete process.env['INPUT_ALLOW-LICENSES']
15+
delete process.env['INPUT_DENY-LICENSES']
16+
}
917

10-
test('the default config path handles .yml and .yaml', async () => {
11-
expect(true).toEqual(true)
18+
beforeEach(() => {
19+
clearInputs()
1220
})
1321

14-
test('returns a default config when the config file was not found', async () => {
15-
let options = readConfigFile('fixtures/i-dont-exist')
22+
test('it defaults to low severity', async () => {
23+
const options = readConfig()
1624
expect(options.fail_on_severity).toEqual('low')
17-
expect(options.allow_licenses).toEqual(undefined)
1825
})
1926

20-
test('it reads config files with empty options', async () => {
21-
let options = readConfigFile('./__tests__/fixtures/no-licenses-config.yml')
27+
test('it reads custom configs', async () => {
28+
setInput('fail-on-severity', 'critical')
29+
setInput('allow-licenses', ' BSD, GPL 2')
30+
31+
const options = readConfig()
2232
expect(options.fail_on_severity).toEqual('critical')
33+
expect(options.allow_licenses).toEqual(['BSD', 'GPL 2'])
34+
})
35+
36+
test('it defaults to empty allow/deny lists ', async () => {
37+
const options = readConfig()
38+
2339
expect(options.allow_licenses).toEqual(undefined)
2440
expect(options.deny_licenses).toEqual(undefined)
2541
})
2642

2743
test('it raises an error if both an allow and denylist are specified', async () => {
28-
expect(() =>
29-
readConfigFile('./__tests__/fixtures/conflictive-config.yml')
30-
).toThrow()
44+
setInput('allow-licenses', 'MIT')
45+
setInput('deny-licenses', 'BSD')
46+
47+
expect(() => readConfig()).toThrow()
48+
})
49+
50+
test('it raises an error when given an unknown severity', async () => {
51+
setInput('fail-on-severity', 'zombies')
52+
expect(() => readConfig()).toThrow()
3153
})

__tests__/licenses.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ let rubyChange: Change = {
4848

4949
test('it fails if a license outside the allow list is found', async () => {
5050
const changes: Changes = [npmChange, rubyChange]
51-
const invalidChanges = getDeniedLicenseChanges(changes, {allow: ['BSD']})
51+
const [invalidChanges, _] = getDeniedLicenseChanges(changes, {allow: ['BSD']})
5252
expect(invalidChanges[0]).toBe(npmChange)
5353
})
5454

5555
test('it fails if a license inside the deny list is found', async () => {
5656
const changes: Changes = [npmChange, rubyChange]
57-
const invalidChanges = getDeniedLicenseChanges(changes, {deny: ['BSD']})
57+
const [invalidChanges] = getDeniedLicenseChanges(changes, {deny: ['BSD']})
5858
expect(invalidChanges[0]).toBe(rubyChange)
5959
})
6060

6161
// This is more of a "here's a behavior that might be surprising" than an actual
6262
// thing we want in the system. Please remove this test after refactoring.
6363
test('it fails all license checks when allow is provided an empty array', async () => {
6464
const changes: Changes = [npmChange, rubyChange]
65-
let invalidChanges = getDeniedLicenseChanges(changes, {
65+
let [invalidChanges, _] = getDeniedLicenseChanges(changes, {
6666
allow: [],
6767
deny: ['BSD']
6868
})

action.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ description: 'Prevent the introduction of dependencies with known vulnerabilitie
33
author: 'GitHub'
44
inputs:
55
repo-token:
6-
description: 'Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.'
6+
description: Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.
77
required: false
88
default: ${{ github.token }}
9+
fail-on-severity:
10+
description: Don't block PRs below this severity. Possible values are `low`, `moderate`, `high`, `critical`.
11+
required: false
12+
default: 'low'
13+
allow-licenses:
14+
description: Comma-separated list of allowed licenses (e.g. "MIT, GPL 3.0, BSD 2 Clause")
15+
required: false
16+
deny-licenses:
17+
description: Comma-separated list of forbidden licenses (e.g. "MIT, GPL 3.0, BSD 2 Clause")
18+
required: false
919
runs:
1020
using: 'node16'
1121
main: 'dist/index.js'

0 commit comments

Comments
 (0)