From 12c91e9d4fad12cf74e52af1ba933b53449937a0 Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:28:51 +0530 Subject: [PATCH 1/8] wip: implement runtime config --- .github/workflows/ci.yml | 3 +++ dist/index.js | 11 +++++------ src/main.ts | 13 ++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9eea170..6bad88b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,3 +26,6 @@ jobs: with: build-url: "https://github.com/empirical-run/dispatch-action" environment: production + runtime-config: + - foo: bar + - baz: qux diff --git a/dist/index.js b/dist/index.js index f47a34b..6552a8e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29370,10 +29370,7 @@ async function run() { else if (!isValidUrl(buildUrl)) { core.setFailed(`Invalid config: build-url must be a valid URL.`); } - const slackWebhookUrl = core.getInput('slack-webhook-url'); - if (slackWebhookUrl) { - console.log(`Warning: slack-webhook-url is not a supported input, and will be ignored.`); - } + // TOOD: Remove platform and only keep environment const platform = core.getInput('platform'); if (platform) { console.warn(`Warning: platform is a deprecated input, you should use environment instead.`); @@ -29383,11 +29380,13 @@ async function run() { core.setFailed(`Missing config parameter: either of "environment" or "platform" (deprecated) needs to passed`); } const authKey = core.getInput('auth-key'); + if (!authKey) { + core.setFailed(`Missing config parameter: auth-key`); + } const headers = { 'Content-Type': 'application/json' }; if (authKey) { - console.log(`Setting an auth header for the request.`); headers['Authorization'] = `Bearer ${authKey}`; } const branch = await getBranchName(); @@ -29407,7 +29406,7 @@ async function run() { commit_url: getCommitUrl(), }, platform, - environment, + environment: environment.toLowerCase(), github_actor: await getActor(), }) }); diff --git a/src/main.ts b/src/main.ts index d5d5a77..8db41bf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -158,26 +158,25 @@ export async function run(): Promise { } else if (!isValidUrl(buildUrl)) { core.setFailed(`Invalid config: build-url must be a valid URL.`) } - const slackWebhookUrl: string = core.getInput('slack-webhook-url'); - if (slackWebhookUrl) { - console.log(`Warning: slack-webhook-url is not a supported input, and will be ignored.`) - } + + // TOOD: Remove platform and only keep environment const platform: string = core.getInput('platform'); if (platform) { console.warn(`Warning: platform is a deprecated input, you should use environment instead.`) } - const environment = core.getInput('environment'); if (!platform && !environment) { core.setFailed(`Missing config parameter: either of "environment" or "platform" (deprecated) needs to passed`) } const authKey = core.getInput('auth-key'); + if (!authKey) { + core.setFailed(`Missing config parameter: auth-key`) + } const headers: Record = { 'Content-Type': 'application/json' }; if (authKey) { - console.log(`Setting an auth header for the request.`); headers['Authorization'] = `Bearer ${authKey}`; } @@ -198,7 +197,7 @@ export async function run(): Promise { commit_url: getCommitUrl(), }, platform, - environment, + environment: environment.toLowerCase(), github_actor: await getActor(), }) }); From 7dbdf0bb9d48df07d3e8e7296ec8521b4b6cad46 Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:30:59 +0530 Subject: [PATCH 2/8] yaml? --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bad88b..39bc75a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,5 +27,5 @@ jobs: build-url: "https://github.com/empirical-run/dispatch-action" environment: production runtime-config: - - foo: bar - - baz: qux + foo: bar + baz: qux From 071ea4b10d3e61d6979f2031973e4432a63596df Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:37:05 +0530 Subject: [PATCH 3/8] tri --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39bc75a..059df39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,6 @@ jobs: with: build-url: "https://github.com/empirical-run/dispatch-action" environment: production - runtime-config: + runtime-config: | foo: bar baz: qux From f5048b12de4b699230f8a576dd23b7a2f7e6d650 Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:37:44 +0530 Subject: [PATCH 4/8] print --- src/main.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.ts b/src/main.ts index 8db41bf..861dbe7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -180,6 +180,15 @@ export async function run(): Promise { headers['Authorization'] = `Bearer ${authKey}`; } + const runtimeConfig = core.getMultilineInput('runtime-config'); + if (runtimeConfig) { + const config = runtimeConfig.map((line: string) => { + const [key, value] = line.split(':'); + return { [key.trim()]: value.trim() }; + }); + console.log(`Runtime config: ${JSON.stringify(config)}`); + } + const branch = await getBranchName(); console.log(`Branch name: ${branch}`); const response = await fetch("https://dispatch.empirical.run/v1/trigger", { From bc22058ff21fb75b37c6ba5deee1a3f7e1c4a1ab Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:38:37 +0530 Subject: [PATCH 5/8] errthing --- .github/workflows/ci.yml | 1 + action.yml | 3 +++ dist/index.js | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 059df39..96520d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,7 @@ jobs: uses: ./ with: build-url: "https://github.com/empirical-run/dispatch-action" + auth-key: "1234567890" environment: production runtime-config: | foo: bar diff --git a/action.yml b/action.yml index 873a567..b81bea5 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,9 @@ inputs: environment: description: "Environment to run the tests on" required: true + runtime-config: + description: "Runtime config for the tests" + required: false runs: using: node20 diff --git a/dist/index.js b/dist/index.js index 6552a8e..7335740 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29389,6 +29389,14 @@ async function run() { if (authKey) { headers['Authorization'] = `Bearer ${authKey}`; } + const runtimeConfig = core.getMultilineInput('runtime-config'); + if (runtimeConfig) { + const config = runtimeConfig.map((line) => { + const [key, value] = line.split(':'); + return { [key.trim()]: value.trim() }; + }); + console.log(`Runtime config: ${JSON.stringify(config)}`); + } const branch = await getBranchName(); console.log(`Branch name: ${branch}`); const response = await fetch("https://dispatch.empirical.run/v1/trigger", { From f6ecf7e1bcb41bb85a71d54c21cfa32021851a7e Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:39:27 +0530 Subject: [PATCH 6/8] vars --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96520d9..02a4290 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,3 +30,4 @@ jobs: runtime-config: | foo: bar baz: qux + eventName: ${{ github.event_name }} From fa86ea6f345b0c596f53458ab9eb7da4e20b1af3 Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 16:42:11 +0530 Subject: [PATCH 7/8] aprse --- dist/index.js | 29 +++++++++++++++++++++++++---- src/main.ts | 30 ++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7335740..85902a6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29361,6 +29361,30 @@ async function getActor() { // https://github.com/actions/toolkit/issues/1143#issuecomment-2193348740 return process.env.GITHUB_TRIGGERING_ACTOR || github.context.actor; } +function parseRuntimeConfig(runtimeConfig) { + return runtimeConfig.reduce((acc, line) => { + if (!line.trim()) { + return acc; + } + if (!line.includes(':')) { + throw new Error(`Invalid runtime config format. Each line must contain a key-value pair separated by colon. Invalid line: "${line}"`); + } + const [key, value] = line.split(':'); + const trimmedKey = key.trim(); + const trimmedValue = value.trim(); + if (!trimmedKey) { + throw new Error(`Invalid runtime config: key cannot be empty in line "${line}"`); + } + if (!trimmedValue) { + throw new Error(`Invalid runtime config: value cannot be empty for key "${trimmedKey}"`); + } + if (acc[trimmedKey]) { + throw new Error(`Invalid runtime config: duplicate key "${trimmedKey}" found`); + } + acc[trimmedKey] = trimmedValue; + return acc; + }, {}); +} async function run() { try { const buildUrl = core.getInput('build-url'); @@ -29391,10 +29415,7 @@ async function run() { } const runtimeConfig = core.getMultilineInput('runtime-config'); if (runtimeConfig) { - const config = runtimeConfig.map((line) => { - const [key, value] = line.split(':'); - return { [key.trim()]: value.trim() }; - }); + const config = parseRuntimeConfig(runtimeConfig); console.log(`Runtime config: ${JSON.stringify(config)}`); } const branch = await getBranchName(); diff --git a/src/main.ts b/src/main.ts index 861dbe7..121b8f1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -150,6 +150,31 @@ async function getActor(): Promise { return process.env.GITHUB_TRIGGERING_ACTOR || github.context.actor; } +function parseRuntimeConfig(runtimeConfig: string[]): Record { + return runtimeConfig.reduce((acc: Record, line: string) => { + if (!line.trim()) { + return acc; + } + if (!line.includes(':')) { + throw new Error(`Invalid runtime config format. Each line must contain a key-value pair separated by colon. Invalid line: "${line}"`); + } + const [key, value] = line.split(':'); + const trimmedKey = key.trim(); + const trimmedValue = value.trim(); + if (!trimmedKey) { + throw new Error(`Invalid runtime config: key cannot be empty in line "${line}"`); + } + if (!trimmedValue) { + throw new Error(`Invalid runtime config: value cannot be empty for key "${trimmedKey}"`); + } + if (acc[trimmedKey]) { + throw new Error(`Invalid runtime config: duplicate key "${trimmedKey}" found`); + } + acc[trimmedKey] = trimmedValue; + return acc; + }, {}); +} + export async function run(): Promise { try { const buildUrl: string = core.getInput('build-url'); @@ -182,10 +207,7 @@ export async function run(): Promise { const runtimeConfig = core.getMultilineInput('runtime-config'); if (runtimeConfig) { - const config = runtimeConfig.map((line: string) => { - const [key, value] = line.split(':'); - return { [key.trim()]: value.trim() }; - }); + const config = parseRuntimeConfig(runtimeConfig); console.log(`Runtime config: ${JSON.stringify(config)}`); } From 476a679bc8a19b4ac07e759905a8128fe87a0fb3 Mon Sep 17 00:00:00 2001 From: Arjun Attam Date: Sat, 24 May 2025 22:07:16 +0530 Subject: [PATCH 8/8] fix --- action.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index b81bea5..51d31f4 100644 --- a/action.yml +++ b/action.yml @@ -2,7 +2,6 @@ name: "Run Empirical tests" description: "This action dispatches a request to run tests" author: "empirical.run" -# Add your action's branding here. This will appear on the GitHub Marketplace. branding: icon: "send" color: "gray-dark" @@ -10,14 +9,14 @@ branding: # Define your inputs here. inputs: auth-key: - description: "Auth key for the application" - required: false - build-url: - description: "URL to the application to be tested" + description: "API key for Empirical" required: true environment: description: "Environment to run the tests on" required: true + build-url: + description: "URL to the application to be tested" + required: true runtime-config: description: "Runtime config for the tests" required: false