Files
youtube-generator/scripts/lib/third-party.ts
T
poli0981andClaude Opus 5.5 a70580e703 ci: security, licensing and style gates; pin every action by SHA
New checks
- security.yml: dependency-review blocks PRs that add a high/critical
  advisory; actionlint + zizmor lint the workflows themselves (template
  injection, permissions, credential persistence, unpinned uses); OpenSSF
  Scorecard weekly and on main (published, not uploaded as alerts).
- compliance.yml: REUSE lint over the whole repo (REUSE.toml + LICENSES/,
  no per-file headers) and Conventional-Commit PR titles.
- rust.yml (src-tauri changes + weekly): rustfmt, clippy -D warnings,
  cargo test, and cargo-deny for RustSec advisories, licenses and sources.
- ci.yml `check` gains: coverage thresholds (src/engine, worker),
  check:licenses, check:bundle, and a `wrangler deploy --dry-run`.

Licensing
- THIRD_PARTY_NOTICES.md is now generated from package.json, the installed
  packages and Cargo.toml/Cargo.lock (`npm run generate:third-party`); CI
  fails when it is stale or when anything bundled into the app carries a
  license outside the allowlist. It had drifted to React 18 / Vite 7 /
  Tailwind 3.
- Vite's build.license emits the full text of every bundled package's
  license to /licenses/third-party.md (served publicly, before the gate).

Bundle budget
- scripts/check-bundle-size.ts measures what CLAUDE.md's "500KB" never
  defined: initial load (everything index.html references) <= 280 KB gzip
  (197 KB today) and no JS chunk over 500 KB raw.

Coverage
- @vitest/coverage-v8; thresholds sit just under today's numbers. The
  engine is at 89% lines / 64% functions — not the 100% CLAUDE.md claimed.

Supply chain
- Every third-party action pinned to a commit SHA (Dependabot updates the
  SHA and its version comment); checkout never persists credentials.
- Release workflows: a `verify` job (typecheck, tests, version sync, Tauri
  alignment, tag == package version) gates the build; no dependency caches
  in release jobs; permissions granted per job.
- Reusable Discord workflows receive only the secrets they declare instead
  of `secrets: inherit` (which exposed the Android signing keys to them).
- Rust: cargo-deny found RUSTSEC-2026-0194/0195 (quick-xml DoS, via plist)
  that Dependabot had not raised; plist 1.10 brings quick-xml 0.41.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 19:46:24 +07:00

213 lines
8.2 KiB
TypeScript

/**
* Third-party licensing, generated and enforced.
*
* npm run generate:third-party rewrite THIRD_PARTY_NOTICES.md
* npm run check:licenses fail if it is stale, or if anything shipped
* to users carries a license not on the list
*
* THIRD_PARTY_NOTICES.md used to be hand-maintained and had drifted three
* majors behind (React 18, Vite 7, Tailwind 3 …). It is now built from
* package.json, the installed packages and Cargo.toml/Cargo.lock, so CI
* catches the drift instead of a reader. The full license texts of every
* package bundled into the web app are emitted separately by Vite
* (`build.license`) to /licenses/third-party.md.
*/
import { readFileSync, writeFileSync } from "fs";
import { resolve } from "path";
const ROOT = resolve(import.meta.dirname, "../..");
const NOTICES = resolve(ROOT, "THIRD_PARTY_NOTICES.md");
/** Licenses acceptable for code that ships inside the app. */
const ALLOWED = new Set([
"MIT",
"ISC",
"Apache-2.0",
"BSD-2-Clause",
"BSD-3-Clause",
"0BSD",
"CC0-1.0",
"Unlicense",
"BlueOak-1.0.0",
"OFL-1.1",
"Zlib",
"MPL-2.0",
]);
/** SPDX expression → allowed? `OR` needs one side, `AND` needs both. */
export function licenseAllowed(expression: string): boolean {
const expr = expression.trim().replace(/^\((.*)\)$/, "$1");
if (/\sOR\s/i.test(expr)) return expr.split(/\s+OR\s+/i).some(licenseAllowed);
if (/\sAND\s/i.test(expr)) return expr.split(/\s+AND\s+/i).every(licenseAllowed);
return ALLOWED.has(expr);
}
interface PackageJson {
version?: string;
license?: string;
homepage?: string;
repository?: string | { url?: string };
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
}
function readJson<T>(path: string): T {
return JSON.parse(readFileSync(path, "utf8")) as T;
}
function projectUrl(pkg: PackageJson): string {
const repo = typeof pkg.repository === "string" ? pkg.repository : pkg.repository?.url;
const fromRepo = repo
?.replace(/^git\+/, "")
.replace(/^git:\/\//, "https://")
.replace(/^github:/, "https://github.com/")
.replace(/\.git$/, "");
if (fromRepo && /^https?:\/\//.test(fromRepo)) return fromRepo;
if (fromRepo && /^[\w.-]+\/[\w.-]+$/.test(fromRepo)) return `https://github.com/${fromRepo}`;
return pkg.homepage ?? "";
}
interface Row {
name: string;
version: string;
license: string;
url: string;
}
function npmRows(names: string[]): Row[] {
return names.sort().map((name) => {
const pkg = readJson<PackageJson>(resolve(ROOT, "node_modules", name, "package.json"));
return {
name,
version: pkg.version ?? "?",
license: pkg.license ?? "UNKNOWN",
url: projectUrl(pkg),
};
});
}
function crateRows(): Row[] {
const toml = readFileSync(resolve(ROOT, "src-tauri/Cargo.toml"), "utf8").replace(/\r\n/g, "\n");
const lock = readFileSync(resolve(ROOT, "src-tauri/Cargo.lock"), "utf8").replace(/\r\n/g, "\n");
const names = [...toml.matchAll(/^([a-z][a-z0-9_-]*)\s*=\s*(?:"|\{)/gm)]
.map((m) => m[1] ?? "")
.filter((n) => n.startsWith("tauri"));
return [...new Set(names)].sort().map((name) => {
const version =
new RegExp(`\\[\\[package\\]\\]\\nname = "${name}"\\nversion = "([^"]+)"`).exec(lock)?.[1] ??
"?";
const url = name.startsWith("tauri-plugin")
? "https://github.com/tauri-apps/plugins-workspace"
: "https://github.com/tauri-apps/tauri";
return { name, version, license: "Apache-2.0 OR MIT", url };
});
}
function table(rows: Row[], heading: string): string {
const lines = rows.map(
(r) => `| \`${r.name}\` | ${r.version} | ${r.license} | ${r.url ? `<${r.url}>` : "—"} |`,
);
return [
`| ${heading} | Version | License | Project |`,
"| --- | --- | --- | --- |",
...lines,
].join("\n");
}
export function renderNotices(): string {
const pkg = readJson<PackageJson>(resolve(ROOT, "package.json"));
const runtime = npmRows(Object.keys(pkg.dependencies ?? {}));
const dev = npmRows(Object.keys(pkg.devDependencies ?? {}));
return `<!-- Generated by scripts/third-party.ts (npm run generate:third-party). Edit the script, not this file; CI fails when it is stale. -->
# Third-Party Notices
YTDescGen is built on the open-source software and services below. Each component keeps its own license; the linked project pages carry the full terms.
The **complete license text of every package bundled into the web app** — including transitive dependencies such as \`scheduler\` or \`@babel/runtime\` — is published with each release at [\`/licenses/third-party.md\`](https://ytgenerator.stream/licenses/third-party.md), generated by Vite from the exact build.
## Runtime dependencies
Bundled into the web app and the desktop / Android apps.
${table(runtime, "Package")}
## Build and development tools
Used to build, test and check YTDescGen. Not shipped to users.
${table(dev, "Package")}
## Desktop and Android shell (Rust crates)
Direct dependencies of \`src-tauri/\`. Transitive crates are checked in CI by \`cargo deny\` (see \`src-tauri/deny.toml\`); \`cargo tree\` lists them all.
${table(crateRows(), "Crate")}
## Fonts and icons
- **Icons:** [Lucide](https://lucide.dev/) (\`lucide-react\`, ISC). Brand marks, where shown, come from [Simple Icons](https://simpleicons.org/) (CC0-1.0); the trademarks belong to their owners.
- **Fonts:** the app uses the operating system's fonts.
## Services (web app only)
The web app at ytgenerator.stream is delivered by Cloudflare. These are services, not bundled code; the [Privacy Policy](PRIVACY.md) explains what each processes.
| Service | Purpose | Terms |
| --- | --- | --- |
| Cloudflare Workers | Hosting and delivery | <https://www.cloudflare.com/terms/> |
| Cloudflare Turnstile | Bot check before entering | <https://www.cloudflare.com/turnstile-privacy-policy/> |
| Cloudflare Web Analytics | Cookieless, aggregate visit statistics | <https://www.cloudflare.com/privacypolicy/> |
The desktop and Android apps use none of them.
## AI-assisted development
As described in the [Disclaimer](DISCLAIMER.md), YTDescGen is developed with **Anthropic's Claude Code** (Claude Opus models). The model contributes source code, translations, documentation and CI configuration; every change is reviewed by the maintainer (\`@poli0981\`) before it is merged. Claude is a product of Anthropic, PBC — <https://www.anthropic.com>. The Apache-2.0 license in [\`LICENSE\`](LICENSE) is granted by the project author, not by Anthropic.
## Questions and omissions
Licensing and attribution questions: **copyright@poli0981.dev**. If you believe something is missing here, open an issue or pull request per [\`CONTRIBUTING.md\`](CONTRIBUTING.md).
`;
}
/** Production packages (bundled into the app) whose license is not allowed. */
export function disallowedProductionLicenses(): string[] {
const lock = readJson<{
packages: Record<string, { dev?: boolean; devOptional?: boolean; license?: unknown }>;
}>(resolve(ROOT, "package-lock.json"));
const bad: string[] = [];
for (const [path, entry] of Object.entries(lock.packages)) {
if (path === "" || entry.dev || entry.devOptional) continue;
const license = typeof entry.license === "string" ? entry.license : "UNKNOWN";
if (!licenseAllowed(license)) bad.push(`${path.replace(/^.*node_modules\//, "")} (${license})`);
}
return bad;
}
export function main(): void {
const write = process.argv.includes("--write");
const expected = renderNotices();
if (write) {
writeFileSync(NOTICES, expected);
console.log("THIRD_PARTY_NOTICES.md regenerated.");
return;
}
let failed = false;
const bad = disallowedProductionLicenses();
if (bad.length > 0) {
failed = true;
console.error(`✗ Bundled packages with licenses outside the allowlist:\n ${bad.join("\n ")}`);
} else {
console.log("✓ Every bundled package has an allowed license.");
}
const current = readFileSync(NOTICES, "utf8").replace(/\r\n/g, "\n");
if (current !== expected) {
failed = true;
console.error("✗ THIRD_PARTY_NOTICES.md is stale — run `npm run generate:third-party`.");
} else {
console.log("✓ THIRD_PARTY_NOTICES.md matches package.json, the lockfile and Cargo.toml.");
}
if (failed) process.exit(1);
}