-
Notifications
You must be signed in to change notification settings - Fork 0
more robust Playwright config #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed62585
more robust Playwright config
Tenemo 48478f0
Merge branch 'master' into dev
Tenemo d90117b
.claude/ gitignored
Tenemo bd94fc0
Merge branch 'dev' of github.com:Tenemo/piech.dev into dev
Tenemo 56ec071
GH workflow better error handling
Tenemo 1a1631a
stuck action fix
Tenemo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "pull_request": { | ||
| "runnerLabel": "ubuntu-latest", | ||
| "workers": 4 | ||
| }, | ||
| "production": { | ||
| "runnerLabel": "ubuntu-latest", | ||
| "maxParallel": 3, | ||
| "workers": 1 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| const CONFIG_PATH = path.resolve( | ||
| process.cwd(), | ||
| '.github', | ||
| 'playwright-workflow-config.json', | ||
| ); | ||
|
|
||
| type WorkflowTarget = 'pull_request' | 'production'; | ||
|
|
||
| type BaseWorkflowConfig = { | ||
| runnerLabel: string; | ||
| workers: number; | ||
| }; | ||
|
|
||
| type ProductionWorkflowConfig = BaseWorkflowConfig & { | ||
| maxParallel: number; | ||
| }; | ||
|
|
||
| type WorkflowConfig = { | ||
| pull_request: BaseWorkflowConfig; | ||
| production: ProductionWorkflowConfig; | ||
| }; | ||
|
|
||
| function assertPositiveInteger(value: number, fieldName: string): void { | ||
| if (!Number.isInteger(value) || value < 1) { | ||
| throw new Error( | ||
| `Expected "${fieldName}" to be a positive integer, received ${String(value)}.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function parseWorkflowTarget(rawTarget: string | undefined): WorkflowTarget { | ||
| if (rawTarget === 'pull_request' || rawTarget === 'production') { | ||
| return rawTarget; | ||
| } | ||
|
|
||
| throw new Error( | ||
| 'Expected a workflow target of "pull_request" or "production".', | ||
| ); | ||
| } | ||
|
|
||
| function validateBaseConfig( | ||
| rawConfig: unknown, | ||
| fieldPrefix: WorkflowTarget, | ||
| ): BaseWorkflowConfig { | ||
| if ( | ||
| typeof rawConfig !== 'object' || | ||
| rawConfig === null || | ||
| Array.isArray(rawConfig) | ||
| ) { | ||
| throw new Error(`Expected "${fieldPrefix}" to be an object.`); | ||
| } | ||
|
|
||
| const config = rawConfig as Record<string, unknown>; | ||
| const { runnerLabel, workers } = config; | ||
|
|
||
| if (typeof runnerLabel !== 'string' || runnerLabel === '') { | ||
| throw new Error( | ||
| `Expected "${fieldPrefix}.runnerLabel" to be a non-empty string.`, | ||
| ); | ||
| } | ||
|
|
||
| if (typeof workers !== 'number') { | ||
| throw new Error(`Expected "${fieldPrefix}.workers" to be a number.`); | ||
| } | ||
|
|
||
| assertPositiveInteger(workers, `${fieldPrefix}.workers`); | ||
|
|
||
| return { | ||
| runnerLabel, | ||
| workers, | ||
| }; | ||
| } | ||
|
|
||
| function validateProductionConfig( | ||
| rawConfig: unknown, | ||
| ): ProductionWorkflowConfig { | ||
| if ( | ||
| typeof rawConfig !== 'object' || | ||
| rawConfig === null || | ||
| Array.isArray(rawConfig) | ||
| ) { | ||
| throw new Error('Expected "production" to be an object.'); | ||
| } | ||
|
|
||
| const config = rawConfig as Record<string, unknown>; | ||
| const validatedConfig = validateBaseConfig(rawConfig, 'production'); | ||
| const { maxParallel } = config; | ||
|
|
||
| if (typeof maxParallel !== 'number') { | ||
| throw new Error('Expected "production.maxParallel" to be a number.'); | ||
| } | ||
|
|
||
| assertPositiveInteger(maxParallel, 'production.maxParallel'); | ||
|
|
||
| return { | ||
| ...validatedConfig, | ||
| maxParallel, | ||
| }; | ||
| } | ||
|
|
||
| function parseWorkflowConfig(rawConfig: unknown): WorkflowConfig { | ||
| if (typeof rawConfig !== 'object' || rawConfig === null) { | ||
| throw new Error('Expected workflow config to be an object.'); | ||
| } | ||
|
|
||
| const maybeConfig = rawConfig as Record<string, unknown>; | ||
|
|
||
| return { | ||
| pull_request: validateBaseConfig( | ||
| maybeConfig.pull_request, | ||
| 'pull_request', | ||
| ), | ||
| production: validateProductionConfig(maybeConfig.production), | ||
| }; | ||
| } | ||
|
|
||
| const target = parseWorkflowTarget(process.argv[2]); | ||
| const rawConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')) as unknown; | ||
| const parsedConfig = parseWorkflowConfig(rawConfig); | ||
| const outputs: Record<string, string> = | ||
| target === 'pull_request' | ||
| ? { | ||
| runner_label: parsedConfig.pull_request.runnerLabel, | ||
| workers: String(parsedConfig.pull_request.workers), | ||
| } | ||
| : { | ||
| runner_label: parsedConfig.production.runnerLabel, | ||
| workers: String(parsedConfig.production.workers), | ||
| max_parallel: String(parsedConfig.production.maxParallel), | ||
| }; | ||
|
|
||
| process.stdout.write( | ||
| `${Object.entries(outputs) | ||
| .map(([key, value]) => `${key}=${value}`) | ||
| .join('\n')}\n`, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The merge-report steps run whenever needs.playwright.result != 'success', which includes 'skipped' (e.g., if resolve_config/setup fails and the matrix never runs). In that case there won’t be any blob-report artifacts and the download/merge steps will fail and add noise. Consider tightening these conditions to only run when the matrix actually ran (e.g., needs.playwright.result == 'failure' || needs.playwright.result == 'cancelled') and/or configuring the download step to ignore missing artifacts.