From 6fb3915db33e95b762628c88dbe32401785d71b7 Mon Sep 17 00:00:00 2001 From: Matheus Nogueira Date: Sun, 1 Mar 2026 20:18:32 -0300 Subject: [PATCH] feat: add environment-name input for v2 runs Allows users to select a named environment (e.g. "Staging", "Production") when starting a v2 Playwright run via the GitHub Action. The environment name is passed as `environmentName` in the API request body, which resolves it server-side to load the corresponding variables. `env-overrides` still take precedence over environment variables. Co-Authored-By: Claude Opus 4.6 --- README.md | 9 ++++++--- action.yml | 8 +++++++- dist/index.js | 12 ++++++++---- src/input.ts | 5 ++++- src/main.ts | 6 ++++-- src/stably/api/playwright-api.ts | 4 +++- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2d0d666..b643b7a 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ Run test suites using Stably's agent (v2) test runner. | api-key | ✅ | | Your API key | | project-id | ✅ | | Your Stably project ID | | playwright-project-name | | | The Playwright project name to run. Maps to the `--project` CLI flag. Optional - if not provided, all projects will run. | -| env-overrides | | | A YAML string or JSON object containing environment variable overrides. Each key is a variable name and the value is a string. | -| github-comment | | true | When enabled, will leave a comment on either the commit or PR with relevant test results. Requires proper permissions (see [Permissions](#permissions) section below). | | +| environment-name | | | Name of the environment to use for this run (e.g. "Staging", "Production"). When omitted, falls back to the project's default environment. | +| env-overrides | | | A YAML string or JSON object containing environment variable overrides. Each key is a variable name and the value is a string. These take precedence over environment variables. | +| github-comment | | true | When enabled, will leave a comment on either the commit or PR with relevant test results. Requires proper permissions (see [Permissions](#permissions) section below). | | github-token | | `${{ github.token }}` | This token is used for leaving the comments on PRs/commits. By default, we'll use the GitHub actions bot token, but you can override this a repository scoped [PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens). | | async | | false | If set, will launch the tests but not wait for them to finish and the action will always output success. Note: Github comments will not function if this is set | @@ -58,7 +59,9 @@ jobs: project-id: YOUR_PROJECT_ID # Optional: specify Playwright project(s) to run (instead of all projects) playwright-project-name: smoke-tests - # Optional: override environment variables + # Optional: select which environment to load variables from + environment-name: Staging + # Optional: override specific environment variables env-overrides: | BASE_URL: https://staging.example.com API_KEY: abc123 diff --git a/action.yml b/action.yml index 07c3d36..b9a2e1e 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,11 @@ inputs: Example: BASE_URL: https://staging.example.com API_KEY: abc123 + environment-name: + description: |- + Name of the environment to use for this run (v2 only). + For example: "Staging", "Production". + When omitted, falls back to the project's default environment. test-group-id: description: The test group ID to execute (v1 only) deprecationMessage: @@ -65,7 +70,8 @@ inputs: default: 'false' environment: description: |- - The environment to inherit variables from (v1 only, v2 support soon). + The environment to inherit variables from (v1 only). + For v2, use environment-name instead. Defaults to 'PRODUCTION'. default: 'PRODUCTION' variable-overrides: diff --git a/dist/index.js b/dist/index.js index 6176f8a..37723f3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36082,6 +36082,7 @@ function parseInput() { const envOverrides = envOverridesJson ? parseObjectInput('env-overrides', envOverridesJson) : undefined; + const environmentName = (0, core_1.getInput)('environment-name').trim() || undefined; // V1 inputs (supporting deprecating of runGroupIds) const testSuiteIdInput = (0, core_1.getInput)('test-suite-id'); const testGroupIdInput = (0, core_1.getInput)('test-group-id'); @@ -36131,7 +36132,8 @@ function parseInput() { version: 'v2', projectId, playwrightProjectName: playwrightProjectName || undefined, - envOverrides + envOverrides, + environmentName } : { version: 'v1', @@ -36250,13 +36252,14 @@ async function runV1({ apiKey, urlReplacement, githubComment, githubToken, testS (0, core_1.setFailed)(e instanceof Error ? e.message : `An unknown error occurred`); } } -async function runV2({ apiKey, projectId, playwrightProjectName, githubComment, githubToken, runInAsyncMode, envOverrides }) { +async function runV2({ apiKey, projectId, playwrightProjectName, githubComment, githubToken, runInAsyncMode, envOverrides, environmentName }) { const { runId } = await (0, playwright_api_1.startPlaywrightRun)({ projectId, apiKey, options: { playwrightProjectName, - envOverrides + envOverrides, + environmentName } }); (0, core_1.setOutput)('testSuiteRunId', runId); @@ -36402,7 +36405,8 @@ async function startPlaywrightRun({ projectId, apiKey, options }) { ]); const body = { playwrightProjectName: options.playwrightProjectName, - envOverrides: options.envOverrides + envOverrides: options.envOverrides, + environmentName: options.environmentName }; const runUrl = new URL(`/v1/projects/${projectId}/runs`, API_ENDPOINT).href; const runResponse = await httpClient.postJson(runUrl, body, { diff --git a/src/input.ts b/src/input.ts index caac3cd..48d994e 100644 --- a/src/input.ts +++ b/src/input.ts @@ -24,6 +24,7 @@ type V2Input = BaseInput & { projectId: string; playwrightProjectName: string | undefined; envOverrides: Record | undefined; + environmentName: string | undefined; }; type V1Input = BaseInput & { @@ -61,6 +62,7 @@ export function parseInput(): ParsedInput { string >) : undefined; + const environmentName = getInput('environment-name').trim() || undefined; // V1 inputs (supporting deprecating of runGroupIds) const testSuiteIdInput = getInput('test-suite-id'); @@ -137,7 +139,8 @@ export function parseInput(): ParsedInput { version: 'v2' as const, projectId, playwrightProjectName: playwrightProjectName || undefined, - envOverrides + envOverrides, + environmentName } : { version: 'v1' as const, diff --git a/src/main.ts b/src/main.ts index 79e73ed..da9452a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -118,14 +118,16 @@ async function runV2({ githubComment, githubToken, runInAsyncMode, - envOverrides + envOverrides, + environmentName }: V2Input): Promise { const { runId } = await startPlaywrightRun({ projectId, apiKey, options: { playwrightProjectName, - envOverrides + envOverrides, + environmentName } }); setOutput('testSuiteRunId', runId); diff --git a/src/stably/api/playwright-api.ts b/src/stably/api/playwright-api.ts index 2e199d9..38f6169 100644 --- a/src/stably/api/playwright-api.ts +++ b/src/stably/api/playwright-api.ts @@ -69,6 +69,7 @@ export async function startPlaywrightRun({ options: { playwrightProjectName?: string; envOverrides?: Record; + environmentName?: string; }; }): Promise { const httpClient = new HttpClient('github-action', [ @@ -77,7 +78,8 @@ export async function startPlaywrightRun({ const body = { playwrightProjectName: options.playwrightProjectName, - envOverrides: options.envOverrides + envOverrides: options.envOverrides, + environmentName: options.environmentName }; const runUrl = new URL(`/v1/projects/${projectId}/runs`, API_ENDPOINT).href;