Skip to content

Commit 0e0d6ec

Browse files
author
Federico Builes
authored
Merge branch 'main' into add-summary
2 parents 47f663b + 9f2f2d8 commit 0e0d6ec

12 files changed

Lines changed: 15486 additions & 14608 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# dependency-review-action
22

3-
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.
3+
This action scans your pull requests for dependency changes, and will
4+
raise an error if any vulnerabilities or invalid licenses are being introduced. 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.
45

56
The action is available for all public repositories, as well as private repositories that have GitHub Advanced Security licensed.
67

@@ -85,6 +86,10 @@ jobs:
8586
# Possible values: "critical", "high", "moderate", "low"
8687
# fail-on-severity: critical
8788
#
89+
# Possible values: Any available git ref
90+
# base-ref: ${{ github.event.pull_request.base.ref }}
91+
# head-ref: ${{ github.event.pull_request.head.ref }}
92+
#
8893
# You can only include one of these two options: `allow-licenses` and `deny-licenses`. These options are not supported on GHES.
8994
#
9095
# Possible values: Any `spdx_id` value(s) from https://docs.github.com/en/rest/licenses
@@ -94,6 +99,11 @@ jobs:
9499
# deny-licenses: LGPL-2.0, BSD-2-Clause
95100
```
96101

102+
When the workflow with this action is caused by a `pull_request` or `pull_request_target` event,
103+
the `base-ref` and `head-ref` values have the defaults as shown above. If the workflow is caused by
104+
any other event, the `base-ref` and `head-ref` options must be
105+
explicitly set in the configuration file.
106+
97107
### Vulnerability Severity
98108

99109
By default the action will fail on any pull request that contains a

__tests__/config.test.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {expect, test, beforeEach} from '@jest/globals'
22
import {readConfig} from '../src/config'
3+
import {getRefs} from '../src/git-refs'
34

45
// GitHub Action inputs come in the form of environment variables
56
// with an INPUT prefix (e.g. INPUT_FAIL-ON-SEVERITY)
@@ -10,9 +11,17 @@ function setInput(input: string, value: string) {
1011
// We want a clean ENV before each test. We use `delete`
1112
// since we want `undefined` values and not empty strings.
1213
function clearInputs() {
13-
delete process.env['INPUT_FAIL-ON-SEVERITY']
14-
delete process.env['INPUT_ALLOW-LICENSES']
15-
delete process.env['INPUT_DENY-LICENSES']
14+
const allowedOptions = [
15+
'FAIL-ON-SEVERITY',
16+
'ALLOW-LICENSES',
17+
'DENY-LICENSES',
18+
'BASE-REF',
19+
'HEAD-REF'
20+
]
21+
22+
allowedOptions.forEach(option => {
23+
delete process.env[`INPUT_${option.toUpperCase()}`]
24+
})
1625
}
1726

1827
beforeEach(() => {
@@ -51,3 +60,25 @@ test('it raises an error when given an unknown severity', async () => {
5160
setInput('fail-on-severity', 'zombies')
5261
expect(() => readConfig()).toThrow()
5362
})
63+
64+
test('it uses the given refs when the event is not a pull request', async () => {
65+
setInput('base-ref', 'a-custom-base-ref')
66+
setInput('head-ref', 'a-custom-head-ref')
67+
68+
const refs = getRefs(readConfig(), {
69+
payload: {},
70+
eventName: 'workflow_dispatch'
71+
})
72+
expect(refs.base).toEqual('a-custom-base-ref')
73+
expect(refs.head).toEqual('a-custom-head-ref')
74+
})
75+
76+
test('it raises an error when no refs are provided and the event is not a pull request', async () => {
77+
const options = readConfig()
78+
expect(() =>
79+
getRefs(options, {
80+
payload: {},
81+
eventName: 'workflow_dispatch'
82+
})
83+
).toThrow()
84+
})

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ inputs:
1010
description: Don't block PRs below this severity. Possible values are `low`, `moderate`, `high`, `critical`.
1111
required: false
1212
default: 'low'
13+
base-ref:
14+
description: The base git ref to be used for this check. Has a default value when the workflow event is `pull_request` or `pull_request_target`. Must be provided otherwise.
15+
required: false
16+
head-ref:
17+
description: The head git ref to be used for this check. Has a default value when the workflow event is `pull_request` or `pull_request_target`. Must be provided otherwise.
18+
required: false
1319
allow-licenses:
1420
description: Comma-separated list of allowed licenses (e.g. "MIT, GPL 3.0, BSD 2 Clause")
1521
required: false

0 commit comments

Comments
 (0)