Skip to content

Commit

Permalink
ci: setup action.yaml validation
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego committed Sep 3, 2024
1 parent 865b43c commit 919fe2d
Show file tree
Hide file tree
Showing 4 changed files with 61 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
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 919fe2d

Please sign in to comment.