diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4902d3c4ba..866c499f71 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -205,6 +205,15 @@ jobs: - run: echo "$PWD/target/debug" >> "$GITHUB_PATH" && chmod +x target/debug/mise - uses: ./.github/actions/mise-tools - run: mise x -- bun i + - run: mise run render + - name: assert render produces no diff + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "::error::'mise run render' produced changes. Run it locally and commit." + git status + git diff HEAD + exit 1 + fi - run: rm -rf ~/.cargo/advisory-dbs && cargo deny check - run: cargo msrv verify - run: cargo machete --with-metadata diff --git a/xtasks/render/schema.ts b/xtasks/render/schema.ts index 824b31e64f..0a725c0c83 100755 --- a/xtasks/render/schema.ts +++ b/xtasks/render/schema.ts @@ -3,6 +3,7 @@ //MISE description="Render JSON schema" //MISE depends=["docs:setup"] +import { spawnSync } from "node:child_process"; import * as fs from "node:fs"; import * as toml from "toml"; @@ -42,8 +43,24 @@ type NestedElement = { properties: Record; }; +const writtenPaths: string[] = []; + function writeFormattedJson(path: string, value: unknown) { fs.writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`); + writtenPaths.push(path); +} + +function formatWithPrettier(paths: string[]) { + if (paths.length === 0) return; + const result = spawnSync("prettier", ["--write", ...paths], { + stdio: "inherit", + }); + if (result.error) { + throw new Error(`prettier failed to spawn: ${result.error.message}`); + } + if (result.status !== 0) { + throw new Error(`prettier exited with status ${result.status}`); + } } function crawlReferencedDefs(schema: JsonObject, root: unknown) { @@ -226,3 +243,5 @@ const misercSchema = { }; writeFormattedJson("schema/miserc.json", misercSchema); + +formatWithPrettier(writtenPaths);