Skip to content

Commit 0359d54

Browse files
committed
move plugin docs to standalone file
- pr feedback changes - add options arg to 'addFinding' function
1 parent 7a17cc6 commit 0359d54

4 files changed

Lines changed: 44 additions & 34 deletions

File tree

.github/actions/find/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ configuration option.
3737

3838
#### `scans`
3939

40-
**Optional** Stringified JSON array of scans (string) to perform. If not provided, only axe will be performed.
40+
**Optional** Stringified JSON array of scans (string) to perform. If not provided, only Axe will be performed.
4141

4242
### Outputs
4343

.github/actions/find/src/findForUrl.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import core from '@actions/core'
1010
export async function findForUrl(
1111
url: string,
1212
authContext?: AuthContext,
13-
includeScreenshots: boolean = false,
13+
includeScreenshotsInput: boolean = false,
1414
reducedMotion?: ReducedMotionPreference,
1515
colorScheme?: ColorSchemePreference,
1616
): Promise<Finding[]> {
@@ -28,8 +28,15 @@ export async function findForUrl(
2828
await page.goto(url)
2929

3030
const findings: Finding[] = []
31-
const addFinding = (findingData: Finding) => {
32-
findings.push(findingData)
31+
const addFinding = async (
32+
findingData: Finding,
33+
{includeScreenshots = false}: {includeScreenshots?: boolean} = {},
34+
) => {
35+
let screenshotId
36+
if (includeScreenshotsInput || includeScreenshots) {
37+
screenshotId = await generateScreenshots(page)
38+
}
39+
findings.push({...findingData, screenshotId})
3340
}
3441

3542
try {
@@ -45,7 +52,7 @@ export async function findForUrl(
4552
page,
4653
addFinding,
4754
// - this will be coming soon
48-
// runAxeScan: () => runAxeScan({page, includeScreenshots, findings}),
55+
// runAxeScan: () => runAxeScan({page, includeScreenshots: includeScreenshotsInput, findings}),
4956
})
5057
} else {
5158
core.info(`Skipping plugin ${plugin.name} because it is not included in the 'scans' input`)
@@ -55,7 +62,7 @@ export async function findForUrl(
5562

5663
if (scansContext.shouldPerformAxeScan) {
5764
runAxeScan({
58-
includeScreenshots,
65+
includeScreenshots: includeScreenshotsInput,
5966
page,
6067
findings,
6168
})

PLUGINS.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Plugins
2+
3+
The plugin system allows teams to create custom scans/tests to run on their pages. An example of this is Axe interaction tests. In some cases, it might be desirable to perform specific interactions on elements of a given page before doing an Axe scan. These interactions are usually unique to each page that is scanned, so it would require the owning team to write a custom plugin that can interact with the page and run the Axe scan when ready. See the example under [.github/scanner-plugins/test-plugin](https://github.com/github/accessibility-scanner/tree/main/.github/scanner-plugins/test-plugin) (this is not an Axe interaction test, but should give a general understanding of plugin structure).
4+
5+
Some plugins come built-in with the scanner and can be enabled via actions inputs.
6+
7+
## How Plugins Work
8+
9+
Plugins are dynamically loaded by the scanner when it runs. The scanner will look into the `./.github` folder in your repo (where you run the workflow from) and search for a `scanner-plugins` folder. If it finds it, it will assume each folder under that is a plugin, and attempt to load the `index.js` file inside it. Once loaded, the scanner will invoke the exported default function from the `index.js` file.
10+
11+
### Default function API
12+
13+
When the default function is invoked, the following arguments are passed to the function:
14+
15+
- page: this is the [playwright page](https://playwright.dev/docs/api/class-page) instance. See the linked docs for information on how to interact with the page.
16+
- addFinding: this is a function that will add a finding to the list. Findings are used to generate issues and 'filings'. See here for the [types](https://github.com/github/accessibility-scanner/blob/main/tests/types.d.ts). This function expects a single object as an argument, and it should match the `Finding` type defined in the types linked above.
17+
18+
## How To Create Plugins
19+
20+
As mentioned above, plugins need to exist under `./.github/scanner-plugins`. For a plugin to work, it needs to meet the following criteria:
21+
22+
- Each seperate plugin should exist in a separate folder under `./.github/scanner-plugins`. So `./.github/scanner-plugins/plugin-1` would be 1 plugin loaded by the scanner.
23+
- Each plugin should have one `index.js` file inside its folder.
24+
- The `index.js` file must export a `name` field. This is the name used to pass to the `scans` input. So the following: `scans: ['my-custom-plugin']` would cause the scanner to only run that plugin.
25+
- The `index.js` file must export a default function. This is the function that the scanner uses to run the plugin. This can be an async function.
26+
27+
## Things to look out for
28+
29+
- Plugin names should be unique. If multiple plugins have the same name, and the `scans` input array contains this name, all the plugins with that name _will_ run. However, this is not advised because if you want to turn off one plugin, you'll have to go back and change that plugin name.

README.md

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Trigger the workflow manually or automatically based on your configuration. The
124124
| `include_screenshots` | No | Whether to capture screenshots of scanned pages and include links to them in filed issues. Screenshots are stored on the `gh-cache` branch of the repository running the workflow. Default: `false` | `true` |
125125
| `reduced_motion` | No | Playwright `reducedMotion` setting for scan contexts. Allowed values: `reduce`, `no-preference` | `reduce` |
126126
| `color_scheme` | No | Playwright `colorScheme` setting for scan contexts. Allowed values: `light`, `dark`, `no-preference` | `dark` |
127-
| `scans` | No | A list of scans (or plugins) to be performed. If not provided, only axe will be performed. | `['axe', 'reflow']` |
127+
| `scans` | No | An array of scans (or plugins) to be performed. If not provided, only Axe will be performed. | `['axe', ...other plugins]` |
128128

129129
---
130130

@@ -157,33 +157,7 @@ The a11y scanner leverages GitHub Copilot coding agent, which can be configured
157157

158158
## Plugins
159159

160-
The plugin system allows teams to create custom scans/test to run on their pages. An example of this is axe interaction tests. In some cases, it might be desirable to perform specific interactions on elements of a given page before doing an axe scan. These interactions are usually unique to each page that is scanned, so it would require the owning team to write a custom plugin that can interact with the page and run the axe scan when ready. See the example under `./.github/scanner-plugins/test-plugin` (this is not an axe interaction test, but should give a general understanding of how plugins look like).
161-
162-
Some plugins come built-in with the scanner and can be enabled via actions inputs.
163-
164-
### How Plugins Work
165-
166-
Plugins are dynamically loaded by the scanner when it runs. The scanner will look into the `./.github` folder in your repo (where you run the workflow from) and search for a `scanner-plugins` folder. If it finds it, it will assume each folder under that is a plugin, and attempt to load the `index.js` file inside it. Once loaded, the scanner will invoke the exported default function from the `index.js` file.
167-
168-
#### Default Function Api
169-
170-
When the default function is invoked, the following arguments are passed to the function:
171-
172-
- page: this is the [playwright page](https://playwright.dev/docs/api/class-page) instance. See the linked docs for information on how to interact with the page.
173-
- addFinding: this is a function that will add a finding to the list. Findings are used to generate issues and 'filings'. See here for the [types](https://github.com/github/accessibility-scanner/blob/main/tests/types.d.ts). This function expects a single object as an argument, and it should match the `Finding` type defined in the types linked above.
174-
175-
### How To Create Plugins
176-
177-
As mentioned above, plugins need to live under `./.github/scanner-plugins`. For a plugin to work, it needs to meet the following criteria:
178-
179-
- Each seperate plugin should live in a separate folder under `./.github/scanner-plugins`. So `./.github/scanner-plugins/plugin-1` would be 1 plugin loaded by the scanner
180-
- Each plugin should have one `index.js` file inside its folder
181-
- The `index.js` file must export a `name` field. This is the name used to pass to the `scans` input. So the following: `scans: ['my-custom-plugin']` would cause the scanner to only run that plugin
182-
- The `index.js` file must export a default function. This is the function that the scanner uses to run the plugin. This can be an async function.
183-
184-
### Things To Lookout For
185-
186-
- Plugin names should be unique. If multiple plugins have the same name, and the `scans` input passes this name, all the plugins with that name _will_ run. However, this is not advised because if you want to turn off one plugin, you'll have to go back and change that plugin name.
160+
See the [plugin docs](https://github.com/github/accessibility-scanner/tree/main/PLUGINS.md) for more information
187161

188162
---
189163

0 commit comments

Comments
 (0)