Skip to content

Commit

Permalink
Merge pull request #89 from exoego/ci
Browse files Browse the repository at this point in the history
Fix missing INPUT_INCLUDE_SIZE_COMPARISON
  • Loading branch information
exoego committed Sep 3, 2024
2 parents 865b43c + 415c1b4 commit ed6eb66
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
21 changes: 20 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
30 changes: 30 additions & 0 deletions scripts/validate-yaml.ts
Original file line number Diff line number Diff line change
@@ -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<string>();
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")
}

0 comments on commit ed6eb66

Please sign in to comment.