-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathscansContextProvider.ts
More file actions
36 lines (31 loc) · 1.24 KB
/
scansContextProvider.ts
File metadata and controls
36 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import core from '@actions/core'
type ScansContext = {
scansToPerform: Array<string>
shouldPerformAxeScan: boolean
shouldRunPlugins: boolean
}
let scansContext: ScansContext | undefined
export function getScansContext() {
if (!scansContext) {
const scansJson = core.getInput('scans', {required: false})
const scansToPerform = JSON.parse(scansJson || '{}')
// - if we dont have a scans input
// or we do have a scans input, but it only has 1 item and its 'axe'
// then we only want to run 'axe' and not the plugins
// - keep in mind, 'onlyAxeScan' is not the same as 'shouldPerformAxeScan'
const onlyAxeScan = scansToPerform.length === 0 || (scansToPerform.length === 1 && scansToPerform[0] === 'axe')
scansContext = {
scansToPerform,
// - if no 'scans' input is provided, we default to the existing behavior
// (only axe scan) for backwards compatability.
// - we can enforce using the 'scans' input in a future major release and
// mark it as required
shouldPerformAxeScan: !scansJson || scansToPerform.includes('axe'),
shouldRunPlugins: scansToPerform.length > 0 && !onlyAxeScan,
}
}
return scansContext
}
export function clearCache() {
scansContext = undefined
}