diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 581d2526d..54a616407 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -64,7 +64,7 @@ jobs: npm ci - name: Verify compiled JS up to date - run: npx tsx pr-checks/check-js.ts + run: npx tsx pr-checks/check-unchanged.ts --language javascript - name: Run unit tests if: always() @@ -122,6 +122,9 @@ jobs: id: install-deps run: npm ci + - name: Verify YAML is correctly formatted + run: npx tsx pr-checks/check-unchanged.ts --language yaml + - name: Verify PR checks up to date if: ${{ !cancelled() && steps.install-deps.outcome == 'success' }} run: .github/workflows/script/verify-pr-checks.sh diff --git a/pr-checks/check-js.ts b/pr-checks/check-unchanged.ts similarity index 66% rename from pr-checks/check-js.ts rename to pr-checks/check-unchanged.ts index 1eb9531a1..c51421018 100755 --- a/pr-checks/check-js.ts +++ b/pr-checks/check-unchanged.ts @@ -2,6 +2,7 @@ import * as fs from "node:fs"; import * as path from "node:path"; +import { parseArgs } from "node:util"; import * as core from "@actions/core"; @@ -100,21 +101,50 @@ function rebuildJavaScript() { runCommand("npm", ["run", "build"], { execOptions: { shell: true } }); } +/** + * Formats YAML files with `npm run format-yaml`. + */ +function formatYAML() { + runCommand("npm", ["run", "format-yaml"], { execOptions: { shell: true } }); +} + function main() { - if (!checkUnchanged(rebuildJavaScript)) { - // If we get a fail here then the PR needs attention - console.error("Failed: JavaScript files are not up to date."); - console.error("Run 'rm -rf lib && npm run build' to update."); + const { values: options } = parseArgs({ + options: { language: { type: "string", default: "javascript" } }, + }); + console.info(`Checking that ${options.language} files are unchanged.`); - addDiffToSummary("Transpiled JS diff"); + if (options.language === "javascript") { + if (!checkUnchanged(rebuildJavaScript)) { + // If we get a fail here then the PR needs attention + console.error("Failed: JavaScript files are not up to date."); + console.error("Run 'rm -rf lib && npm run build' to update."); - // Reset bundled files to allow other checks to test for changes - runCommand("git", ["checkout", "lib"]); + addDiffToSummary("Transpiled JS diff"); - return 1; + // Reset bundled files to allow other checks to test for changes + runCommand("git", ["checkout", "lib"]); + + return 1; + } + + console.info("Success: JavaScript files are up to date"); + } else if (options.language === "yaml") { + if (!checkUnchanged(formatYAML)) { + // If we get a fail here then the PR needs attention + console.error("Failed: YAML files are not correctly formatted."); + console.error("Run 'npm run format-yaml' to format them."); + + addDiffToSummary("YAML formatting changes"); + + return 1; + } + + console.info("Success: YAML files are correctly formatted"); + } else { + console.error(`Unknown language: ${options.language}`); } - console.info("Success: JavaScript files are up to date"); return 0; }