Merge pull request #182 from poli0981/chore/copyright-years
chore(legal): keep copyright years current, checked in CI
This commit is contained in:
8 files changed
+220
-3
No files matched your search
@@ -70,6 +70,11 @@ jobs:
|
||||
# THIRD_PARTY_NOTICES.md matches what is actually installed.
|
||||
- name: Check licenses and third-party notices
|
||||
run: npm run check:licenses
|
||||
# NOTICE, REUSE.toml and the installers' copyright string state the
|
||||
# years ("2026", later "2026-2027"). The first commit in a new year
|
||||
# fails here until `npm run update:copyright` extends them.
|
||||
- name: Check copyright years
|
||||
run: npm run check:copyright
|
||||
|
||||
# --- security ---------------------------------------------------------
|
||||
# Advisory-only: a fresh high-severity advisory in a transitive dep must
|
||||
|
||||
@@ -2,7 +2,7 @@ import { readFileSync } from "fs";
|
||||
import { posix, resolve } from "path";
|
||||
import { Marked, type Tokens } from "marked";
|
||||
import type { Plugin } from "vite";
|
||||
import { LOGO_SVG, SITE_ORIGIN } from "../src/config/brand.ts";
|
||||
import { LOGO_SVG, SITE_ORIGIN, copyrightYears } from "../src/config/brand.ts";
|
||||
import { LEGAL_DOCS, legalDocPath, type LegalDoc, type LegalDocId } from "../src/config/legal.ts";
|
||||
|
||||
/**
|
||||
@@ -239,7 +239,7 @@ function pageShell(options: {
|
||||
<nav aria-label="Legal documents"><p>Legal</p><ul>${nav}</ul></nav>
|
||||
<main>${options.body}</main>
|
||||
</div>
|
||||
<footer>© ${new Date().getUTCFullYear()} poli0981 (SkullMute) · Source code under the Apache License 2.0 · <a href="https://github.com/poli0981/youtube-generator">GitHub</a> · <a href="mailto:contact@poli0981.dev">contact@poli0981.dev</a></footer>
|
||||
<footer>© ${copyrightYears(new Date().getUTCFullYear())} poli0981 (SkullMute) · Source code under the Apache License 2.0 · <a href="https://github.com/poli0981/youtube-generator">GitHub</a> · <a href="mailto:contact@poli0981.dev">contact@poli0981.dev</a></footer>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
+3
-1
@@ -30,7 +30,9 @@
|
||||
"check:tauri": "tsx scripts/check-tauri-versions.ts",
|
||||
"check:bundle": "tsx scripts/check-bundle-size.ts",
|
||||
"check:licenses": "tsx scripts/third-party.ts",
|
||||
"generate:third-party": "tsx scripts/third-party.ts --write"
|
||||
"generate:third-party": "tsx scripts/third-party.ts --write",
|
||||
"check:copyright": "tsx scripts/check-copyright.ts",
|
||||
"update:copyright": "tsx scripts/check-copyright.ts --write"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource-variable/inter": "^5.3.0",
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* CLI for scripts/lib/copyright.ts:
|
||||
*
|
||||
* npm run check:copyright verify NOTICE, REUSE.toml and tauri.conf.json
|
||||
* state the copyright years for HEAD's year
|
||||
* npm run update:copyright rewrite them to those years
|
||||
*/
|
||||
import { main } from "./lib/copyright";
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Copyright years, kept current.
|
||||
*
|
||||
* npm run check:copyright fail if a notice states the wrong years
|
||||
* npm run update:copyright rewrite them to the expected years
|
||||
*
|
||||
* The years are written by hand in three files — NOTICE, REUSE.toml and the
|
||||
* installers' copyright string in src-tauri/tauri.conf.json — and nothing
|
||||
* used to keep them current. Each must state `copyrightYears(year)` from
|
||||
* src/config/brand.ts: "2026", then "2026-2027" from the first commit made in
|
||||
* 2027, and so on.
|
||||
*
|
||||
* "This year" is the year HEAD was committed, not the clock: re-running CI on
|
||||
* an old commit stays green, and the first new work in a new year is what asks
|
||||
* for the bump. Without git (a source tarball) it falls back to the UTC year.
|
||||
*
|
||||
* Deliberately left alone: the `[yyyy]` placeholder in the Apache-2.0
|
||||
* appendix (LICENSE, LICENSES/Apache-2.0.txt), the Gradle wrapper's own 2015
|
||||
* notice, CHANGELOG history and the `{{year}}` of generated descriptions.
|
||||
*/
|
||||
import { execFileSync } from "child_process";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import { copyrightYears } from "../../src/config/brand.ts";
|
||||
|
||||
const ROOT = resolve(import.meta.dirname, "../..");
|
||||
|
||||
export interface Notice {
|
||||
/** Repo-relative path. */
|
||||
file: string;
|
||||
/** Finds the notice; capture group 1 is its years ("2026", "2026-2027"). */
|
||||
pattern: RegExp;
|
||||
}
|
||||
|
||||
export const NOTICES: readonly Notice[] = [
|
||||
{ file: "NOTICE", pattern: /^Copyright ([0-9]{4}(?:-[0-9]{4})?) poli0981 /m },
|
||||
{
|
||||
file: "REUSE.toml",
|
||||
pattern: /^SPDX-FileCopyrightText = "([0-9]{4}(?:-[0-9]{4})?) poli0981 /m,
|
||||
},
|
||||
{
|
||||
file: "src-tauri/tauri.conf.json",
|
||||
pattern: /"copyright": "Copyright ([0-9]{4}(?:-[0-9]{4})?) poli0981 /,
|
||||
},
|
||||
];
|
||||
|
||||
export interface NoticeCheck {
|
||||
notice: Notice;
|
||||
/** The years the file states now, or null when the notice is not found. */
|
||||
found: string | null;
|
||||
expected: string;
|
||||
}
|
||||
|
||||
function readRepoFile(file: string): string {
|
||||
return readFileSync(resolve(ROOT, file), "utf8");
|
||||
}
|
||||
|
||||
/** The year HEAD was committed, or this UTC year when git is unavailable. */
|
||||
export function headCommitYear(): number {
|
||||
try {
|
||||
const iso = execFileSync("git", ["log", "-1", "--format=%cI"], {
|
||||
cwd: ROOT,
|
||||
encoding: "utf8",
|
||||
});
|
||||
const year = Number(iso.trim().slice(0, 4));
|
||||
if (Number.isInteger(year) && year >= 2000) return year;
|
||||
} catch {
|
||||
// Not a git checkout.
|
||||
}
|
||||
return new Date().getUTCFullYear();
|
||||
}
|
||||
|
||||
/** Every notice's current years against the ones `year` calls for. */
|
||||
export function checkNotices(year: number, read = readRepoFile): NoticeCheck[] {
|
||||
const expected = copyrightYears(year);
|
||||
return NOTICES.map((notice) => ({
|
||||
notice,
|
||||
found: notice.pattern.exec(read(notice.file))?.[1] ?? null,
|
||||
expected,
|
||||
}));
|
||||
}
|
||||
|
||||
/** `raw` with the notice's years swapped for `years`; nothing else changes. */
|
||||
export function withYears(raw: string, notice: Notice, years: string): string {
|
||||
return raw.replace(notice.pattern, (match, current: string) => match.replace(current, years));
|
||||
}
|
||||
|
||||
export function main(): void {
|
||||
const write = process.argv.includes("--write");
|
||||
let failed = false;
|
||||
for (const { notice, found, expected } of checkNotices(headCommitYear())) {
|
||||
if (found === expected) {
|
||||
console.log(`✓ ${notice.file}: ${found}`);
|
||||
} else if (found === null) {
|
||||
failed = true;
|
||||
console.error(`✗ ${notice.file}: no copyright notice found (expected ${expected}).`);
|
||||
} else if (write) {
|
||||
writeFileSync(
|
||||
resolve(ROOT, notice.file),
|
||||
withYears(readRepoFile(notice.file), notice, expected),
|
||||
);
|
||||
console.log(`✎ ${notice.file}: ${found} → ${expected}`);
|
||||
} else {
|
||||
failed = true;
|
||||
console.error(
|
||||
`✗ ${notice.file}: ${found}, expected ${expected}. Run: npm run update:copyright`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (failed) process.exit(1);
|
||||
}
|
||||
@@ -29,6 +29,7 @@
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"copyright": "Copyright 2026 poli0981 (SkullMute)",
|
||||
"licenseFile": "installer-license.txt",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
|
||||
@@ -7,6 +7,22 @@
|
||||
|
||||
export const SITE_ORIGIN = "https://ytgenerator.stream";
|
||||
|
||||
/** The year YTDescGen began (first commit: 2026-04-07). */
|
||||
export const COPYRIGHT_START_YEAR = 2026;
|
||||
|
||||
/**
|
||||
* The years a copyright notice states: `"2026"`, then `"2026-2027"` once
|
||||
* `currentYear` moves past the start. Never a range that runs backwards, even
|
||||
* for a clock or a commit dated before the start. NOTICE, REUSE.toml and the
|
||||
* installers' copyright string are kept to this by `npm run check:copyright`;
|
||||
* the legal pages' footer calls it at build time.
|
||||
*/
|
||||
export function copyrightYears(currentYear: number): string {
|
||||
return currentYear > COPYRIGHT_START_YEAR
|
||||
? `${COPYRIGHT_START_YEAR}-${currentYear}`
|
||||
: String(COPYRIGHT_START_YEAR);
|
||||
}
|
||||
|
||||
export const BRAND_GRADIENT = { from: "#6366F1", to: "#A855F7" } as const;
|
||||
|
||||
/** The app mark as an inline SVG string (`aria-hidden`; pair it with text). */
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import { COPYRIGHT_START_YEAR, copyrightYears } from "@config/brand";
|
||||
import { NOTICES, checkNotices, withYears, type Notice } from "../../scripts/lib/copyright";
|
||||
|
||||
function noticeFor(file: string): Notice {
|
||||
const notice = NOTICES.find((n) => n.file === file);
|
||||
if (!notice) throw new Error(`no notice for ${file}`);
|
||||
return notice;
|
||||
}
|
||||
|
||||
describe("copyrightYears", () => {
|
||||
it.each([
|
||||
[2026, "2026"],
|
||||
[2027, "2026-2027"],
|
||||
[2031, "2026-2031"],
|
||||
// A clock or a commit dated before the start never makes a backwards range.
|
||||
[2025, "2026"],
|
||||
])("%i → %s", (year, expected) => {
|
||||
expect(copyrightYears(year)).toBe(expected);
|
||||
});
|
||||
|
||||
it("starts in the year of the first commit", () => {
|
||||
expect(COPYRIGHT_START_YEAR).toBe(2026);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the notices in the repository", () => {
|
||||
// Deliberately independent of today's date: `npm run check:copyright` in CI
|
||||
// holds them to HEAD's year. This catches a file reformatted so the pattern
|
||||
// no longer finds its notice, or one notice drifting from the others.
|
||||
it("are all found and all state the same years", () => {
|
||||
const found = checkNotices(COPYRIGHT_START_YEAR).map((check) => check.found);
|
||||
expect(found).toHaveLength(3);
|
||||
expect(found).not.toContain(null);
|
||||
expect(new Set(found).size).toBe(1);
|
||||
});
|
||||
|
||||
it("include the installers' copyright string", () => {
|
||||
const conf = JSON.parse(readFileSync(resolve("src-tauri/tauri.conf.json"), "utf8")) as {
|
||||
bundle: { copyright?: string };
|
||||
};
|
||||
expect(conf.bundle.copyright).toMatch(/^Copyright [0-9]{4}(-[0-9]{4})? poli0981 /);
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkNotices", () => {
|
||||
it("reports a notice whose years are behind", () => {
|
||||
const read = (file: string) =>
|
||||
file === "NOTICE"
|
||||
? "YTDescGen\nCopyright 2026 poli0981 (https://github.com/poli0981)\n"
|
||||
: "nothing here";
|
||||
const [notice, reuse] = checkNotices(2027, read);
|
||||
expect(notice).toMatchObject({ found: "2026", expected: "2026-2027" });
|
||||
expect(reuse).toMatchObject({ found: null, expected: "2026-2027" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("withYears", () => {
|
||||
it.each(NOTICES.map((n) => [n.file]))("rewrites only the years in %s", (file) => {
|
||||
const notice = noticeFor(file);
|
||||
const raw = readFileSync(resolve(file), "utf8");
|
||||
const current = notice.pattern.exec(raw)?.[1];
|
||||
expect(current).toBeDefined();
|
||||
|
||||
const updated = withYears(raw, notice, "2026-2099");
|
||||
expect(notice.pattern.exec(updated)?.[1]).toBe("2026-2099");
|
||||
// Swapping the years back restores the file byte for byte.
|
||||
expect(withYears(updated, notice, current ?? "")).toBe(raw);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user