Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/repository-standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Repository standard

on:
pull_request:
merge_group:
types: [checks_requested]
push:
branches: ["main"]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: repository-standard-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
standard:
name: repository-standard
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
persist-credentials: false
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24.18.0
- name: Install pinned checker dependencies
run: npm ci --prefix .standards --ignore-scripts --no-audit --no-fund
- name: Install checksum-verified Gitleaks
run: node .standards/install-gitleaks.mjs
- name: Check complete proposed change
env:
BASE: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }}
HEAD: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha || github.sha }}
shell: bash
run: |
set -euo pipefail
if [[ -z "$BASE" || "$BASE" =~ ^0+$ ]]; then
BASE="$(git rev-list --max-parents=0 "$HEAD" | tail -n 1)"
fi
node .standards/check.mjs ci "$BASE" "$HEAD"
48 changes: 48 additions & 0 deletions .repo-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"schemaVersion": 1,
"standardVersion": "0.4.0",
"kind": "product",
"lifecycle": "active",
"adoption": "adopting",
"profiles": ["mobile", "network"],
"docs": {
"mode": "strict",
"readmes": ["README.md", "README.ru.md"],
"roots": ["docs/en", "docs/ru"]
},
"evidence": {
"ci": {
"status": "NOT_VERIFIED"
},
"bootstrap": {
"status": "NOT_VERIFIED"
},
"release": {
"status": "NOT_VERIFIED"
},
"runtime": {
"status": "NOT_VERIFIED"
},
"fullHistory": {
"status": "NOT_VERIFIED"
},
"fullFormatting": {
"status": "NOT_VERIFIED"
},
"bilingualLegacyDocs": {
"status": "NOT_VERIFIED"
},
"presentation": {
"status": "NOT_VERIFIED"
},
"hostingEnforcement": {
"status": "NOT_VERIFIED"
},
"profile:mobile": {
"status": "NOT_VERIFIED"
},
"profile:network": {
"status": "NOT_VERIFIED"
}
}
}
1 change: 1 addition & 0 deletions .standards/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
2 changes: 2 additions & 0 deletions .standards/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
bin/
21 changes: 21 additions & 0 deletions .standards/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Alexandr Vorontsov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
146 changes: 146 additions & 0 deletions .standards/check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { execFileSync, spawnSync } from "node:child_process";
import { checkDocs, safePath, validatePolicy, verifyLock } from "./policy.mjs";

const kit = path.dirname(fileURLToPath(import.meta.url));
function git(args, options = {}) {
return execFileSync("git", args, {
encoding: "utf8",
maxBuffer: 64 * 1024 * 1024,
stdio: ["ignore", "pipe", "pipe"],
...options,
});
}
const root = git(["rev-parse", "--show-toplevel"]).trim();
process.chdir(root);
const args = process.argv.slice(2);
const mode = args[0];
if (!["staged", "ci", "structure"].includes(mode))
throw new Error("Usage: check.mjs staged | ci <base-sha> <head-sha> | structure");
const commit = (value) => {
if (!/^[a-f0-9]{40}$/.test(value || "")) throw new Error("A full commit SHA is required");
return git(["rev-parse", "--verify", `${value}^{commit}`]).trim();
};
let before, after, changes;
if (mode === "ci") {
const base = commit(args[1]);
after = commit(args[2]);
before = git(["merge-base", base, after]).trim();
changes = git(["diff", "--name-only", "--no-renames", "-z", before, after, "--"])
.split("\0")
.filter(Boolean);
} else if (mode === "staged") {
try {
before = git(["rev-parse", "--verify", "HEAD"]).trim();
} catch {
before = null;
}
after = ":";
changes = git(["diff", "--cached", "--name-only", "--no-renames", "-z", "--"])
.split("\0")
.filter(Boolean);
} else {
before = null;
after = null;
changes = [];
}
function readAt(ref, name) {
safePath(name);
if (ref === null) return null;
const object = ref === ":" ? `:${name}` : `${ref}:${name}`;
try {
return git(["show", object]);
} catch (e) {
// A missing path is expected for additions/deletions. Other Git failures remain errors.
const message = String(e.stderr || "");
if (
/does not exist|exists on disk, but not in|not in the index|not a valid object name|path .* not in/i.test(
message,
)
)
return null;
throw e;
}
}
const content = (name) =>
mode === "structure"
? fs.readFileSync(path.join(root, safePath(name)), "utf8")
: readAt(after, name);
const policy = JSON.parse(content(".repo-policy.json") || "null");
const failures = validatePolicy(policy);
if (failures.length) throw new Error(failures.join("\n"));
for (const directory of policy.docs.roots) {
const page = `${directory}/development-standard.md`;
if (!content(page)?.trim()) failures.push(`Missing adoption documentation: ${page}`);
}
const lock = JSON.parse(content(".standards/lock.json") || "null");
failures.push(...verifyLock(lock, (name) => content(name)));
if (mode !== "staged")
failures.push(...checkDocs(policy, changes, (name) => readAt(before, name), content));
else {
// Commit-time structure is authoritative; the final accumulated PR diff is enforced in CI.
failures.push(...checkDocs(policy, [], () => null, content));
const pending = checkDocs(policy, changes, (name) => readAt(before, name), content);
if (pending.length)
console.log("DOCS: final PR must update both README files and both documentation languages.");
}
if (failures.length) throw new Error(failures.join("\n"));
if (mode === "structure") {
console.log("PASS: policy, bundle and README structure");
process.exit(0);
}

const prettier = await import("prettier");
const formatOptions = JSON.parse(fs.readFileSync(path.join(kit, "format.json"), "utf8"));
for (const name of changes) {
safePath(name);
if (
name.startsWith(".standards/") ||
/(^|\/)(package-lock\.json|pnpm-lock\.yaml|yarn\.lock)$/.test(name)
)
continue;
const data = content(name);
if (data == null || data.includes("\0")) continue;
const info = await prettier.getFileInfo(name, { resolveConfig: false });
if (!info.inferredParser) continue;
if (!(await prettier.check(data, { ...formatOptions, filepath: name })))
failures.push(`Prettier: ${name}`);
}
if (failures.length) throw new Error(failures.join("\n"));

const binary =
process.env.GITLEAKS_BIN ||
path.join(kit, "bin", process.platform === "win32" ? "gitleaks.exe" : "gitleaks");
const common = ["--redact", "--no-banner", "--config", path.join(kit, "gitleaks.toml")];
function scan(scanArgs) {
const result = spawnSync(binary, scanArgs, { cwd: root, stdio: "inherit", timeout: 300000 });
if (result.error || result.status !== 0)
throw new Error("Gitleaks failed or is unavailable; commit/CI blocked.");
}
if (mode === "ci") scan(["git", root, `--log-opts=${before}..${after}`, ...common]);
else {
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "repository-standard-"));
try {
for (const name of changes) {
const text = content(name);
if (text == null) continue;
const data = git(["show", `:${name}`], { encoding: null });
const destination = path.join(temp, safePath(name));
fs.mkdirSync(path.dirname(destination), { recursive: true });
fs.writeFileSync(destination, data);
}
scan(["dir", temp, ...common]);
} finally {
const resolved = path.resolve(temp);
if (
path.dirname(resolved) !== path.resolve(os.tmpdir()) ||
!path.basename(resolved).startsWith("repository-standard-")
)
throw new Error("Unsafe temporary cleanup target");
fs.rmSync(resolved, { recursive: true, force: true });
}
}
console.log(`PASS: ${mode} policy, documentation, changed-file Prettier and Gitleaks`);
5 changes: 5 additions & 0 deletions .standards/format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"endOfLine": "lf",
"proseWrap": "preserve",
"printWidth": 100
}
4 changes: 4 additions & 0 deletions .standards/gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = "Repository standard: default Gitleaks detectors"

[extend]
useDefault = true
20 changes: 20 additions & 0 deletions .standards/hook.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from "node:fs";
import path from "node:path";
import { execFileSync, spawnSync } from "node:child_process";
const gitDir = execFileSync("git", ["rev-parse", "--absolute-git-dir"], {
encoding: "utf8",
}).trim();
const stateFile = path.join(gitDir, "repository-standard-hook.json");
if (fs.existsSync(stateFile)) {
const state = JSON.parse(fs.readFileSync(stateFile, "utf8"));
if (state.original) {
const previous = spawnSync("sh", [state.original], { stdio: "inherit" });
if (previous.error || previous.status !== 0) process.exit(previous.status || 1);
}
}
const checker = spawnSync(
process.execPath,
[path.join(import.meta.dirname, "check.mjs"), "staged"],
{ stdio: "inherit" },
);
process.exit(checker.error || checker.status !== 0 ? checker.status || 1 : 0);
3 changes: 3 additions & 0 deletions .standards/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
set -eu
exec node "$(git rev-parse --show-toplevel)/.standards/hook.mjs"
62 changes: 62 additions & 0 deletions .standards/install-gitleaks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import { fileURLToPath } from "node:url";
import { execFileSync } from "node:child_process";
import { sha256 } from "./policy.mjs";

const assets = {
"linux-x64": [
"gitleaks_8.30.1_linux_x64.tar.gz",
"551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb",
],
"linux-arm64": [
"gitleaks_8.30.1_linux_arm64.tar.gz",
"e4a487ee7ccd7d3a7f7ec08657610aa3606637dab924210b3aee62570fb4b080",
],
"win32-x64": [
"gitleaks_8.30.1_windows_x64.zip",
"d29144deff3a68aa93ced33dddf84b7fdc26070add4aa0f4513094c8332afc4e",
],
"win32-arm64": [
"gitleaks_8.30.1_windows_arm64.zip",
"b95f5e4f5c425cedca7ee203d9afd29597e692c4924a12ed42f970537c72cc0f",
],
"darwin-arm64": [
"gitleaks_8.30.1_darwin_arm64.tar.gz",
"b40ab0ae55c505963e365f271a8d3846efbc170aa17f2607f13df610a9aeb6a5",
],
"darwin-x64": [
"gitleaks_8.30.1_darwin_x64.tar.gz",
"dfe101a4db2255fc85120ac7f3d25e4342c3c20cf749f2c20a18081af1952709",
],
};
const asset = assets[`${process.platform}-${process.arch}`];
if (!asset) throw new Error("Unsupported platform; install pinned Gitleaks and set GITLEAKS_BIN");
const directory = path.dirname(fileURLToPath(import.meta.url));
const bin = path.join(directory, "bin");
fs.mkdirSync(bin, { recursive: true });
const response = await fetch(
`https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/${asset[0]}`,
{ signal: AbortSignal.timeout(60000) },
);
if (!response.ok) throw new Error(`Gitleaks download failed: ${response.status}`);
const buffer = Buffer.from(await response.arrayBuffer());
if (sha256(buffer) !== asset[1]) throw new Error("Gitleaks checksum mismatch");
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "gitleaks-download-"));
try {
const archive = path.join(temporary, asset[0]);
fs.writeFileSync(archive, buffer);
const executable = process.platform === "win32" ? "gitleaks.exe" : "gitleaks";
execFileSync("tar", ["-xf", archive, "-C", bin, executable], { stdio: "inherit" });
if (process.platform !== "win32") fs.chmodSync(path.join(bin, executable), 0o755);
console.log(execFileSync(path.join(bin, executable), ["version"], { encoding: "utf8" }).trim());
} finally {
const resolved = path.resolve(temporary);
if (
path.dirname(resolved) !== path.resolve(os.tmpdir()) ||
!path.basename(resolved).startsWith("gitleaks-download-")
)
throw new Error("Unsafe temporary cleanup target");
fs.rmSync(resolved, { recursive: true, force: true });
}
Loading
Loading