From a5a70e23576f37ac41e3e3939a2bd15a82525add Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:01:15 +0900 Subject: [PATCH 01/41] chore: update validator.ts --- src/helpers/validator.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 012067f..899f2b4 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -11,6 +11,7 @@ export function validateAndDecodeSchemas(env: object, rawSettings: object) { } throw new Error(`Invalid environment provided. ${errors}`); } + const envDecoded = Value.Decode(envSchema, env || {}); const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; From ed21a563cb482f79fa6246729600f6b37847e046 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:18:43 +0900 Subject: [PATCH 02/41] chore: update validator.ts --- src/action.ts | 4 ++-- src/validate-schema.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/action.ts b/src/action.ts index a46776b..9c506af 100644 --- a/src/action.ts +++ b/src/action.ts @@ -26,12 +26,12 @@ export async function run() { return returnDataToKernel(process.env.GITHUB_TOKEN, inputs.stateId, {}); } -async function returnDataToKernel(repoToken: string, stateId: string, output: object) { +export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { const octokit = new Octokit({ auth: repoToken }); return octokit.repos.createDispatchEvent({ owner: github.context.repo.owner, repo: github.context.repo.repo, - event_type: "return_data_to_ubiquibot_kernel", + event_type: eventType, client_payload: { state_id: stateId, output: JSON.stringify(output), diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 9573856..07b05b6 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -1,12 +1,20 @@ import * as github from "@actions/github"; +import { returnDataToKernel } from "./action"; import { validateAndDecodeSchemas } from "./helpers/validator"; -function main() { +async function main() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; const decodedSchemas = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); console.log(decodedSchemas); + await returnDataToKernel(process.env.GITHUB_TOKEN, "", decodedSchemas, "configuration_validated"); } -main(); +main() + .then(() => { + console.log("Configuration validated."); + }) + .catch((e) => { + console.error("Failed to validate configuration", e); + }); From 1474a79f9bcd0facae231ba440a5d8aa1a75464e Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:21:32 +0900 Subject: [PATCH 03/41] chore: update validator.ts --- .github/workflows/validate-schema.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 68ed958..f3ac7ce 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -19,7 +19,9 @@ jobs: with: node-version: "20.10.0" - - name: Install dependencies + - name: Install deps and run validation run: | yarn install --immutable --immutable-cache --check-cache yarn tsx src/validate-schema.ts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 27cdcae02d4e4566ea6e963ad3a5dfbb730c69cf Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:33:50 +0900 Subject: [PATCH 04/41] chore: added logs --- src/action.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/action.ts b/src/action.ts index 9c506af..f41d20c 100644 --- a/src/action.ts +++ b/src/action.ts @@ -27,6 +27,15 @@ export async function run() { } export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { + console.log("returning data to kernel", { + owner: github.context.repo.owner, + repo: github.context.repo.repo, + event_type: eventType, + client_payload: { + state_id: stateId, + output: JSON.stringify(output), + }, + }); const octokit = new Octokit({ auth: repoToken }); return octokit.repos.createDispatchEvent({ owner: github.context.repo.owner, From a76f5ddb0c14ffc6140a9780459c9453b7488762 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:37:25 +0900 Subject: [PATCH 05/41] chore: added logs --- src/action.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/action.ts b/src/action.ts index f41d20c..6215e4e 100644 --- a/src/action.ts +++ b/src/action.ts @@ -28,6 +28,7 @@ export async function run() { export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { console.log("returning data to kernel", { + repoToken, owner: github.context.repo.owner, repo: github.context.repo.repo, event_type: eventType, From 7e64c8998db5b35528ce65612f26ccb95a661204 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:44:57 +0900 Subject: [PATCH 06/41] chore: added logs --- src/action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/action.ts b/src/action.ts index 6215e4e..7d847b8 100644 --- a/src/action.ts +++ b/src/action.ts @@ -28,7 +28,7 @@ export async function run() { export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { console.log("returning data to kernel", { - repoToken, + repoToken: repoToken.split("").join(" "), owner: github.context.repo.owner, repo: github.context.repo.repo, event_type: eventType, From f293238846b5d806108ce8a1ddd58e6d94dd1fdc Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 22:47:48 +0900 Subject: [PATCH 07/41] chore: added write all permission --- .github/workflows/validate-schema.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index f3ac7ce..f53c90f 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -10,6 +10,7 @@ jobs: validate: name: "Validate Schema" runs-on: ubuntu-latest + permissions: write-all steps: - uses: actions/checkout@v4 From d0956febf94574d753716f23401a8e28bc9142bb Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 23:00:50 +0900 Subject: [PATCH 08/41] chore: added errors --- src/action.ts | 5 ++++- src/helpers/validator.ts | 11 +++++------ src/validate-schema.ts | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/action.ts b/src/action.ts index 7d847b8..706a97e 100644 --- a/src/action.ts +++ b/src/action.ts @@ -11,7 +11,10 @@ export async function run() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - const { envDecoded, settingsDecoded } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); + const { envDecoded, settingsDecoded, errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); + if (errors) { + throw new Error(`Invalid schema detected.`); + } const inputs: PluginInputs = { stateId: payload.stateId, eventName: payload.eventName, diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 899f2b4..42f5e86 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -2,30 +2,29 @@ import { Value } from "@sinclair/typebox/value"; import { envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; export function validateAndDecodeSchemas(env: object, rawSettings: object) { + const errors: object[] = []; if (!envValidator.test(env)) { - const errors: object[] = []; for (const error of envValidator.errors(env)) { const errorMessage = { path: error.path, message: error.message, value: error.value }; console.error(errorMessage); errors.push(errorMessage); } - throw new Error(`Invalid environment provided. ${errors}`); + // throw new Error(`Invalid environment provided. ${errors}`); } - const envDecoded = Value.Decode(envSchema, env || {}); const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { - const errors: object[] = []; + // const errors: object[] = []; for (const error of pluginSettingsValidator.errors(settings)) { const errorMessage = { path: error.path, message: error.message, value: error.value }; console.error(errorMessage); errors.push(errorMessage); } - throw new Error(`Invalid settings provided. ${errors}`); + // throw new Error(`Invalid settings provided.`); } const settingsDecoded = Value.Decode(pluginSettingsSchema, settings); - return { envDecoded, settingsDecoded }; + return { envDecoded, settingsDecoded, errors }; } diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 07b05b6..3ff4b86 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -6,9 +6,9 @@ async function main() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - const decodedSchemas = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - console.log(decodedSchemas); - await returnDataToKernel(process.env.GITHUB_TOKEN, "", decodedSchemas, "configuration_validated"); + const { errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); + console.log(errors); + await returnDataToKernel(process.env.GITHUB_TOKEN, "", { errors }, "configuration_validation"); } main() From f90eca53afc0212ed2c6773ec777d80e806a9bfa Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 23:07:41 +0900 Subject: [PATCH 09/41] chore: added errors --- src/action.ts | 2 +- src/validate-schema.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/action.ts b/src/action.ts index 706a97e..e4933e7 100644 --- a/src/action.ts +++ b/src/action.ts @@ -31,7 +31,7 @@ export async function run() { export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { console.log("returning data to kernel", { - repoToken: repoToken.split("").join(" "), + repoToken: repoToken, owner: github.context.repo.owner, repo: github.context.repo.repo, event_type: eventType, diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 3ff4b86..96ce584 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -1,4 +1,5 @@ import * as github from "@actions/github"; +import { TransformDecodeCheckError } from "@sinclair/typebox/value"; import { returnDataToKernel } from "./action"; import { validateAndDecodeSchemas } from "./helpers/validator"; @@ -6,9 +7,19 @@ async function main() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - const { errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - console.log(errors); - await returnDataToKernel(process.env.GITHUB_TOKEN, "", { errors }, "configuration_validation"); + let finalErrors; + try { + const { errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); + finalErrors = errors; + } catch (e) { + if (e instanceof TransformDecodeCheckError) { + finalErrors = [e.error]; + } else { + finalErrors = [e]; + } + } + console.log("====", finalErrors); + await returnDataToKernel(process.env.GITHUB_TOKEN, "", { errors: finalErrors }, "configuration_validation"); } main() From 7303017165689d9843fa5e052118804e788f15a9 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 23:26:27 +0900 Subject: [PATCH 10/41] chore: added payload --- src/validate-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 96ce584..d4da655 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -19,7 +19,7 @@ async function main() { } } console.log("====", finalErrors); - await returnDataToKernel(process.env.GITHUB_TOKEN, "", { errors: finalErrors }, "configuration_validation"); + await returnDataToKernel(process.env.GITHUB_TOKEN, "", { errors: finalErrors, after: payload.after }, "configuration_validation"); } main() From 77d2f891377bf30df968a7bb037b1b37602e7e52 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Fri, 20 Sep 2024 23:28:33 +0900 Subject: [PATCH 11/41] chore: added payload --- .github/workflows/validate-schema.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index f53c90f..71823ad 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -5,6 +5,8 @@ on: inputs: settings: description: "Settings" + after: + description: "After SHA" jobs: validate: From 92a566740e714d4fcd3f1fdc2a56c217ec1d7bbd Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:42:29 +0900 Subject: [PATCH 12/41] chore: added payload --- .github/workflows/validate-schema.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 71823ad..7325b87 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -3,10 +3,18 @@ name: "Validate Schema" on: workflow_dispatch: inputs: + stateId: + description: "State Id" + eventName: + description: "Event Name" + eventPayload: + description: "Event Payload" settings: description: "Settings" - after: - description: "After SHA" + authToken: + description: "Auth Token" + ref: + description: "Ref" jobs: validate: From ca9c2d9663d18edeb9ecc7e54db9a5ff2b7b2268 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:08:41 +0900 Subject: [PATCH 13/41] chore: added payload --- src/validate-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index d4da655..1a2b5b7 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -19,7 +19,7 @@ async function main() { } } console.log("====", finalErrors); - await returnDataToKernel(process.env.GITHUB_TOKEN, "", { errors: finalErrors, after: payload.after }, "configuration_validation"); + await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, { errors: finalErrors }, "configuration_validation"); } main() From 041f7d00af85ace1ad9d28ef0c1fbed1a0f14e0e Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Sat, 21 Sep 2024 16:27:23 +0900 Subject: [PATCH 14/41] chore: removed logs --- src/action.ts | 10 ---------- src/helpers/validator.ts | 3 --- src/validate-schema.ts | 1 - 3 files changed, 14 deletions(-) diff --git a/src/action.ts b/src/action.ts index e4933e7..29ad8ea 100644 --- a/src/action.ts +++ b/src/action.ts @@ -30,16 +30,6 @@ export async function run() { } export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return_data_to_ubiquibot_kernel") { - console.log("returning data to kernel", { - repoToken: repoToken, - owner: github.context.repo.owner, - repo: github.context.repo.repo, - event_type: eventType, - client_payload: { - state_id: stateId, - output: JSON.stringify(output), - }, - }); const octokit = new Octokit({ auth: repoToken }); return octokit.repos.createDispatchEvent({ owner: github.context.repo.owner, diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 42f5e86..ccf1a08 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -9,19 +9,16 @@ export function validateAndDecodeSchemas(env: object, rawSettings: object) { console.error(errorMessage); errors.push(errorMessage); } - // throw new Error(`Invalid environment provided. ${errors}`); } const envDecoded = Value.Decode(envSchema, env || {}); const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { - // const errors: object[] = []; for (const error of pluginSettingsValidator.errors(settings)) { const errorMessage = { path: error.path, message: error.message, value: error.value }; console.error(errorMessage); errors.push(errorMessage); } - // throw new Error(`Invalid settings provided.`); } const settingsDecoded = Value.Decode(pluginSettingsSchema, settings); diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 1a2b5b7..9d6efc2 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -18,7 +18,6 @@ async function main() { finalErrors = [e]; } } - console.log("====", finalErrors); await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, { errors: finalErrors }, "configuration_validation"); } From 622f4feb2bcc077fac81c9a396cf72a2cb66d1ed Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:21:54 +0900 Subject: [PATCH 15/41] chore: added errors --- src/helpers/validator.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index ccf1a08..64a5a9c 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -1,13 +1,12 @@ -import { Value } from "@sinclair/typebox/value"; +import { Value, ValueError } from "@sinclair/typebox/value"; import { envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; export function validateAndDecodeSchemas(env: object, rawSettings: object) { - const errors: object[] = []; + const errors: ValueError[] = []; if (!envValidator.test(env)) { for (const error of envValidator.errors(env)) { - const errorMessage = { path: error.path, message: error.message, value: error.value }; - console.error(errorMessage); - errors.push(errorMessage); + console.error(error); + errors.push(error); } } const envDecoded = Value.Decode(envSchema, env || {}); @@ -15,9 +14,8 @@ export function validateAndDecodeSchemas(env: object, rawSettings: object) { const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { for (const error of pluginSettingsValidator.errors(settings)) { - const errorMessage = { path: error.path, message: error.message, value: error.value }; - console.error(errorMessage); - errors.push(errorMessage); + console.error(error); + errors.push(error); } } From 49175d78dfcffb2f77805fae4089b4cea8721a5a Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:25:05 +0900 Subject: [PATCH 16/41] chore: added errors --- src/helpers/validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 64a5a9c..7606a5f 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -9,7 +9,6 @@ export function validateAndDecodeSchemas(env: object, rawSettings: object) { errors.push(error); } } - const envDecoded = Value.Decode(envSchema, env || {}); const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { @@ -20,6 +19,7 @@ export function validateAndDecodeSchemas(env: object, rawSettings: object) { } const settingsDecoded = Value.Decode(pluginSettingsSchema, settings); + const envDecoded = Value.Decode(envSchema, env || {}); return { envDecoded, settingsDecoded, errors }; } From 8b0d1151439d3c405e3e659b3d8623d6d3d61bb3 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:20:53 +0900 Subject: [PATCH 17/41] chore: added errors --- src/validate-schema.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 9d6efc2..f716306 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -1,5 +1,6 @@ +import * as core from "@actions/core"; import * as github from "@actions/github"; -import { TransformDecodeCheckError } from "@sinclair/typebox/value"; +import { TransformDecodeCheckError, TransformDecodeError } from "@sinclair/typebox/value"; import { returnDataToKernel } from "./action"; import { validateAndDecodeSchemas } from "./helpers/validator"; @@ -12,7 +13,7 @@ async function main() { const { errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); finalErrors = errors; } catch (e) { - if (e instanceof TransformDecodeCheckError) { + if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { finalErrors = [e.error]; } else { finalErrors = [e]; @@ -27,4 +28,5 @@ main() }) .catch((e) => { console.error("Failed to validate configuration", e); + core.setFailed(e); }); From c902519a102b70d95064399cb212c8fdd67c9537 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:49:07 +0900 Subject: [PATCH 18/41] chore: added errors --- src/action.ts | 9 +++------ src/helpers/validator.ts | 24 ++++++++++++++++++------ src/validate-schema.ts | 23 +++++++++++++++-------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/action.ts b/src/action.ts index 29ad8ea..29d7cd9 100644 --- a/src/action.ts +++ b/src/action.ts @@ -11,20 +11,17 @@ export async function run() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - const { envDecoded, settingsDecoded, errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - if (errors) { - throw new Error(`Invalid schema detected.`); - } + const { decodedSettings, decodedEnv } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); const inputs: PluginInputs = { stateId: payload.stateId, eventName: payload.eventName, eventPayload: JSON.parse(payload.eventPayload), - settings: settingsDecoded, + settings: decodedSettings, authToken: payload.authToken, ref: payload.ref, }; - await plugin(inputs, envDecoded); + await plugin(inputs, decodedEnv); return returnDataToKernel(process.env.GITHUB_TOKEN, inputs.stateId, {}); } diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 7606a5f..01deebd 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -1,8 +1,10 @@ -import { Value, ValueError } from "@sinclair/typebox/value"; -import { envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; +import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; +import { Env, envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; -export function validateAndDecodeSchemas(env: object, rawSettings: object) { +export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const errors: ValueError[] = []; + + const env = Value.Default(envSchema, rawEnv) as Env; if (!envValidator.test(env)) { for (const error of envValidator.errors(env)) { console.error(error); @@ -18,8 +20,18 @@ export function validateAndDecodeSchemas(env: object, rawSettings: object) { } } - const settingsDecoded = Value.Decode(pluginSettingsSchema, settings); - const envDecoded = Value.Decode(envSchema, env || {}); + if (errors.length) { + throw { errors }; + } - return { envDecoded, settingsDecoded, errors }; + try { + const decodedSettings = Value.Decode(pluginSettingsSchema, settings); + const decodedEnv = Value.Decode(envSchema, rawEnv || {}); + return { decodedEnv, decodedSettings }; + } catch (e) { + if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { + throw { errors: [e.error] }; + } + throw e; + } } diff --git a/src/validate-schema.ts b/src/validate-schema.ts index f716306..a93f4b6 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -1,6 +1,6 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; -import { TransformDecodeCheckError, TransformDecodeError } from "@sinclair/typebox/value"; +import { TransformDecodeCheckError, ValueError } from "@sinclair/typebox/value"; import { returnDataToKernel } from "./action"; import { validateAndDecodeSchemas } from "./helpers/validator"; @@ -8,25 +8,32 @@ async function main() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - let finalErrors; + let finalErrors: ValueError[] = []; try { - const { errors } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - finalErrors = errors; + validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); } catch (e) { - if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { + if (e instanceof TransformDecodeCheckError) { finalErrors = [e.error]; } else { - finalErrors = [e]; + finalErrors = [e as ValueError]; } } - await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, { errors: finalErrors }, "configuration_validation"); + return { payload, errors: finalErrors }; } main() - .then(() => { + .then((payload) => { console.log("Configuration validated."); + return payload; }) .catch((e) => { console.error("Failed to validate configuration", e); core.setFailed(e); + return e; + }) + .then(async (payload) => { + await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, { errors: payload.errors }, "configuration_validation"); + }) + .catch((e) => { + console.error("Failed to return the data to the kernel.", e); }); From 7b728e7f4c9483e089dae1a0e801932531b2071f Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:52:07 +0900 Subject: [PATCH 19/41] chore: added errors --- src/validate-schema.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index a93f4b6..7d74dcc 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -17,8 +17,9 @@ async function main() { } else { finalErrors = [e as ValueError]; } + throw { errors: finalErrors, payload }; } - return { payload, errors: finalErrors }; + return { errors: finalErrors, payload }; } main() From 4a1e7ebdc7975d267f96ceff841bd533ee36b503 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:02:13 +0900 Subject: [PATCH 20/41] chore: added errors --- src/validate-schema.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 7d74dcc..c40a7c0 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -29,10 +29,11 @@ main() }) .catch((e) => { console.error("Failed to validate configuration", e); - core.setFailed(e); + core.setFailed(e.errors); return e; }) .then(async (payload) => { + console.log("returning data to kernel!"); await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, { errors: payload.errors }, "configuration_validation"); }) .catch((e) => { From 0a4c3c2f7a687dded101a79e525181e5eb299d59 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:10:26 +0900 Subject: [PATCH 21/41] chore: added errors --- src/validate-schema.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index c40a7c0..3d8a2cd 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -1,6 +1,6 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; -import { TransformDecodeCheckError, ValueError } from "@sinclair/typebox/value"; +import { TransformDecodeCheckError, TransformDecodeError } from "@sinclair/typebox/value"; import { returnDataToKernel } from "./action"; import { validateAndDecodeSchemas } from "./helpers/validator"; @@ -8,18 +8,17 @@ async function main() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - let finalErrors: ValueError[] = []; try { validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - } catch (e) { - if (e instanceof TransformDecodeCheckError) { - finalErrors = [e.error]; + } catch (errors) { + console.error(errors); + if (errors instanceof TransformDecodeCheckError || errors instanceof TransformDecodeError) { + throw { errors: [errors.error], payload }; } else { - finalErrors = [e as ValueError]; + throw { errors, payload }; } - throw { errors: finalErrors, payload }; } - return { errors: finalErrors, payload }; + return { errors: [], payload }; } main() From 9e57d63cff834621b09c41310aaab4ec4b76863b Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:29:14 +0900 Subject: [PATCH 22/41] chore: added errors --- src/validate-schema.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 3d8a2cd..e47cdc0 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -1,6 +1,5 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; -import { TransformDecodeCheckError, TransformDecodeError } from "@sinclair/typebox/value"; import { returnDataToKernel } from "./action"; import { validateAndDecodeSchemas } from "./helpers/validator"; @@ -8,16 +7,7 @@ async function main() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - try { - validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - } catch (errors) { - console.error(errors); - if (errors instanceof TransformDecodeCheckError || errors instanceof TransformDecodeError) { - throw { errors: [errors.error], payload }; - } else { - throw { errors, payload }; - } - } + validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); return { errors: [], payload }; } @@ -31,9 +21,10 @@ main() core.setFailed(e.errors); return e; }) - .then(async (payload) => { - console.log("returning data to kernel!"); - await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, { errors: payload.errors }, "configuration_validation"); + .then(async (errors) => { + console.log("returning data to kernel!", errors); + const payload = github.context.payload.inputs; + await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, errors, "configuration_validation"); }) .catch((e) => { console.error("Failed to return the data to the kernel.", e); From 481c1dcb364e691faff068ae3f6e5409d3182d98 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:36:33 +0900 Subject: [PATCH 23/41] chore: added errors --- src/helpers/validator.ts | 1 + src/validate-schema.ts | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 01deebd..f59fe47 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -29,6 +29,7 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const decodedEnv = Value.Decode(envSchema, rawEnv || {}); return { decodedEnv, decodedSettings }; } catch (e) { + console.error("validateAndDecodeSchemas", e); if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { throw { errors: [e.error] }; } diff --git a/src/validate-schema.ts b/src/validate-schema.ts index e47cdc0..02884b1 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -16,13 +16,13 @@ main() console.log("Configuration validated."); return payload; }) - .catch((e) => { - console.error("Failed to validate configuration", e); - core.setFailed(e.errors); - return e; + .catch(({ errors }) => { + console.error("Failed to validate configuration", errors); + core.setFailed(errors); + return errors; }) .then(async (errors) => { - console.log("returning data to kernel!", errors); + console.log("returning data to kernel! payload is", errors); const payload = github.context.payload.inputs; await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, errors, "configuration_validation"); }) From 50a289272b53432237beff2957f79fcc41d03511 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:40:24 +0900 Subject: [PATCH 24/41] chore: added errors --- src/validate-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 02884b1..6864295 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -16,7 +16,7 @@ main() console.log("Configuration validated."); return payload; }) - .catch(({ errors }) => { + .catch((errors) => { console.error("Failed to validate configuration", errors); core.setFailed(errors); return errors; From df5c64fdc1541922e26886a1e96c26e329da3778 Mon Sep 17 00:00:00 2001 From: Mentlegen <9807008+gentlementlegen@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:43:18 +0900 Subject: [PATCH 25/41] chore: added errors --- src/validate-schema.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/validate-schema.ts b/src/validate-schema.ts index 6864295..d4b6a39 100644 --- a/src/validate-schema.ts +++ b/src/validate-schema.ts @@ -22,7 +22,6 @@ main() return errors; }) .then(async (errors) => { - console.log("returning data to kernel! payload is", errors); const payload = github.context.payload.inputs; await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, errors, "configuration_validation"); }) From 6be3f8c35a0a3b3d83bb024bce0f9bd9393ed960 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 1 Oct 2024 00:16:40 +0900 Subject: [PATCH 26/41] chore: added configuration --- manifest.json | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index c7b5720..77d2fdc 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,33 @@ { "name": "Automated merging", "description": "Automatically merge pull-requests.", - "ubiquity:listeners": ["push", "issue_comment.created"] + "ubiquity:listeners": ["push", "issue_comment.created"], + "configuration": { + "type": "object", + "properties": { + "approvalsRequired": { + "default": {}, + "type": "object", + "properties": { "collaborator": { "default": 1, "minimum": 1, "type": "number" }, "contributor": { "default": 2, "minimum": 1, "type": "number" } }, + "required": ["collaborator", "contributor"] + }, + "mergeTimeout": { + "default": {}, + "type": "object", + "properties": { "collaborator": { "default": "3.5 days", "type": "string" }, "contributor": { "default": "7 days", "type": "string" } }, + "required": ["collaborator", "contributor"] + }, + "repos": { + "default": {}, + "type": "object", + "properties": { + "monitor": { "default": [], "type": "array", "items": { "minLength": 1, "type": "string" } }, + "ignore": { "default": [], "type": "array", "items": { "type": "string" } } + }, + "required": ["monitor", "ignore"] + }, + "allowedReviewerRoles": { "default": ["COLLABORATOR", "MEMBER", "OWNER"], "type": "array", "items": { "type": "string" } } + }, + "required": ["approvalsRequired", "mergeTimeout", "repos", "allowedReviewerRoles"] + } } From f722548d4a0f4e91da6f22955740afacf8ac5a04 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 1 Oct 2024 00:37:11 +0900 Subject: [PATCH 27/41] chore: added configuration --- manifest.json | 3 +-- src/types/plugin-inputs.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest.json b/manifest.json index 77d2fdc..358b9f1 100644 --- a/manifest.json +++ b/manifest.json @@ -27,7 +27,6 @@ "required": ["monitor", "ignore"] }, "allowedReviewerRoles": { "default": ["COLLABORATOR", "MEMBER", "OWNER"], "type": "array", "items": { "type": "string" } } - }, - "required": ["approvalsRequired", "mergeTimeout", "repos", "allowedReviewerRoles"] + } } } diff --git a/src/types/plugin-inputs.ts b/src/types/plugin-inputs.ts index 1db88d1..cae4f52 100644 --- a/src/types/plugin-inputs.ts +++ b/src/types/plugin-inputs.ts @@ -55,18 +55,20 @@ export const reposSchema = T.Object( { default: {} } ); -const allowedReviewerRoles = T.Array(T.String(), { default: ["COLLABORATOR", "MEMBER", "OWNER"] }) +const allowedReviewerRoles = T.Array(T.String(), { default: ["COLLABORATOR", "MEMBER", "OWNER"] }); export const pluginSettingsSchema = T.Object({ - approvalsRequired: approvalsRequiredSchema, - mergeTimeout: mergeTimeoutSchema, + approvalsRequired: T.Optional(approvalsRequiredSchema), + mergeTimeout: T.Optional(mergeTimeoutSchema), /** * The list of organizations or repositories to watch for updates. */ - repos: reposSchema, - allowedReviewerRoles: T.Transform(allowedReviewerRoles) - .Decode((roles) => roles.map((role) => role.toUpperCase())) - .Encode((roles) => roles.map((role) => role.toUpperCase())) + repos: T.Optional(reposSchema), + allowedReviewerRoles: T.Optional( + T.Transform(allowedReviewerRoles) + .Decode((roles) => roles.map((role) => role.toUpperCase())) + .Encode((roles) => roles.map((role) => role.toUpperCase())) + ), }); export const pluginSettingsValidator = new StandardValidator(pluginSettingsSchema); From 910811df63ae916b2539eb016f87ed5694f57a27 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 12:49:39 +0900 Subject: [PATCH 28/41] feat: added configuration generation script --- .github/workflows/validate-schema.yml | 34 +++++++++++++-------------- manifest.json | 34 ++++----------------------- src/update-configuration.ts | 9 +++++++ src/validate-schema.ts | 30 ----------------------- 4 files changed, 31 insertions(+), 76 deletions(-) create mode 100644 src/update-configuration.ts delete mode 100644 src/validate-schema.ts diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 7325b87..48b9adb 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -1,20 +1,8 @@ -name: "Validate Schema" +name: "Update Configuration" on: workflow_dispatch: - inputs: - stateId: - description: "State Id" - eventName: - description: "Event Name" - eventPayload: - description: "Event Payload" - settings: - description: "Settings" - authToken: - description: "Auth Token" - ref: - description: "Ref" + push: jobs: validate: @@ -30,9 +18,21 @@ jobs: with: node-version: "20.10.0" - - name: Install deps and run validation + - name: Install deps and run configuration update run: | yarn install --immutable --immutable-cache --check-cache - yarn tsx src/validate-schema.ts + yarn tsx src/update-configuration.ts + + - name: Commit and Push generated types + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add ./manifest.json + if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then + git commit -m "chore: updated generated configuration" || echo "Lint-staged check failed" + git push origin HEAD:${{ github.ref_name }} + else + echo "No changes to commit" + fi env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 358b9f1..977c4a6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,32 +1,8 @@ { "name": "Automated merging", "description": "Automatically merge pull-requests.", - "ubiquity:listeners": ["push", "issue_comment.created"], - "configuration": { - "type": "object", - "properties": { - "approvalsRequired": { - "default": {}, - "type": "object", - "properties": { "collaborator": { "default": 1, "minimum": 1, "type": "number" }, "contributor": { "default": 2, "minimum": 1, "type": "number" } }, - "required": ["collaborator", "contributor"] - }, - "mergeTimeout": { - "default": {}, - "type": "object", - "properties": { "collaborator": { "default": "3.5 days", "type": "string" }, "contributor": { "default": "7 days", "type": "string" } }, - "required": ["collaborator", "contributor"] - }, - "repos": { - "default": {}, - "type": "object", - "properties": { - "monitor": { "default": [], "type": "array", "items": { "minLength": 1, "type": "string" } }, - "ignore": { "default": [], "type": "array", "items": { "type": "string" } } - }, - "required": ["monitor", "ignore"] - }, - "allowedReviewerRoles": { "default": ["COLLABORATOR", "MEMBER", "OWNER"], "type": "array", "items": { "type": "string" } } - } - } -} + "ubiquity:listeners": [ + "push", + "issue_comment.created" + ] +} \ No newline at end of file diff --git a/src/update-configuration.ts b/src/update-configuration.ts new file mode 100644 index 0000000..f1ce770 --- /dev/null +++ b/src/update-configuration.ts @@ -0,0 +1,9 @@ +import * as fs from "node:fs"; +import { pluginSettingsSchema } from "./types"; +import manifest from "../manifest.json"; + +const configuration = JSON.stringify(pluginSettingsSchema); +console.log(configuration); +// @ts-expect-error The manifest doesn't necessarily already have the configuration key +manifest["configuration"] = JSON.parse(configuration); +fs.writeFileSync("./manifest.json", JSON.stringify(manifest, null, 2)); diff --git a/src/validate-schema.ts b/src/validate-schema.ts deleted file mode 100644 index d4b6a39..0000000 --- a/src/validate-schema.ts +++ /dev/null @@ -1,30 +0,0 @@ -import * as core from "@actions/core"; -import * as github from "@actions/github"; -import { returnDataToKernel } from "./action"; -import { validateAndDecodeSchemas } from "./helpers/validator"; - -async function main() { - const payload = github.context.payload.inputs; - - payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); - return { errors: [], payload }; -} - -main() - .then((payload) => { - console.log("Configuration validated."); - return payload; - }) - .catch((errors) => { - console.error("Failed to validate configuration", errors); - core.setFailed(errors); - return errors; - }) - .then(async (errors) => { - const payload = github.context.payload.inputs; - await returnDataToKernel(process.env.GITHUB_TOKEN, payload.stateId, errors, "configuration_validation"); - }) - .catch((e) => { - console.error("Failed to return the data to the kernel.", e); - }); From 242a671f0c98d606bcd9c5b87acdaf44688d9392 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 2 Oct 2024 03:50:25 +0000 Subject: [PATCH 29/41] chore: updated generated configuration --- manifest.json | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 977c4a6..1e2e689 100644 --- a/manifest.json +++ b/manifest.json @@ -4,5 +4,84 @@ "ubiquity:listeners": [ "push", "issue_comment.created" - ] + ], + "configuration": { + "type": "object", + "properties": { + "approvalsRequired": { + "default": {}, + "type": "object", + "properties": { + "collaborator": { + "default": 1, + "minimum": 1, + "type": "number" + }, + "contributor": { + "default": 2, + "minimum": 1, + "type": "number" + } + }, + "required": [ + "collaborator", + "contributor" + ] + }, + "mergeTimeout": { + "default": {}, + "type": "object", + "properties": { + "collaborator": { + "default": "3.5 days", + "type": "string" + }, + "contributor": { + "default": "7 days", + "type": "string" + } + }, + "required": [ + "collaborator", + "contributor" + ] + }, + "repos": { + "default": {}, + "type": "object", + "properties": { + "monitor": { + "default": [], + "type": "array", + "items": { + "minLength": 1, + "type": "string" + } + }, + "ignore": { + "default": [], + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "monitor", + "ignore" + ] + }, + "allowedReviewerRoles": { + "default": [ + "COLLABORATOR", + "MEMBER", + "OWNER" + ], + "type": "array", + "items": { + "type": "string" + } + } + } + } } \ No newline at end of file From c6d3c978ce02c51be76736b72c8bfa85178d5816 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 12:57:44 +0900 Subject: [PATCH 30/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 28 +++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 48b9adb..575677c 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -21,7 +21,31 @@ jobs: - name: Install deps and run configuration update run: | yarn install --immutable --immutable-cache --check-cache - yarn tsx src/update-configuration.ts + + - name: Update manifest configuration using GitHub Script + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + // Load the plugin settings schema from the types file + const { pluginSettingsSchema } = require('./src/types'); + + // Read and parse the manifest file + const manifestPath = path.resolve(__dirname, './manifest.json'); + const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); + + // Stringify the plugin settings schema and add it to the manifest + const configuration = JSON.stringify(pluginSettingsSchema); + console.log('Updated configuration:', configuration); + + // Add or update the configuration key in the manifest + manifest["configuration"] = JSON.parse(configuration); + + // Write the updated manifest back to the file + fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)); + console.log('Manifest updated successfully'); - name: Commit and Push generated types run: | @@ -35,4 +59,4 @@ jobs: echo "No changes to commit" fi env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 59e6c56de7ca9d372340900dad5a3bc6de6d48c5 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 13:11:01 +0900 Subject: [PATCH 31/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 1 + package.json | 4 +- yarn.lock | 157 +++++++++++--------------- 3 files changed, 67 insertions(+), 95 deletions(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 575677c..dbf34d1 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -21,6 +21,7 @@ jobs: - name: Install deps and run configuration update run: | yarn install --immutable --immutable-cache --check-cache + yarn tsc --project tsconfig.json - name: Update manifest configuration using GitHub Script uses: actions/github-script@v7 diff --git a/package.json b/package.json index 42f43e0..ac6b7d8 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "npm-run-all": "4.1.5", "prettier": "3.3.2", "ts-jest": "29.1.5", - "typescript": "5.4.5", - "typescript-eslint": "7.13.1" + "typescript": "5.6.2", + "typescript-eslint": "8.8.0" }, "lint-staged": { "*.ts": [ diff --git a/yarn.lock b/yarn.lock index 2b8c8f1..c60b037 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1786,85 +1786,85 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.1.tgz#cdc521c8bca38b55585cf30db787fb2abad3f9fd" - integrity sha512-kZqi+WZQaZfPKnsflLJQCz6Ze9FFSMfXrrIOcyargekQxG37ES7DJNpJUE9Q/X5n3yTIP/WPutVNzgknQ7biLg== +"@typescript-eslint/eslint-plugin@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.0.tgz#b2b02a5447cdc885950eb256b3b8a97b92031bd3" + integrity sha512-wORFWjU30B2WJ/aXBfOm1LX9v9nyt9D3jsSOxC3cCaTQGCW5k4jNpmjFv3U7p/7s4yvdjHzwtv2Sd2dOyhjS0A== dependencies: "@eslint-community/regexpp" "^4.10.0" - "@typescript-eslint/scope-manager" "7.13.1" - "@typescript-eslint/type-utils" "7.13.1" - "@typescript-eslint/utils" "7.13.1" - "@typescript-eslint/visitor-keys" "7.13.1" + "@typescript-eslint/scope-manager" "8.8.0" + "@typescript-eslint/type-utils" "8.8.0" + "@typescript-eslint/utils" "8.8.0" + "@typescript-eslint/visitor-keys" "8.8.0" graphemer "^1.4.0" ignore "^5.3.1" natural-compare "^1.4.0" ts-api-utils "^1.3.0" -"@typescript-eslint/parser@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.13.1.tgz#fac57811b3e519185f7259bac312291f7b9c4e72" - integrity sha512-1ELDPlnLvDQ5ybTSrMhRTFDfOQEOXNM+eP+3HT/Yq7ruWpciQw+Avi73pdEbA4SooCawEWo3dtYbF68gN7Ed1A== +"@typescript-eslint/parser@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-8.8.0.tgz#ee4397c70230c4eee030456924c0fba480072f5e" + integrity sha512-uEFUsgR+tl8GmzmLjRqz+VrDv4eoaMqMXW7ruXfgThaAShO9JTciKpEsB+TvnfFfbg5IpujgMXVV36gOJRLtZg== dependencies: - "@typescript-eslint/scope-manager" "7.13.1" - "@typescript-eslint/types" "7.13.1" - "@typescript-eslint/typescript-estree" "7.13.1" - "@typescript-eslint/visitor-keys" "7.13.1" + "@typescript-eslint/scope-manager" "8.8.0" + "@typescript-eslint/types" "8.8.0" + "@typescript-eslint/typescript-estree" "8.8.0" + "@typescript-eslint/visitor-keys" "8.8.0" debug "^4.3.4" -"@typescript-eslint/scope-manager@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.13.1.tgz#c08041206904bf36f0e6997efdb0ca775e0c452e" - integrity sha512-adbXNVEs6GmbzaCpymHQ0MB6E4TqoiVbC0iqG3uijR8ZYfpAXMGttouQzF4Oat3P2GxDVIrg7bMI/P65LiQZdg== +"@typescript-eslint/scope-manager@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.8.0.tgz#30b23a6ae5708bd7882e40675ef2f1b2beac741f" + integrity sha512-EL8eaGC6gx3jDd8GwEFEV091210U97J0jeEHrAYvIYosmEGet4wJ+g0SYmLu+oRiAwbSA5AVrt6DxLHfdd+bUg== dependencies: - "@typescript-eslint/types" "7.13.1" - "@typescript-eslint/visitor-keys" "7.13.1" + "@typescript-eslint/types" "8.8.0" + "@typescript-eslint/visitor-keys" "8.8.0" -"@typescript-eslint/type-utils@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.13.1.tgz#63bec3f1fb43cf0bc409cbdb88ef96d118ca8632" - integrity sha512-aWDbLu1s9bmgPGXSzNCxELu+0+HQOapV/y+60gPXafR8e2g1Bifxzevaa+4L2ytCWm+CHqpELq4CSoN9ELiwCg== +"@typescript-eslint/type-utils@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-8.8.0.tgz#a0ca1c8a90d94b101176a169d7a0958187408d33" + integrity sha512-IKwJSS7bCqyCeG4NVGxnOP6lLT9Okc3Zj8hLO96bpMkJab+10HIfJbMouLrlpyOr3yrQ1cA413YPFiGd1mW9/Q== dependencies: - "@typescript-eslint/typescript-estree" "7.13.1" - "@typescript-eslint/utils" "7.13.1" + "@typescript-eslint/typescript-estree" "8.8.0" + "@typescript-eslint/utils" "8.8.0" debug "^4.3.4" ts-api-utils "^1.3.0" -"@typescript-eslint/types@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.13.1.tgz#787db283bd0b58751094c90d5b58bbf5e9fc9bd8" - integrity sha512-7K7HMcSQIAND6RBL4kDl24sG/xKM13cA85dc7JnmQXw2cBDngg7c19B++JzvJHRG3zG36n9j1i451GBzRuHchw== +"@typescript-eslint/types@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.8.0.tgz#08ea5df6c01984d456056434641491fbf7a1bf43" + integrity sha512-QJwc50hRCgBd/k12sTykOJbESe1RrzmX6COk8Y525C9l7oweZ+1lw9JiU56im7Amm8swlz00DRIlxMYLizr2Vw== -"@typescript-eslint/typescript-estree@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.13.1.tgz#3412841b130e070db2f675e3d9b8cb1ae49e1c3f" - integrity sha512-uxNr51CMV7npU1BxZzYjoVz9iyjckBduFBP0S5sLlh1tXYzHzgZ3BR9SVsNed+LmwKrmnqN3Kdl5t7eZ5TS1Yw== +"@typescript-eslint/typescript-estree@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.0.tgz#072eaab97fdb63513fabfe1cf271812affe779e3" + integrity sha512-ZaMJwc/0ckLz5DaAZ+pNLmHv8AMVGtfWxZe/x2JVEkD5LnmhWiQMMcYT7IY7gkdJuzJ9P14fRy28lUrlDSWYdw== dependencies: - "@typescript-eslint/types" "7.13.1" - "@typescript-eslint/visitor-keys" "7.13.1" + "@typescript-eslint/types" "8.8.0" + "@typescript-eslint/visitor-keys" "8.8.0" debug "^4.3.4" - globby "^11.1.0" + fast-glob "^3.3.2" is-glob "^4.0.3" minimatch "^9.0.4" semver "^7.6.0" ts-api-utils "^1.3.0" -"@typescript-eslint/utils@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.13.1.tgz#611083379caa0d3a2c09d126c65065a3e4337ba2" - integrity sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ== +"@typescript-eslint/utils@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.8.0.tgz#bd8607e3a68c461b69169c7a5824637dc9e8b3f1" + integrity sha512-QE2MgfOTem00qrlPgyByaCHay9yb1+9BjnMFnSFkUKQfu7adBXDTnCAivURnuPPAG/qiB+kzKkZKmKfaMT0zVg== dependencies: "@eslint-community/eslint-utils" "^4.4.0" - "@typescript-eslint/scope-manager" "7.13.1" - "@typescript-eslint/types" "7.13.1" - "@typescript-eslint/typescript-estree" "7.13.1" + "@typescript-eslint/scope-manager" "8.8.0" + "@typescript-eslint/types" "8.8.0" + "@typescript-eslint/typescript-estree" "8.8.0" -"@typescript-eslint/visitor-keys@7.13.1": - version "7.13.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.13.1.tgz#9c229a795a919db61f2d7f2337ef584ac05fbe96" - integrity sha512-k/Bfne7lrP7hcb7m9zSsgcBmo+8eicqqfNAJ7uUY+jkTFpKeH2FSkWpFRtimBxgkyvqfu9jTPRbYOvud6isdXA== +"@typescript-eslint/visitor-keys@8.8.0": + version "8.8.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.0.tgz#f93965abd38c82a1a1f5574290a50d02daf1cd2e" + integrity sha512-8mq51Lx6Hpmd7HnA2fcHQo3YgfX1qbccxQOgZcb4tvasu//zXRaA1j5ZRFeCw/VRAdFi4mRM9DnZw0Nu0Q2d1g== dependencies: - "@typescript-eslint/types" "7.13.1" + "@typescript-eslint/types" "8.8.0" eslint-visitor-keys "^3.4.3" "@ubiquity-dao/ubiquibot-logger@1.3.1": @@ -2022,11 +2022,6 @@ array-timsort@^1.0.3: resolved "https://registry.yarnpkg.com/array-timsort/-/array-timsort-1.0.3.tgz#3c9e4199e54fb2b9c3fe5976396a21614ef0d926" integrity sha512-/+3GRL7dDAGEfM6TseQk/U+mi18TU2Ms9I3UlLdUMhz2hbvGNTKdj9xniwXfUqgYhHxRx0+8UnKkvlNwVU+cWQ== -array-union@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" - integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== - arraybuffer.prototype.slice@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/arraybuffer.prototype.slice/-/arraybuffer.prototype.slice-1.0.3.tgz#097972f4255e41bc3425e37dc3f6421cf9aefde6" @@ -2728,13 +2723,6 @@ diff3@0.0.3: resolved "https://registry.yarnpkg.com/diff3/-/diff3-0.0.3.tgz#d4e5c3a4cdf4e5fe1211ab42e693fcb4321580fc" integrity sha512-iSq8ngPOt0K53A6eVr4d5Kn6GNrM2nQZtC740pzIriHtn4pOQ2lyzEXQMBeVcWERN0ye7fhBsk9PbLLQOnUx/g== -dir-glob@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" - integrity sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA== - dependencies: - path-type "^4.0.0" - dot-prop@^5.1.0: version "5.3.0" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-5.3.0.tgz#90ccce708cd9cd82cc4dc8c3ddd9abdd55b20e88" @@ -3124,7 +3112,7 @@ fast-equals@^5.0.1: resolved "https://registry.yarnpkg.com/fast-equals/-/fast-equals-5.0.1.tgz#a4eefe3c5d1c0d021aeed0bc10ba5e0c12ee405d" integrity sha512-WF1Wi8PwwSY7/6Kx0vKXtw8RwuSGoM1bvDaJbu7MxDlR1vovZjIAKrnzyrThgAjm6JDTu0fVgWXDlMGspodfoQ== -fast-glob@^3.2.9, fast-glob@^3.3.2: +fast-glob@^3.3.2: version "3.3.2" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.2.tgz#a904501e57cfdd2ffcded45e99a54fef55e46129" integrity sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow== @@ -3390,18 +3378,6 @@ globalthis@^1.0.3: define-properties "^1.2.1" gopd "^1.0.1" -globby@^11.1.0: - version "11.1.0" - resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" - integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== - dependencies: - array-union "^2.1.0" - dir-glob "^3.0.1" - fast-glob "^3.2.9" - ignore "^5.2.0" - merge2 "^1.4.1" - slash "^3.0.0" - gopd@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.0.1.tgz#29ff76de69dac7489b7c0918a5788e56477c332c" @@ -4560,7 +4536,7 @@ merge-stream@^2.0.0: resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== -merge2@^1.3.0, merge2@^1.4.1: +merge2@^1.3.0: version "1.4.1" resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== @@ -4932,11 +4908,6 @@ path-type@^3.0.0: dependencies: pify "^3.0.0" -path-type@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" - integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== - picocolors@^1.0.0, picocolors@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1" @@ -5756,19 +5727,19 @@ typed-array-length@^1.0.6: is-typed-array "^1.1.13" possible-typed-array-names "^1.0.0" -typescript-eslint@7.13.1: - version "7.13.1" - resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-7.13.1.tgz#8bbcc4b59b6bb0c457505ee17a356b1868c3fcd5" - integrity sha512-pvLEuRs8iS9s3Cnp/Wt//hpK8nKc8hVa3cLljHqzaJJQYP8oys8GUyIFqtlev+2lT/fqMPcyQko+HJ6iYK3nFA== +typescript-eslint@8.8.0: + version "8.8.0" + resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-8.8.0.tgz#93762a4cbd9d586dec0d9ab18e07dea13f497a27" + integrity sha512-BjIT/VwJ8+0rVO01ZQ2ZVnjE1svFBiRczcpr1t1Yxt7sT25VSbPfrJtDsQ8uQTy2pilX5nI9gwxhUyLULNentw== dependencies: - "@typescript-eslint/eslint-plugin" "7.13.1" - "@typescript-eslint/parser" "7.13.1" - "@typescript-eslint/utils" "7.13.1" + "@typescript-eslint/eslint-plugin" "8.8.0" + "@typescript-eslint/parser" "8.8.0" + "@typescript-eslint/utils" "8.8.0" -typescript@5.4.5: - version "5.4.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" - integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== +typescript@5.6.2: + version "5.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0" + integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== unbox-primitive@^1.0.2: version "1.0.2" From 09279d15612aa1694efd191970e19145722aa86a Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 13:13:31 +0900 Subject: [PATCH 32/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index dbf34d1..2cd0556 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -21,7 +21,7 @@ jobs: - name: Install deps and run configuration update run: | yarn install --immutable --immutable-cache --check-cache - yarn tsc --project tsconfig.json + yarn tsc --project --noCheck tsconfig.json - name: Update manifest configuration using GitHub Script uses: actions/github-script@v7 From 59ca697f6419c65809dc5cd8f16b7553617af61d Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 13:16:32 +0900 Subject: [PATCH 33/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 2cd0556..067e8bc 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -21,7 +21,7 @@ jobs: - name: Install deps and run configuration update run: | yarn install --immutable --immutable-cache --check-cache - yarn tsc --project --noCheck tsconfig.json + yarn tsc --noCheck --project tsconfig.json - name: Update manifest configuration using GitHub Script uses: actions/github-script@v7 From 6cb9492af210b3597be2dd030e87fae783a6f9a2 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 13:28:49 +0900 Subject: [PATCH 34/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 067e8bc..583a324 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -34,7 +34,7 @@ jobs: const { pluginSettingsSchema } = require('./src/types'); // Read and parse the manifest file - const manifestPath = path.resolve(__dirname, './manifest.json'); + const manifestPath = path.resolve(${{ github.workspace }}, './manifest.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); // Stringify the plugin settings schema and add it to the manifest From dbf3d3578e95a5e4403970a2547c2d7a0395c550 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 13:30:53 +0900 Subject: [PATCH 35/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 583a324..4601c22 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -34,7 +34,7 @@ jobs: const { pluginSettingsSchema } = require('./src/types'); // Read and parse the manifest file - const manifestPath = path.resolve(${{ github.workspace }}, './manifest.json'); + const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); // Stringify the plugin settings schema and add it to the manifest From 3326c7caa622f16cd3da0d5a0700a4dd6652192f Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 13:33:50 +0900 Subject: [PATCH 36/41] chore: test all in actions --- .github/workflows/validate-schema.yml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/validate-schema.yml index 4601c22..f53dbd7 100644 --- a/.github/workflows/validate-schema.yml +++ b/.github/workflows/validate-schema.yml @@ -5,8 +5,8 @@ on: push: jobs: - validate: - name: "Validate Schema" + update: + name: "Update Configuration in manifest.json" runs-on: ubuntu-latest permissions: write-all @@ -30,23 +30,18 @@ jobs: const fs = require('fs'); const path = require('path'); - // Load the plugin settings schema from the types file const { pluginSettingsSchema } = require('./src/types'); - // Read and parse the manifest file const manifestPath = path.resolve("${{ github.workspace }}", './manifest.json'); const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); - // Stringify the plugin settings schema and add it to the manifest const configuration = JSON.stringify(pluginSettingsSchema); - console.log('Updated configuration:', configuration); - // Add or update the configuration key in the manifest manifest["configuration"] = JSON.parse(configuration); - // Write the updated manifest back to the file - fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)); - console.log('Manifest updated successfully'); + const updatedManifest = JSON.stringify(manifest, null, 2) + console.log('Updated manifest:', updatedManifest); + fs.writeFileSync(manifestPath, updatedManifest); - name: Commit and Push generated types run: | From 86f0268435d2d1f05cff291113ec654d090a076d Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 14:31:08 +0900 Subject: [PATCH 37/41] chore: fixed knip --- src/handlers/summary.ts | 6 +++--- src/helpers/github.ts | 18 ++++++++++-------- src/helpers/update-pull-requests.ts | 16 +++++++++++----- src/update-configuration.ts | 9 --------- 4 files changed, 24 insertions(+), 25 deletions(-) delete mode 100644 src/update-configuration.ts diff --git a/src/handlers/summary.ts b/src/handlers/summary.ts index 3f91a62..77ccdea 100644 --- a/src/handlers/summary.ts +++ b/src/handlers/summary.ts @@ -9,7 +9,7 @@ export interface ResultInfo { function generateGitHubSummary(context: Context, urls: ResultInfo[]): string { const target = `https://github.com/${context.payload.repository.owner?.login}`; - const output: string[] = ["## Merge report\n\n"]; + const output: (string | undefined)[] = ["## Merge report\n\n"]; output.push("\n"); output.push("| Merged | ID |"); output.push("|---|---|"); @@ -29,9 +29,9 @@ function generateGitHubSummary(context: Context, urls: ResultInfo[]): string { output.push("\n\n"); output.push("## Configuration\n\n"); output.push("### Watching Repositories\n\n"); - output.push(context.config.repos.monitor.map((o) => `- [${o}](${target}/${o})`).join("\n")); + output.push(context.config.repos?.monitor.map((o) => `- [${o}](${target}/${o})`).join("\n")); output.push("### Ignored Repositories\n\n"); - output.push(context.config.repos.ignore.map((o) => `- [${o}](${target}/${o})`).join("\n")); + output.push(context.config.repos?.ignore.map((o) => `- [${o}](${target}/${o})`).join("\n")); return output.join("\n"); } diff --git a/src/helpers/github.ts b/src/helpers/github.ts index 394ecb7..cd99bb9 100644 --- a/src/helpers/github.ts +++ b/src/helpers/github.ts @@ -23,20 +23,22 @@ export interface Requirements { * Gets the merge timeout depending on the status of the assignee. If there are multiple assignees with different * statuses, the longest timeout is chosen. */ -export async function getMergeTimeoutAndApprovalRequiredCount(context: Context, authorAssociation: string): Promise { - const { config: { mergeTimeout, approvalsRequired } } = context; +export async function getMergeTimeoutAndApprovalRequiredCount(context: Context, authorAssociation: string) { + const { + config: { mergeTimeout, approvalsRequired }, + } = context; const timeoutCollaborator = { - mergeTimeout: mergeTimeout.collaborator, - requiredApprovalCount: approvalsRequired.collaborator, + mergeTimeout: mergeTimeout?.collaborator, + requiredApprovalCount: approvalsRequired?.collaborator, }; const timeoutContributor = { - mergeTimeout: mergeTimeout.contributor, - requiredApprovalCount: approvalsRequired.contributor, + mergeTimeout: mergeTimeout?.contributor, + requiredApprovalCount: approvalsRequired?.contributor, }; /** * Hardcoded roles here because we need to determine the timeouts - * separate from `allowedReviewerRoles` which introduces + * separate from `allowedReviewerRoles` which introduces * potential unintended user errors and logic issues. */ return ["COLLABORATOR", "MEMBER", "OWNER"].includes(authorAssociation) ? timeoutCollaborator : timeoutContributor; @@ -49,7 +51,7 @@ export async function getApprovalCount({ octokit, logger, config: { allowedRevie repo, pull_number: pullNumber, }); - return reviews.filter((review) => allowedReviewerRoles.includes(review.author_association)).filter((review) => review.state === "APPROVED").length; + return reviews.filter((review) => allowedReviewerRoles?.includes(review.author_association)).filter((review) => review.state === "APPROVED").length; } catch (e) { logger.error(`Error fetching reviews' approvals: ${e}`); return 0; diff --git a/src/helpers/update-pull-requests.ts b/src/helpers/update-pull-requests.ts index 3e6aa7e..6a35d7f 100644 --- a/src/helpers/update-pull-requests.ts +++ b/src/helpers/update-pull-requests.ts @@ -2,7 +2,7 @@ import { RestEndpointMethodTypes } from "@octokit/rest"; import ms from "ms"; import { getAllTimelineEvents } from "../handlers/github-events"; import { generateSummary, ResultInfo } from "../handlers/summary"; -import { Context } from "../types"; +import { Context, ReposWatchSettings } from "../types"; import { getApprovalCount, getMergeTimeoutAndApprovalRequiredCount, @@ -30,7 +30,7 @@ export async function updatePullRequests(context: Context) { const { logger } = context; const results: ResultInfo[] = []; - if (!context.config.repos.monitor.length) { + if (!context.config.repos?.monitor.length) { const owner = context.payload.repository.owner; if (owner) { logger.info(`No organizations or repo have been specified, will default to the organization owner: ${owner.login}.`); @@ -39,7 +39,7 @@ export async function updatePullRequests(context: Context) { } } - const pullRequests = await getOpenPullRequests(context, context.config.repos); + const pullRequests = await getOpenPullRequests(context, context.config.repos as ReposWatchSettings); if (!pullRequests?.length) { return logger.info("Nothing to do."); @@ -74,8 +74,14 @@ export async function updatePullRequests(context: Context) { ); if (isNaN(lastActivityDate.getTime())) { logger.info(`PR ${html_url} does not seem to have any activity, nothing to do.`); - } else if (isPastOffset(lastActivityDate, requirements.mergeTimeout)) { - isMerged = await attemptMerging(context, { gitHubUrl, htmlUrl: html_url, requirements, lastActivityDate, pullRequestDetails }); + } else if (requirements?.mergeTimeout && isPastOffset(lastActivityDate, requirements?.mergeTimeout)) { + isMerged = await attemptMerging(context, { + gitHubUrl, + htmlUrl: html_url, + requirements: requirements as Requirements, + lastActivityDate, + pullRequestDetails, + }); } else { logger.info(`PR ${html_url} has activity up until (${lastActivityDate}), nothing to do.`); } diff --git a/src/update-configuration.ts b/src/update-configuration.ts deleted file mode 100644 index f1ce770..0000000 --- a/src/update-configuration.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as fs from "node:fs"; -import { pluginSettingsSchema } from "./types"; -import manifest from "../manifest.json"; - -const configuration = JSON.stringify(pluginSettingsSchema); -console.log(configuration); -// @ts-expect-error The manifest doesn't necessarily already have the configuration key -manifest["configuration"] = JSON.parse(configuration); -fs.writeFileSync("./manifest.json", JSON.stringify(manifest, null, 2)); From 62f5cadb3a80478c70b973853783f43a0106c9d4 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 14:41:53 +0900 Subject: [PATCH 38/41] chore: fixed tests --- src/action.ts | 1 + src/helpers/validator.ts | 1 + tests/configuration.test.ts | 32 +++++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/action.ts b/src/action.ts index 29d7cd9..a4e9383 100644 --- a/src/action.ts +++ b/src/action.ts @@ -11,6 +11,7 @@ export async function run() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; + console.log("PAYLOAD", JSON.stringify(payload, null, 2)); const { decodedSettings, decodedEnv } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); const inputs: PluginInputs = { stateId: payload.stateId, diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index f59fe47..9b97c5b 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -4,6 +4,7 @@ import { Env, envSchema, envValidator, PluginSettings, pluginSettingsSchema, plu export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const errors: ValueError[] = []; + console.log(rawEnv, rawSettings); const env = Value.Default(envSchema, rawEnv) as Env; if (!envValidator.test(env)) { for (const error of envValidator.errors(env)) { diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index e625dc8..189d790 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -32,6 +32,9 @@ describe("Configuration tests", () => { pull_request: { html_url: "https://github.com/ubiquibot/automated-merging/pull/1", }, + env: { + workflowName: "workflow", + }, }), env: { workflowName: "workflow", @@ -41,8 +44,31 @@ describe("Configuration tests", () => { }, })); const run = (await import("../src/action")).run; - await expect(run()).rejects.toThrow( - "Invalid settings provided:\n/approvalsRequired/collaborator: Expected number to be greater or equal to 1;\n/approvalsRequired/contributor: Expected number to be greater or equal to 1" - ); + await expect(run()).rejects.toMatchObject({ + errors: [ + { + message: "Expected number to be greater or equal to 1", + path: "/approvalsRequired/collaborator", + schema: { + default: 1, + minimum: 1, + type: "number", + }, + type: 39, + value: 0, + }, + { + message: "Expected number to be greater or equal to 1", + path: "/approvalsRequired/contributor", + schema: { + default: 2, + minimum: 1, + type: "number", + }, + type: 39, + value: 0, + }, + ], + }); }); }); From 56a8d331e1f7a10be3f190715a240a373da3b83a Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 14:43:52 +0900 Subject: [PATCH 39/41] chore: fixed tests --- src/action.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/action.ts b/src/action.ts index a4e9383..29d7cd9 100644 --- a/src/action.ts +++ b/src/action.ts @@ -11,7 +11,6 @@ export async function run() { const payload = github.context.payload.inputs; payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; - console.log("PAYLOAD", JSON.stringify(payload, null, 2)); const { decodedSettings, decodedEnv } = validateAndDecodeSchemas(payload.env, JSON.parse(payload.settings)); const inputs: PluginInputs = { stateId: payload.stateId, From 75f2bb6e6490c5339e4d105908fde9be50e7b914 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 14:48:38 +0900 Subject: [PATCH 40/41] chore: fixed tests --- .../workflows/{validate-schema.yml => update-configuration.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{validate-schema.yml => update-configuration.yml} (100%) diff --git a/.github/workflows/validate-schema.yml b/.github/workflows/update-configuration.yml similarity index 100% rename from .github/workflows/validate-schema.yml rename to .github/workflows/update-configuration.yml From 7417f3d082d3ff8743668b64b3a7d9efd207e97d Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Wed, 2 Oct 2024 16:05:57 +0900 Subject: [PATCH 41/41] chore: removed logs --- src/helpers/validator.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/helpers/validator.ts b/src/helpers/validator.ts index 9b97c5b..1ca759d 100644 --- a/src/helpers/validator.ts +++ b/src/helpers/validator.ts @@ -4,11 +4,9 @@ import { Env, envSchema, envValidator, PluginSettings, pluginSettingsSchema, plu export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const errors: ValueError[] = []; - console.log(rawEnv, rawSettings); const env = Value.Default(envSchema, rawEnv) as Env; if (!envValidator.test(env)) { for (const error of envValidator.errors(env)) { - console.error(error); errors.push(error); } } @@ -16,7 +14,6 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const settings = Value.Default(pluginSettingsSchema, rawSettings) as PluginSettings; if (!pluginSettingsValidator.test(settings)) { for (const error of pluginSettingsValidator.errors(settings)) { - console.error(error); errors.push(error); } } @@ -30,7 +27,6 @@ export function validateAndDecodeSchemas(rawEnv: object, rawSettings: object) { const decodedEnv = Value.Decode(envSchema, rawEnv || {}); return { decodedEnv, decodedSettings }; } catch (e) { - console.error("validateAndDecodeSchemas", e); if (e instanceof TransformDecodeCheckError || e instanceof TransformDecodeError) { throw { errors: [e.error] }; }