π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[ci] Require approval for Markdown additions and edits
laurenspriema369b381bc6a
diff --git a/.github/checks/change-approval/files.mjs b/.github/checks/change-approval/files.mjsindex f8c6e744aa..e30721f507 100644--- a/.github/checks/change-approval/files.mjs+++ b/.github/checks/change-approval/files.mjs@@ -73,5 +73,11 @@ export function checkFiles({ files }) {const configs = files.filter(({ path }) => configFile.test(path)).map(({ path }) => path);- return { binaries, large, guardrails, configs };+ const markdown = files+ .filter(+ ({ path, deleted }) =>+ !deleted && /\.(md|markdown|mdx)$/i.test(path),+ )+ .map(({ path }) => path);+ return { binaries, large, guardrails, configs, markdown };}diff --git a/.github/checks/change-approval/report.mjs b/.github/checks/change-approval/report.mjsindex 95f774fe33..81f6e8a447 100644--- a/.github/checks/change-approval/report.mjs+++ b/.github/checks/change-approval/report.mjs@@ -1,7 +1,7 @@import { appendFileSync } from "node:fs";export function writeReport({- files: { binaries, large, guardrails, configs },+ files: { binaries, large, guardrails, configs, markdown },dependencies,rust,swift,@@ -41,6 +41,11 @@ export function writeReport({plural: "config files",count: configs.length,},+ {+ singular: "Markdown file",+ plural: "Markdown files",+ count: markdown.length,+ },{singular: "Rust lint policy file",plural: "Rust lint policy files",@@ -92,6 +97,8 @@ export function writeReport({sections.push(`## Toolchain and registry config\n\n${list(configs.map(code))}`,);+ if (markdown.length)+ sections.push(`## Markdown files\n\n${list(markdown.map(code))}`);if (rust.length)sections.push(`## Rust lint declarations and files containing unsafe\n\n${list(rust.map(({ path, reasons }) => `${code(path)}: ${reasons.map(code).join("; ")}`))}`,diff --git a/.github/checks/change-approval/test.mjs b/.github/checks/change-approval/test.mjsindex 1b0d016120..42348909ae 100644--- a/.github/checks/change-approval/test.mjs+++ b/.github/checks/change-approval/test.mjs@@ -216,6 +216,70 @@ test("binary deleted is ignored", (t) => {assert.equal(scan(t, { "a.bin": Buffer.alloc(16) }, { "a.bin": null }), "");});+test("Markdown additions and edits need approval in CI", (t) => {+ const changed = {+ "README.md": "# Updated\n",+ "docs/empty.md": "",+ "docs/guide.MARKDOWN": "# Guide\n",+ "web/page.MDX": "# Page\n",+ };+ const { stdout, output, summary } = scan(+ t,+ { "README.md": "# Original\n" },+ { ...changed, "notes.md.txt": "Not Markdown\n" },+ { ci: true },+ );+ assert.equal(output, 'categories=["Markdown files"]\n');+ assert.equal(+ stdout,+ "::warning title=Change approval needed::4 Markdown files\n",+ );+ assert.equal(+ summary,+ `4 Markdown files\n\n## Markdown files\n\n${Object.keys(changed)+ .map((path) => `- \`${path}\``)+ .join("\n")}\n`,+ );+});++test("Markdown edits and untracked files are scanned locally", (t) => {+ const output = scan(+ t,+ { "docs/guide.md": "# Original\n" },+ { "docs/guide.md": "# Updated\n", "README.MD": "# New\n" },+ { commit: false },+ );+ assert.match(output, /^2 Markdown files\n/);+ assert.match(output, /- `docs\/guide.md`/);+ assert.match(output, /- `README.MD`/);+});++test("renaming a text file to Markdown needs approval", (t) => {+ const { output, summary } = scan(+ t,+ { "guide.txt": "# Guide\n" },+ { "guide.txt": null, "guide.md": "# Guide\n" },+ { ci: true },+ );+ assert.equal(output, 'categories=["Markdown files"]\n');+ assert.equal(+ summary,+ "1 Markdown file\n\n## Markdown files\n\n- `guide.md`\n",+ );+});++test("unchanged Markdown and deletions need no approval", (t) => {+ const { stdout, output, summary } = scan(+ t,+ { "README.md": "# Keep\n", "docs/old.md": "# Remove\n" },+ { "docs/old.md": null, "notes.txt": "Ordinary change\n" },+ { ci: true },+ );+ assert.equal(stdout, "");+ assert.equal(output, "categories=[]\n");+ assert.equal(summary, "No approval needed.\n");+});+test("CI preserves tabs and newlines in binary and large filenames", (t) => {const binary = "image.png\tpayload.jar";const large = "large\nfile.txt";@@ -1266,6 +1330,9 @@ test("workflow scans PR changes with the complete checker from main", (t) => {"export function checkRust() { return []; }",[`${checkerDir}/web.mjs`]:'throw new Error("loaded an untrusted rule");',+ [`${checkerDir}/files.mjs`]:+ 'throw new Error("loaded an untrusted file rule");',+ "docs/guide.md": "# Guide\n","src/lib.rs": "pub unsafe fn call() {}","web/example.ts":"// eslint-disable-next-line no-console\nfirst();\n",@@ -1274,9 +1341,10 @@ test("workflow scans PR changes with the complete checker from main", (t) => {);assert.equal(output,- 'categories=["guardrail files","Rust lint policy files","Web lint policy files"]\n',+ 'categories=["guardrail files","Markdown files","Rust lint policy files","Web lint policy files"]\n',);assert.match(summary, /- `src\/lib.rs`/);assert.match(summary, /- `web\/example.ts`/);assert.match(summary, /- `rust\/Cargo.toml`/);+ assert.match(summary, /- `docs\/guide.md`/);});