From 38f47add8b19632c5dc2d9e1f2539f8c30dd86f6 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Sat, 3 Oct 2026 09:08:09 +0700 Subject: [PATCH] chore(legal): keep copyright years current, checked in CI Every notice already says 2026, which is right: the first commit is from 2026-04-07, so there is no 2025 to fix and no 2025-2026 range to claim. What was missing is anything keeping the years current. - src/config/brand.ts: COPYRIGHT_START_YEAR and copyrightYears(), "2026" now and "2026-2027" from the first commit made in 2027 - npm run check:copyright (CI, next to check:licenses) holds NOTICE, REUSE.toml and the installers' copyright string to HEAD's commit year, not the clock, so old commits stay green; npm run update:copyright rewrites them - tauri.conf.json gains bundle.copyright, so the .exe/NSIS, macOS and Linux packages stop shipping an empty copyright field - the /legal pages' footer prints the same range at build time Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 5 ++ build-plugins/legal-docs.ts | 4 +- package.json | 4 +- scripts/check-copyright.ts | 10 +++ scripts/lib/copyright.ts | 111 ++++++++++++++++++++++++++++++++ src-tauri/tauri.conf.json | 1 + src/config/brand.ts | 16 +++++ tests/scripts/copyright.test.ts | 72 +++++++++++++++++++++ 8 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 scripts/check-copyright.ts create mode 100644 scripts/lib/copyright.ts create mode 100644 tests/scripts/copyright.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fb5090..157b100 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/build-plugins/legal-docs.ts b/build-plugins/legal-docs.ts index d25fad3..a2d7a32 100644 --- a/build-plugins/legal-docs.ts +++ b/build-plugins/legal-docs.ts @@ -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: {
${options.body}
- + `; diff --git a/package.json b/package.json index cc83000..917ddb4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/check-copyright.ts b/scripts/check-copyright.ts new file mode 100644 index 0000000..89b4009 --- /dev/null +++ b/scripts/check-copyright.ts @@ -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(); diff --git a/scripts/lib/copyright.ts b/scripts/lib/copyright.ts new file mode 100644 index 0000000..34d39bd --- /dev/null +++ b/scripts/lib/copyright.ts @@ -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); +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 353dcf3..1107c36 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -29,6 +29,7 @@ }, "bundle": { "active": true, + "copyright": "Copyright 2026 poli0981 (SkullMute)", "licenseFile": "installer-license.txt", "icon": [ "icons/32x32.png", diff --git a/src/config/brand.ts b/src/config/brand.ts index 15828b7..5cb0e5f 100644 --- a/src/config/brand.ts +++ b/src/config/brand.ts @@ -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). */ diff --git a/tests/scripts/copyright.test.ts b/tests/scripts/copyright.test.ts new file mode 100644 index 0000000..89fc991 --- /dev/null +++ b/tests/scripts/copyright.test.ts @@ -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); + }); +});