Skip to content

Commit cf0b579

Browse files
authored
Add workflow input options for reducedMotion and colorScheme (#145)
- [x] Inspect repository structure, related issues, and current find action input flow - [x] Run existing lint/tests and identify baseline status (noting unrelated existing failures) - [x] Add minimal new inputs to the appropriate action.yml files for `reduced_motion` and `color_scheme` - [x] Thread new inputs through the find action code and validate allowed values before passing to Playwright context options - [x] Update directly related documentation for the new inputs - [x] Run relevant lint/build/tests after changes - [x] Run code review and security scan tools, address any actionable findings - [x] Summarize changes, validation results, and security status <!-- START COPILOT CODING AGENT TIPS --> --- 🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security)
2 parents 066e45c + 8d104a2 commit cf0b579

File tree

8 files changed

+67
-6
lines changed

8 files changed

+67
-6
lines changed

.github/actions/find/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ https://primer.style/octicons/
1919

2020
**Optional** Stringified JSON object containing `username`, `password`, `cookies`, and/or `localStorage` from an authenticated session. For example: `{"username":"some-user","password":"correct-horse-battery-staple","cookies":[{"name":"theme-preference","value":"light","domain":"primer.style","path":"/"}],"localStorage":{"https://primer.style":{"theme-preference":"light"}}}`
2121

22+
#### `reduced_motion`
23+
24+
**Optional** Playwright
25+
[`reducedMotion`](https://playwright.dev/docs/api/class-browser#browser-new-context-option-reduced-motion)
26+
configuration option.
27+
28+
#### `color_scheme`
29+
30+
**Optional** Playwright
31+
[`colorScheme`](https://playwright.dev/docs/api/class-browser#browser-new-context-option-color-scheme)
32+
configuration option.
33+
2234
### Outputs
2335

2436
#### `findings`

.github/actions/find/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ inputs:
1313
description: "Whether to capture screenshots of scanned pages and include links to them in the issue"
1414
required: false
1515
default: "false"
16+
reduced_motion:
17+
description: "Playwright reducedMotion setting: https://playwright.dev/docs/api/class-browser#browser-new-page-option-reduced-motion"
18+
required: false
19+
color_scheme:
20+
description: "Playwright colorScheme setting: https://playwright.dev/docs/api/class-browser#browser-new-context-option-color-scheme"
21+
required: false
1622

1723
outputs:
1824
findings:

.github/actions/find/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {Finding} from './types.d.js'
1+
import type {ColorSchemePreference, Finding, ReducedMotionPreference} from './types.d.js'
22
import {AxeBuilder} from '@axe-core/playwright'
33
import playwright from 'playwright'
44
import {AuthContext} from './AuthContext.js'
@@ -8,12 +8,18 @@ export async function findForUrl(
88
url: string,
99
authContext?: AuthContext,
1010
includeScreenshots: boolean = false,
11+
reducedMotion?: ReducedMotionPreference,
12+
colorScheme?: ColorSchemePreference,
1113
): Promise<Finding[]> {
1214
const browser = await playwright.chromium.launch({
1315
headless: true,
1416
executablePath: process.env.CI ? '/usr/bin/google-chrome' : undefined,
1517
})
16-
const contextOptions = authContext?.toPlaywrightBrowserContextOptions() ?? {}
18+
const contextOptions = {
19+
...(authContext?.toPlaywrightBrowserContextOptions() ?? {}),
20+
...(reducedMotion ? {reducedMotion} : {}),
21+
...(colorScheme ? {colorScheme} : {}),
22+
}
1723
const context = await browser.newContext(contextOptions)
1824
const page = await context.newPage()
1925
await page.goto(url)

.github/actions/find/src/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {AuthContextInput} from './types.js'
1+
import type {AuthContextInput, ColorSchemePreference, ReducedMotionPreference} from './types.js'
22
import * as core from '@actions/core'
33
import {AuthContext} from './AuthContext.js'
44
import {findForUrl} from './findForUrl.js'
@@ -11,11 +11,31 @@ export default async function () {
1111
const authContext = new AuthContext(authContextInput)
1212

1313
const includeScreenshots = core.getInput('include_screenshots', {required: false}) !== 'false'
14+
const reducedMotionInput = core.getInput('reduced_motion', {required: false})
15+
let reducedMotion: ReducedMotionPreference | undefined
16+
if (reducedMotionInput) {
17+
if (!['reduce', 'no-preference', null].includes(reducedMotionInput)) {
18+
throw new Error(
19+
"Input 'reduced_motion' must be one of: 'reduce', 'no-preference', or null per Playwright documentation.",
20+
)
21+
}
22+
reducedMotion = reducedMotionInput as ReducedMotionPreference
23+
}
24+
const colorSchemeInput = core.getInput('color_scheme', {required: false})
25+
let colorScheme: ColorSchemePreference | undefined
26+
if (colorSchemeInput) {
27+
if (!['light', 'dark', 'no-preference', null].includes(colorSchemeInput)) {
28+
throw new Error(
29+
"Input 'color_scheme' must be one of: 'light', 'dark', 'no-preference', or null per Playwright documentation.",
30+
)
31+
}
32+
colorScheme = colorSchemeInput as ColorSchemePreference
33+
}
1434

1535
const findings = []
1636
for (const url of urls) {
1737
core.info(`Preparing to scan ${url}`)
18-
const findingsForUrl = await findForUrl(url, authContext, includeScreenshots)
38+
const findingsForUrl = await findForUrl(url, authContext, includeScreenshots, reducedMotion, colorScheme)
1939
if (findingsForUrl.length === 0) {
2040
core.info(`No accessibility gaps were found on ${url}`)
2141
continue

.github/actions/find/src/types.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ export type AuthContextInput = {
3131
cookies?: Cookie[]
3232
localStorage?: LocalStorage
3333
}
34+
35+
export type ReducedMotionPreference = 'reduce' | 'no-preference' | null
36+
37+
export type ColorSchemePreference = 'light' | 'dark' | 'no-preference' | null

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ jobs:
5151
# auth_context: # Optional: Stringified JSON object for complex authentication
5252
# skip_copilot_assignment: false # Optional: Set to true to skip assigning issues to GitHub Copilot (or if you don't have GitHub Copilot)
5353
# include_screenshots: false # Optional: Set to true to capture screenshots and include links to them in filed issues
54+
# reduced_motion: no-preference # Optional: Playwright reduced motion configuration option
55+
# color_scheme: light # Optional: Playwright color scheme configuration option
5456
```
5557

5658
> 👉 Update all `REPLACE_THIS` placeholders with your actual values. See [Action Inputs](#action-inputs) for details.
@@ -115,6 +117,8 @@ Trigger the workflow manually or automatically based on your configuration. The
115117
| `auth_context` | No | If scanned pages require authentication, a stringified JSON object containing username, password, cookies, and/or localStorage from an authenticated session | `{"username":"some-user","password":"***","cookies":[...]}` |
116118
| `skip_copilot_assignment` | No | Whether to skip assigning filed issues to GitHub Copilot. Set to `true` if you don't have GitHub Copilot or prefer to handle issues manually | `true` |
117119
| `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` |
120+
| `reduced_motion` | No | Playwright `reducedMotion` setting for scan contexts. Allowed values: `reduce`, `no-preference` | `reduce` |
121+
| `color_scheme` | No | Playwright `colorScheme` setting for scan contexts. Allowed values: `light`, `dark`, `no-preference` | `dark` |
118122

119123
---
120124

@@ -148,11 +152,11 @@ The a11y scanner leverages GitHub Copilot coding agent, which can be configured
148152

149153
💬 We welcome your feedback! To submit feedback or report issues, please create an issue in this repository. For more information on contributing, please refer to the [CONTRIBUTING](./CONTRIBUTING.md) file.
150154

151-
## License
155+
## License
152156

153157
📄 This project is licensed under the terms of the MIT open source license. Please refer to the [LICENSE](./LICENSE) file for the full terms.
154158

155-
## Maintainers
159+
## Maintainers
156160

157161
🔧 Please refer to the [CODEOWNERS](./.github/CODEOWNERS) file for more information.
158162

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ inputs:
3535
description: "Whether to capture screenshots and include links to them in the issue"
3636
required: false
3737
default: "false"
38+
reduced_motion:
39+
description: "Playwright reducedMotion setting: https://playwright.dev/docs/api/class-browser#browser-new-page-option-reduced-motion"
40+
required: false
41+
color_scheme:
42+
description: "Playwright colorScheme setting: https://playwright.dev/docs/api/class-browser#browser-new-context-option-color-scheme"
43+
required: false
3844

3945
outputs:
4046
results:
@@ -85,6 +91,8 @@ runs:
8591
urls: ${{ inputs.urls }}
8692
auth_context: ${{ inputs.auth_context || steps.auth.outputs.auth_context }}
8793
include_screenshots: ${{ inputs.include_screenshots }}
94+
reduced_motion: ${{ inputs.reduced_motion }}
95+
color_scheme: ${{ inputs.color_scheme }}
8896
- name: File
8997
id: file
9098
uses: ./../../_actions/github/accessibility-scanner/current/.github/actions/file

0 commit comments

Comments
 (0)