diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cb5f785 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +permissions: + contents: read + +jobs: + checks: + name: Install lint and tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + cache: npm + + - name: Install dependencies + run: npm ci --ignore-scripts + + # The check an instance runs when a board installs the theme, run on the + # packed tarball rather than on the sources. + - name: Install lint + run: npm run lint + + - name: Test + run: npm test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4ed0619 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,124 @@ +# Releases the theme when a `v` tag is pushed. +# +# The catalog lists a theme only if its tarball is an asset of an immutable +# release made by this workflow, on a GitHub-hosted runner, for the release's +# own tag, and carries an attestation from that run (see "The release workflow +# runs on the tag" in the plugin contract of openbrf/openbrf). So this starts +# on the tag push and nowhere else: a run on main, or one started by hand, +# would make an attestation the catalog refuses. +# +# To release: set `version` in theme.json and package.json in a pull request, +# merge it, then push the tag from the merged commit: +# +# git tag v0.1.0 && git push origin v0.1.0 +# +# Create no release in the GitHub UI first. Publishing a release with a new tag +# creates the tag, the tag push then starts this workflow after the release is +# already immutable, and the upload of the tarball fails. +# +# The tarball is packed once, attested, and attached to the release before the +# release is published, because the assets of an immutable release cannot +# change afterwards. +name: Release + +on: + push: + tags: ["v*"] + +concurrency: + group: release + cancel-in-progress: false + +permissions: + contents: read + +jobs: + release: + name: Pack, attest and release + runs-on: ubuntu-latest + permissions: + # Create the release and upload the tarball. + contents: write + # Attest the tarball. + id-token: write + attestations: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Whole history, to tell whether the tagged commit is on main. + fetch-depth: 0 + # Nothing here pushes, so the token has no reason to sit in the + # runner's git config where later steps and scripts can read it. + persist-credentials: false + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + + # A tag is cheap to push from anywhere, so the run refuses one that is + # not main's own commit and one that does not match the version the + # manifest states. + - name: Check the tag + env: + TAG: ${{ github.ref_name }} + run: | + if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then + echo "::error::$TAG is not on main. Merge the release first, then tag the merged commit." + exit 1 + fi + version=$(node -p 'require("./theme.json").version') + if [ "$TAG" != "v$version" ]; then + echo "::error::The tag is $TAG but theme.json states version $version." + exit 1 + fi + if [ "$(node -p 'require("./package.json").version')" != "$version" ]; then + echo "::error::package.json and theme.json state different versions." + exit 1 + fi + + - name: Install dependencies + run: npm ci --ignore-scripts + + - name: Install lint + run: npm run lint + + - name: Test + run: npm test + + - name: Pack + id: pack + run: | + file=$(node scripts/pack.mjs) + echo "file=$file" >> "$GITHUB_OUTPUT" + + - name: Attest the tarball + uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2 + with: + subject-path: ${{ steps.pack.outputs.file }} + + # Created as a draft, so the tarball is attached before the release is + # published and becomes immutable. + - name: Create the release + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + FILE: ${{ steps.pack.outputs.file }} + run: | + gh release create "$TAG" "$FILE" \ + --draft \ + --verify-tag \ + --title "$TAG" \ + --notes "Release $TAG of the Open BRF example theme. Verify the tarball with: gh attestation verify $(basename "$FILE") --repo $GITHUB_REPOSITORY --source-ref refs/tags/$TAG" + gh release edit "$TAG" --draft=false + + # What a catalog entry for this release states. + - name: Report the digest + env: + FILE: ${{ steps.pack.outputs.file }} + run: | + { + echo "### $(basename "$FILE")" + echo + echo "- sha512: \`$(sha512sum "$FILE" | cut -d' ' -f1)\`" + echo "- bytes: \`$(stat -c %s "$FILE")\`" + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b947077 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..2b42e39 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +26.12.0 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..df6f34f --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +MIT No Attribution + +Copyright 2026 Open BRF contributors + +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. + +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. diff --git a/README.md b/README.md index 605044a..5e416a9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,83 @@ # example-theme -Reference Open BRF theme: data-only token set extending the default theme. + +The reference theme for [Open BRF](https://github.com/openbrf/openbrf): a +data-only token set that extends the default theme, to start your own from. + +It changes what a theme usually changes first. The trust accent is green +instead of brass, in light and dark; controls have a slightly rounder corner; +and the register's monospace face, Spline Sans Mono, is bundled in the package +rather than loaded from anywhere. Everything it does not state it inherits from +`porttavlan`, the default theme. + +A theme is pure data: no JavaScript, so installing one needs no restart and +carries no supply-chain risk. The format, every token and the rules a theme is +held to are in the +[token contract](https://github.com/openbrf/openbrf/blob/main/docs/theme-contract.md). + +## What is in here + +| Path | What it is | +| ------------------------------------ | ------------------------------------------------------- | +| `theme.json` | The manifest: identity, token values, fonts, variants | +| `fonts/spline-sans-mono-latin.woff2` | The bundled typeface | +| `fonts/OFL.txt` | Its licence, which the font requires to travel with it | +| `scripts/pack.mjs` | Packs the theme into `dist/example-theme-.tgz` | +| `scripts/lint.mjs` | Runs the install lint on the packed theme | +| `test/` | The lint as a test, plus a check that it can still fail | + +## Making your own + +Copy the repository, rename the theme in `theme.json` and `package.json` (a +name is lowercase words joined by hyphens, and unique in the catalog), and +change the values. Then check it the way an instance will: + +```sh +npm install +npm run lint # packs the theme and runs the install lint on the tarball +npm test +``` + +`npm run lint` uses +[`@openbrf/theme-tools`](https://www.npmjs.com/package/@openbrf/theme-tools), +the same package the core runs when a board installs a theme, so you see the +same refusal before you publish. The lint is a gate: it refuses a theme that +renders the statutory register below WCAG AA, one that carries anything +executable, and one that loads a font from outside the package or bundles one +with no licence. + +A font you bundle needs its own licence file and a declaration in `theme.json`. +Do not link a font from a CDN: that discloses every viewer's IP address to a +third party. + +## Releasing + +A release is made by `.github/workflows/release.yml` and only by a pushed tag. +The catalog lists a theme only if its tarball is an asset of an immutable GitHub +release, with a build attestation from that workflow on the release's tag. The +repository needs GitHub's immutable releases setting on before the first one. + +1. Set `version` in `theme.json` and `package.json` in a pull request, and merge + it. +2. Tag the merged commit and push the tag: + + ```sh + git tag v0.1.0 + git push origin v0.1.0 + ``` + +The workflow refuses a tag that is not on `main` or that does not match the +manifest's version, lints and tests, packs the tarball once, attests it, +attaches it to the release and publishes. Its run summary shows the `sha512` +and size to state in the catalog entry. + +Do not publish a release from the GitHub UI first: that creates the tag after +the release is already immutable, and the tarball can no longer be attached. + +To be installable from the curated catalog, a release is then listed with a pull +request to [`openbrf/catalog`](https://github.com/openbrf/catalog). + +## Licence + +[MIT-0](LICENSE): no conditions, so you can start a proprietary theme from this +one without keeping a notice. The bundled font is under the SIL Open Font +License 1.1; see `fonts/OFL.txt`. diff --git a/fonts/OFL.txt b/fonts/OFL.txt new file mode 100644 index 0000000..ebcad12 --- /dev/null +++ b/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2022 The Spline Sans Mono Project Authors (https://github.com/SorkinType/SplineSansMono) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/fonts/spline-sans-mono-latin.woff2 b/fonts/spline-sans-mono-latin.woff2 new file mode 100644 index 0000000..5ffd342 Binary files /dev/null and b/fonts/spline-sans-mono-latin.woff2 differ diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..23b4b59 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,44 @@ +{ + "name": "example-theme", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "example-theme", + "version": "0.1.0", + "license": "MIT-0", + "devDependencies": { + "@openbrf/theme-tools": "^1.0.0" + } + }, + "node_modules/@openbrf/theme-tools": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@openbrf/theme-tools/-/theme-tools-1.0.0.tgz", + "integrity": "sha512-BHFmJvCKPy2iN1drVWyFC0VzXT/+Wy9fBq7XJjmwPOcf0OxpwUalP+LsYv7SfH95L4NzMOO2vcgObR/1D85/Ww==", + "dev": true, + "license": "AGPL-3.0-only", + "dependencies": { + "@openbrf/tokens": "^1.0.0", + "zod": "^4.6.7" + } + }, + "node_modules/@openbrf/tokens": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@openbrf/tokens/-/tokens-1.0.0.tgz", + "integrity": "sha512-0K/M/TpiBHQXGkFScaqE0MKr9byaiP8jng8NY2J+EmF3BgbOwb+W41YXv96vyWWlWr9/Eckd6J5GlRxlHUTDrg==", + "dev": true, + "license": "AGPL-3.0-only" + }, + "node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..edfc299 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "example-theme", + "version": "0.1.0", + "private": true, + "description": "Reference Open BRF theme: a data-only token set extending the default theme.", + "license": "MIT-0", + "type": "module", + "scripts": { + "pack": "node scripts/pack.mjs", + "lint": "node scripts/lint.mjs", + "test": "node --test test/" + }, + "devDependencies": { + "@openbrf/theme-tools": "^1.0.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/openbrf/example-theme.git" + } +} diff --git a/scripts/lint.mjs b/scripts/lint.mjs new file mode 100644 index 0000000..addff44 --- /dev/null +++ b/scripts/lint.mjs @@ -0,0 +1,43 @@ +/** + * Lints a packed theme with the check an instance runs at install. + * + * Takes the tarball's path, and packs the theme first when given none. Exits + * non-zero when the package cannot be read or the lint finds an error; + * warnings are printed and do not fail, as at install. + */ +import { readFile } from "node:fs/promises"; +import { execFileSync } from "node:child_process"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { lintThemePackage } from "@openbrf/theme-tools"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); + +const path = + process.argv[2] ?? + execFileSync(process.execPath, [join(root, "scripts", "pack.mjs")], { + encoding: "utf8", + }).trim(); + +const result = lintThemePackage(await readFile(path)); + +if (!result.ok) { + console.error(`${path}: cannot be read (${result.reason})`); + for (const issue of result.issues) { + console.error(` ${issue}`); + } + process.exit(1); +} + +for (const finding of result.lint.findings) { + const where = finding.severity === "error" ? "error" : "warning"; + console.error(`${where}: ${JSON.stringify(finding)}`); +} + +if (!result.lint.ok) { + process.exit(1); +} +console.log( + `${result.manifest.name} ${result.manifest.version}: passes the install lint`, +); diff --git a/scripts/pack.mjs b/scripts/pack.mjs new file mode 100644 index 0000000..959ec1d --- /dev/null +++ b/scripts/pack.mjs @@ -0,0 +1,45 @@ +/** + * Packs the theme into dist/-.tgz and prints the file's path. + * + * The package is the files an instance reads and nothing else: theme.json, the + * fonts directory and the licence. `writeThemeArchive` is the writer the core + * tests its own reader with, and it is deterministic, so packing the same + * sources twice gives the same bytes and the sha512 the catalog states stays + * meaningful. + */ +import { mkdir, readdir, readFile, writeFile } from "node:fs/promises"; +import { dirname, join, relative } from "node:path"; +import { fileURLToPath } from "node:url"; + +import { writeThemeArchive } from "@openbrf/theme-tools"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); + +async function* walk(directory) { + for (const entry of await readdir(directory, { withFileTypes: true })) { + const path = join(directory, entry.name); + if (entry.isDirectory()) { + yield* walk(path); + } else if (entry.isFile()) { + yield path; + } + } +} + +const files = new Map(); +const add = async (path, name = relative(root, path)) => + files.set(name.split("\\").join("/"), await readFile(path)); + +await add(join(root, "theme.json")); +// `.txt` is a file type a package may carry; a bare `LICENSE` is not. +await add(join(root, "LICENSE"), "LICENSE.txt"); +for await (const path of walk(join(root, "fonts"))) { + await add(path); +} + +const manifest = JSON.parse(files.get("theme.json").toString("utf8")); +const output = join(root, "dist", `${manifest.name}-${manifest.version}.tgz`); + +await mkdir(dirname(output), { recursive: true }); +await writeFile(output, writeThemeArchive(files)); +console.log(output); diff --git a/test/theme.test.mjs b/test/theme.test.mjs new file mode 100644 index 0000000..62b6c0a --- /dev/null +++ b/test/theme.test.mjs @@ -0,0 +1,74 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { readFile } from "node:fs/promises"; +import { dirname, join } from "node:path"; +import { test } from "node:test"; +import { fileURLToPath } from "node:url"; + +import { + lintThemePackage, + readThemeArchive, + writeThemeArchive, +} from "@openbrf/theme-tools"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const pack = () => + execFileSync(process.execPath, [join(root, "scripts", "pack.mjs")], { + encoding: "utf8", + }).trim(); + +test("the packed theme passes the install lint with no finding", async () => { + const result = lintThemePackage(await readFile(pack())); + + assert.equal(result.ok, true); + assert.equal(result.lint.ok, true); + assert.deepEqual(result.lint.findings, []); +}); + +test("packing twice gives the same bytes", async () => { + const digest = async () => + createHash("sha512") + .update(await readFile(pack())) + .digest("hex"); + + assert.equal(await digest(), await digest()); +}); + +test("the package carries the manifest, the licences and the declared font", async () => { + const files = readThemeArchive(await readFile(pack())); + + assert.deepEqual([...files.keys()].sort(), [ + "LICENSE.txt", + "fonts/OFL.txt", + "fonts/spline-sans-mono-latin.woff2", + "theme.json", + ]); +}); + +test("the manifest and package.json state the same version", async () => { + const manifest = JSON.parse(await readFile(join(root, "theme.json"), "utf8")); + const pkg = JSON.parse(await readFile(join(root, "package.json"), "utf8")); + + assert.equal(manifest.version, pkg.version); + assert.equal(manifest.name, pkg.name); +}); + +test("the lint refuses this theme once its accent is unreadable", async () => { + const files = new Map(readThemeArchive(await readFile(pack()))); + const manifest = JSON.parse( + new TextDecoder().decode(files.get("theme.json")), + ); + // Light text on a light ground: the pair the lint measures, made to fail. + manifest.modes.light["on-accent-trust"] = + manifest.modes.light["accent-trust"]; + files.set("theme.json", new TextEncoder().encode(JSON.stringify(manifest))); + + const result = lintThemePackage(writeThemeArchive(files)); + + assert.equal(result.ok, true); + assert.equal(result.lint.ok, false); + assert.ok( + result.lint.findings.some((finding) => finding.rule === "contrast"), + ); +}); diff --git a/theme.json b/theme.json new file mode 100644 index 0000000..0083232 --- /dev/null +++ b/theme.json @@ -0,0 +1,46 @@ +{ + "name": "example-theme", + "displayName": "Example", + "version": "0.1.0", + "contract": "^1.0.0", + "extends": "porttavlan", + "description": "A theme that inherits the default and changes the trust accent to green, bundling its own typeface.", + "modes": { + "light": { + "accent-trust": "#2F5D50", + "accent-trust-hover": "#264C42", + "accent-trust-soft": "#DCE8E4", + "accent-trust-register": "#7FBFAA", + "on-accent-trust": "#FFFFFF", + "radius-control": "6px", + "font-data": "'Spline Sans Mono', ui-monospace, SFMono-Regular, Menlo, monospace" + }, + "dark": { + "accent-trust": "#7FBFAA", + "accent-trust-hover": "#93CCB9", + "accent-trust-soft": "#1E2E29", + "accent-trust-register": "#7FBFAA", + "on-accent-trust": "#17181A", + "radius-control": "6px", + "font-data": "'Spline Sans Mono', ui-monospace, SFMono-Regular, Menlo, monospace" + } + }, + "fonts": [ + { + "family": "Spline Sans Mono", + "license": "OFL-1.1", + "licenseFile": "fonts/OFL.txt", + "files": [ + { + "path": "fonts/spline-sans-mono-latin.woff2", + "weight": "400 700", + "style": "normal" + } + ] + } + ], + "viewVariants": { + "memberRegister": "table" + }, + "license": "MIT-0" +}