From 919fe2d0dea4ef127ffd90a2e9b7f31cb29ccb17 Mon Sep 17 00:00:00 2001 From: exoego Date: Tue, 3 Sep 2024 15:16:54 +0900 Subject: [PATCH 1/2] ci: setup action.yaml validation --- .github/workflows/ci.yml | 9 +++++++++ package-lock.json | 21 ++++++++++++++++++++- package.json | 3 ++- scripts/validate-yaml.ts | 30 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 scripts/validate-yaml.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5d30be..a496d4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,3 +62,12 @@ jobs: path: | dist/ action.yaml + + validate-action-yaml: + runs-on: ubuntu-latest + timeout-minutes: 1 + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - run: bun install + - run: bun scripts/validate-yaml.ts diff --git a/package-lock.json b/package-lock.json index 8309f43..9f4a979 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "@types/node": "^20.14.9", "esbuild": "^0.23.1", "typescript": "^5.5.4", - "vitest": "^2.0.5" + "vitest": "^2.0.5", + "yaml": "^2.5.0" } }, "node_modules/@ampproject/remapping": { @@ -3169,6 +3170,18 @@ "dev": true, "optional": true, "peer": true + }, + "node_modules/yaml": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz", + "integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==", + "dev": true, + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } } }, "dependencies": { @@ -5158,6 +5171,12 @@ "dev": true, "optional": true, "peer": true + }, + "yaml": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz", + "integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==", + "dev": true } } } diff --git a/package.json b/package.json index c53fbbf..b6f1b4c 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@biomejs/biome": "^1.8.3", "esbuild": "^0.23.1", "vitest": "^2.0.5", - "typescript": "^5.5.4" + "typescript": "^5.5.4", + "yaml": "^2.5.0" } } diff --git a/scripts/validate-yaml.ts b/scripts/validate-yaml.ts new file mode 100644 index 0000000..32b42b5 --- /dev/null +++ b/scripts/validate-yaml.ts @@ -0,0 +1,30 @@ +import YAML from 'yaml'; +import fs from 'node:fs'; + +const actionYaml = YAML.parse(fs.readFileSync("action.yaml", "utf-8")); + +const inputKeys = Object.keys(actionYaml.inputs) +const envKeys = new Set(); +actionYaml.runs.steps.forEach((step: any) => { + if (step.name !== "Compare with base branch bundle") return; + Object.keys(step.env).forEach((key: string) => { + envKeys.add(key.replace(/^INPUT_/, "").toLowerCase()) + }) +}) +if (envKeys.size === 0) { + throw new Error("No environment variables found. Did you forget to add `env` to the step?") +} + +const missingKeys = inputKeys.filter((key: string) => !envKeys.has(key)) +if (missingKeys.length > 0) { + const s = missingKeys.map((key: string) => `INPUT_${key.toUpperCase()}: \${{ inputs.${key} }}`).join("\n") + + throw new Error(` +Missing environment variables for ${missingKeys.join(", ")}. +Add the following envs to the step "Compare with base branch bundle" in action.yaml: + +${s} + `) +} else { + console.log("All environment variables are present") +} From 415c1b462314041383936bf7ed68ffc3b92a09c3 Mon Sep 17 00:00:00 2001 From: exoego Date: Tue, 3 Sep 2024 15:19:12 +0900 Subject: [PATCH 2/2] bugfix: fix missing INPUT_INCLUDE_SIZE_COMPARISON --- action.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yaml b/action.yaml index d7c4e86..dc57377 100644 --- a/action.yaml +++ b/action.yaml @@ -94,6 +94,7 @@ runs: INPUT_NAME: ${{ inputs.name }} INPUT_ANALYZE_DIRECTORY: ${{ inputs.analyze_directory }} INPUT_INCLUDE_EXTENSIONS: ${{ inputs.include_extensions }} + INPUT_INCLUDE_SIZE_COMPARISON: ${{ inputs.include_size_comparison }} INPUT_PERCENT_EXTRA_ATTENTION: ${{ inputs.percent_extra_attention }} INPUT_SHOW_DETAILS: ${{ inputs.show_details }} INPUT_SHOW_NO_CHANGE: ${{ inputs.show_no_change }}