Skip to content
Merged
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
14 changes: 10 additions & 4 deletions .github/workflows/repo-banners.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Renders the README banner for every public AsBuiltReport.* repo into assets/repo-banners/,
# the organisation profile tiles into profile/images/tiles/, and the README section icon pack
# into assets/section-icons/, then commits any that changed.
# the organisation profile tiles into profile/images/tiles/, the README section icon pack
# into assets/section-icons/, and the health check highlight swatches into
# assets/highlight-swatches/, then commits any that changed.
# On a pull request it renders without committing, and uploads the images for review.
# The generator lives in generator/. Run it by hand after creating a new repo, or wait for the daily run.
name: Repo banners
Expand Down Expand Up @@ -57,6 +58,10 @@ jobs:
working-directory: generator
run: node section-icons.mjs

- name: Render highlight swatches
working-directory: generator
run: node highlight-swatches.mjs

- name: Render banners and tiles
working-directory: generator
env:
Expand All @@ -77,17 +82,18 @@ jobs:
path: |
assets/repo-banners
assets/section-icons
assets/highlight-swatches
profile/images/tiles

- name: Commit changes
if: github.event_name != 'pull_request'
run: |
git add assets/repo-banners assets/section-icons profile/images/tiles
git add assets/repo-banners assets/section-icons assets/highlight-swatches profile/images/tiles
if git diff --cached --quiet; then
echo "No banner changes"
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -m 'Update repo banners, profile tiles and section icons'
git commit -m 'Update repo banners, profile tiles, section icons and highlight swatches'
git push
11 changes: 10 additions & 1 deletion generator/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Brand asset generator

Renders the brand images for AsBuiltReport repos: a README banner for every public `AsBuiltReport.*` repo and the module tiles on the organisation profile, from one HTML template, and the section icon pack used on README headings.
Renders the brand images for AsBuiltReport repos: a README banner for every public `AsBuiltReport.*` repo and the module tiles on the organisation profile, from one HTML template, the section icon pack used on README headings, and the health check highlight swatches used in README HealthCheck tables.

| Output | Size | Path |
|---|---|---|
| README banner | 1760 x 480 | `assets/repo-banners/<repo>.png` |
| Profile tile | 840 x 240 | `profile/images/tiles/<repo>.png` |
| README section icon | 32 x 32 SVG, 96 x 96 PNG | `assets/section-icons/<name>.svg`, `.png` |
| Highlight swatch | 16 x 16 SVG | `assets/highlight-swatches/<HEX>.svg` |

The [Repo banners](../.github/workflows/repo-banners.yml) workflow runs daily, on pushes to `generator/`, and by hand. It commits only the images that changed. After creating a new repo, run the workflow by hand so its banner exists straight away.

Expand All @@ -20,6 +21,12 @@ The [Repo banners](../.github/workflows/repo-banners.yml) workflow runs daily, o

Section headings in module READMEs use icons in place of emoji, in the style of the feature icons on [www.asbuiltreport.com](https://www.asbuiltreport.com): an [Octicons](https://primer.style/octicons/) glyph in console blue on a highlighter yellow tile. `section-icons.json` lists each icon, its Octicon and the heading texts it is used for. `section-icons.mjs` renders them, with a catalogue at [`assets/section-icons`](../assets/section-icons). To add an icon, add an entry to `section-icons.json`.

## Highlight swatches

HealthCheck tables in module READMEs show each highlight colour as a small swatch. They used to come from placeholder image services such as placehold.co, place-hold.it and via.placeholder.com, which break. `highlight-swatches.json` lists the highlight colours of each report style: the AsBuiltReport.Core default style, and the modules with a style of their own. `highlight-swatches.mjs` renders a swatch for each colour, with a catalogue at [`assets/highlight-swatches`](../assets/highlight-swatches).

When a module adds its own report style, add its `Critical`, `Warning`, `Info` and `OK` colours to `highlight-swatches.json` under the repo name.

## Using a banner in a README

```html
Expand All @@ -39,6 +46,7 @@ New modules get this from the [Plaster template](https://github.com/AsBuiltRepor
- the banner in place of the old logo at the top (or at the top when there is no logo)
- section icons in place of the emoji on known section headings, sized to the heading level (headings inside code blocks are left alone)
- badges in the brand palette: link blue `#1F5FD0` for versions, console blue `#012456` for counts (downloads, contributors), highlighter `#FFD02B` for compatibility (platform)
- central highlight swatches in place of placeholder images, in the colour the repo's report style uses (by the image's alt text: `Critical`, `Warning`, `Info` or `OK`), so a README never shows a colour the report does not use

Where the pull request is already open, it commits to that branch instead. It skips READMEs that already have every change. It is a dry run unless you pass `--apply`:

Expand All @@ -60,6 +68,7 @@ npx playwright install chromium
node render.mjs # every repo
node render.mjs --repo AsBuiltReport.Microsoft.Azure # one repo
node section-icons.mjs # the section icon pack
node highlight-swatches.mjs # the highlight swatches
node --test # tests
```

Expand Down
13 changes: 13 additions & 0 deletions generator/highlight-swatches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_comment": "Health check highlight colours, by report style. A repo uses the default (AsBuiltReport.Core) style unless it is listed with its own. Each colour must match the BackgroundColor of that Style -Name in the style file, so a README swatch shows the colour the report really uses.",
"styles": {
"default": {
"source": "AsBuiltReport.Core default style (AsBuiltReport.Core.Style.ps1)",
"colours": { "Critical": "FEDDD7", "Warning": "FFF4C7", "Info": "E3F5FC", "OK": "DFF0D0" }
},
"AsBuiltReport.Nutanix.PrismElement": {
"source": "AsBuiltReport.Nutanix.PrismElement.Style.ps1",
"colours": { "Critical": "F55656", "Warning": "FFBC0B", "Info": "22A5F7", "OK": "36D068" }
}
}
}
73 changes: 73 additions & 0 deletions generator/highlight-swatches.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Renders a swatch for every health check highlight colour in highlight-swatches.json into
// assets/highlight-swatches/<HEX>.svg, with a catalogue README. READMEs use them in their
// HealthCheck tables, in place of third-party placeholder image services.
//
// The swatches follow the colour swatches in the brand guide: a 16 px square with a 3 px corner
// and a #C5D2E6 rule border, so pale highlights stay visible on a white page.
//
// Usage (from this folder): node highlight-swatches.mjs
// Only files whose bytes change are written.

import { readFile, writeFile, mkdir } from "node:fs/promises";
import { existsSync } from "node:fs";
import { join } from "node:path";
import { config, here } from "./repos.mjs";

const { styles } = JSON.parse(await readFile(join(here, "highlight-swatches.json"), "utf8"));
const outDir = join(here, "..", "assets", "highlight-swatches");
const baseUrl = `https://raw.githubusercontent.com/${config.org}/.github/main/assets/highlight-swatches`;

export function swatchSvg(hex) {
return [
`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" role="img" aria-label="#${hex}">`,
`<rect x="0.5" y="0.5" width="15" height="15" rx="3" fill="#${hex}" stroke="#C5D2E6"/>`,
"</svg>",
"",
].join("\n");
}

async function writeIfChanged(path, text) {
if (existsSync(path) && (await readFile(path, "utf8")) === text) return false;
await writeFile(path, text);
return true;
}

function catalogue() {
const sections = Object.entries(styles).flatMap(([name, style]) => [
`## ${name === "default" ? "Default style" : name}`,
"",
`From ${style.source}.${name === "default" ? " Used by every module that does not define its own highlight colours." : ""}`,
"",
"| Swatch | Style | Hex |",
"|:---:|---|---|",
...Object.entries(style.colours).map(([label, hex]) => `| <img src="${hex}.svg" alt="#${hex}" width="16" height="16"> | ${label} | \`#${hex}\` |`),
"",
]);
return [
"# Health check highlight swatches",
"",
"Colour swatches for the HealthCheck tables in AsBuiltReport module READMEs. Each one shows the background colour that a report gives a highlighted cell, so readers can match the README to the report.",
"",
"This folder is generated by [`generator/highlight-swatches.mjs`](../../generator/highlight-swatches.mjs) from [`highlight-swatches.json`](../../generator/highlight-swatches.json). Do not edit the files here by hand. When a module adds its own report style, add its colours to that file.",
"",
...sections,
"## Using a swatch",
"",
"Use the swatch for the colour the module's report uses, with the style name as the alt text:",
"",
"```markdown",
`![Warning](${baseUrl}/FFF4C7.svg) VM snapshot age >= 7 days`,
"```",
"",
].join("\n");
}

await mkdir(outDir, { recursive: true });
const colours = [...new Set(Object.values(styles).flatMap((s) => Object.values(s.colours)))];
let changed = 0;
for (const hex of colours) {
if (!/^[0-9A-F]{6}$/.test(hex)) throw new Error(`Invalid colour ${hex}: use six upper case hex digits`);
if (await writeIfChanged(join(outDir, `${hex}.svg`), swatchSvg(hex))) changed++;
}
if (await writeIfChanged(join(outDir, "README.md"), catalogue())) changed++;
console.log(`${colours.length} swatches, ${changed} file(s) changed`);
34 changes: 33 additions & 1 deletion generator/readme-brand.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// addBanner the repo banner in place of the old organisation logo
// addSectionIcons section icons in place of the emoji on known section headings
// recolourBadges shields.io badges in the brand palette
// replaceHighlightSwatches central health check highlight swatches in place of placeholder services
// readme-banners.mjs uses these to open pull requests. readme-brand.test.mjs tests them.

import { readFileSync } from "node:fs";
Expand Down Expand Up @@ -103,6 +104,37 @@ export function recolourBadges(readme) {
return readme.replace(/https:\/\/img\.shields\.io\/[^\s"'()<>]+/g, recolourBadge);
}

// ---------- Highlight swatches ----------

// HealthCheck tables show each highlight colour as a small image from a third-party placeholder
// service, which often breaks. These are replaced with the central swatches. The colour comes from
// the repo's report style (highlight-swatches.json), not the old link, because some READMEs show
// colours copied from another module's style.
const { styles } = JSON.parse(readFileSync(join(here, "highlight-swatches.json"), "utf8"));
const placeholderImage = /!\[([^\]]*)\]\((https?:\/\/(?:placehold\.co|place-hold\.it|via\.placeholder\.com|dummyimage\.com)\/[^)\s]*)\)/g;
const styleLabels = { critical: "Critical", citical: "Critical", warning: "Warning", info: "Info", ok: "OK" };

export function swatchUrl(hex) {
return `${assetBase}/highlight-swatches/${hex}.svg`;
}

export function replaceHighlightSwatches(readme, repo) {
const colours = (styles[repo] || styles.default).colours;
const known = new Set(Object.values(styles).flatMap((s) => Object.values(s.colours)));
return readme.replace(placeholderImage, (match, alt, url) => {
const label = styleLabels[alt.trim().toLowerCase()];
if (label && colours[label]) return `![${label}](${swatchUrl(colours[label])})`;
// Unknown style name: keep the link's own colour when there is a swatch for it.
const hex = (url.match(/(?<![0-9A-Fa-f])[0-9A-Fa-f]{6}(?![0-9A-Fa-f])/) || [""])[0].toUpperCase();
return known.has(hex) ? `![${alt}](${swatchUrl(hex)})` : match;
});
}

// Placeholder images that replaceHighlightSwatches could not map, for the dry run to report.
export function unmappedPlaceholders(readme) {
return [...readme.matchAll(placeholderImage)].map((m) => m[0]);
}

export function applyBrand(readme, repo) {
return recolourBadges(addSectionIcons(addBanner(readme, repo)));
return replaceHighlightSwatches(recolourBadges(addSectionIcons(addBanner(readme, repo))), repo);
}
34 changes: 30 additions & 4 deletions generator/readme-brand.test.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Tests for readme-brand.mjs: the banner, section icon and badge changes made to module READMEs.
// Nothing is stubbed: the functions are pure and read only section-icons.json and repos.json.
// Tests for readme-brand.mjs: the banner, section icon, badge and highlight swatch changes made to module READMEs.
// Nothing is stubbed: the functions are pure and read only section-icons.json, highlight-swatches.json and repos.json.
// Run from this folder: node --test
// To check against the live READMEs as well, set README_DIR to a folder of downloaded README files.

import { test } from "node:test";
import assert from "node:assert/strict";
import { readdirSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { addBanner, addSectionIcons, recolourBadge, recolourBadges, applyBrand } from "./readme-brand.mjs";
import { addBanner, addSectionIcons, recolourBadge, recolourBadges, replaceHighlightSwatches, unmappedPlaceholders, swatchUrl, applyBrand } from "./readme-brand.mjs";

const icon = (name, size) => `<img src="https://raw.githubusercontent.com/AsBuiltReport/.github/main/assets/section-icons/${name}.svg" alt="" width="${size}" height="${size}" align="top">`;

Expand Down Expand Up @@ -63,6 +63,31 @@ test("replaces an existing colour and keeps other query parameters", () => {
assert.equal(recolourBadges('<img src="https://img.shields.io/powershellgallery/v/X.svg" />'), '<img src="https://img.shields.io/powershellgallery/v/X.svg?color=1F5FD0" />');
});

test("replaces placeholder services with the central swatch for the repo's style", () => {
const row = "| ![Warning](https://placehold.co/15x15/FFF4C7/FFF4C7) Unknown<br> ![Critical](https://place-hold.it/15/FEDDD7/FEDDD7.png) Offline |";
assert.equal(replaceHighlightSwatches(row, "AsBuiltReport.VMware.vSphere"), `| ![Warning](${swatchUrl("FFF4C7")}) Unknown<br> ![Critical](${swatchUrl("FEDDD7")}) Offline |`);
});

// VMware.ESXi showed PureStorage's colours and Azure an Info colour from no style. Both reports use the Core style.
test("uses the report style's colour, not the colour in the old link", () => {
assert.equal(replaceHighlightSwatches("![Warning](https://place-hold.it/15/FFE860/FFE860.png)", "AsBuiltReport.VMware.ESXi"), `![Warning](${swatchUrl("FFF4C7")})`);
assert.equal(replaceHighlightSwatches("![Info](https://placehold.co/15x15/D4E4F7/D4E4F7)", "AsBuiltReport.Microsoft.Azure"), `![Info](${swatchUrl("E3F5FC")})`);
});

test("uses a module's own style where it has one", () => {
assert.equal(replaceHighlightSwatches("![Warning](https://via.placeholder.com/15/FFBC0B/FFBC0B.png)", "AsBuiltReport.Nutanix.PrismElement"), `![Warning](${swatchUrl("FFBC0B")})`);
});

test("corrects the Citical alt text typo", () => {
assert.equal(replaceHighlightSwatches("![Citical](https://placehold.co/15x15/FEDDD7/FEDDD7)", "AsBuiltReport.Microsoft.Azure"), `![Critical](${swatchUrl("FEDDD7")})`);
});

test("leaves a placeholder alone when neither the style name nor the colour is known", () => {
const unknown = "![Odd](https://placehold.co/15x15/123456/123456)";
assert.equal(replaceHighlightSwatches(unknown, "AsBuiltReport.Core"), unknown);
assert.deepEqual(unmappedPlaceholders(unknown), [unknown]);
});

test("adds the banner once", () => {
const readme = "<p align=\"center\">\n <a href=\"https://www.asbuiltreport.com/\" alt=\"AsBuiltReport\"></a>\n <img src='https://github.com/AsBuiltReport.png' width=\"8%\" height=\"8%\" /></a>\n</p>\nText";
const once = addBanner(readme, "AsBuiltReport.Core");
Expand All @@ -80,10 +105,11 @@ if (readmeDir) {
const before = readFileSync(join(readmeDir, file), "utf8");
const after = applyBrand(before, repo);
assert.equal(applyBrand(after, repo), after, "second run changes nothing");
assert.deepEqual(unmappedPlaceholders(after), [], "no placeholder images left");
const lines = (t) => t.split(/\r?\n/);
const changed = lines(after).filter((l, i, all) => !lines(before).includes(l));
for (const line of changed) {
assert.ok(/section-icons\/|img\.shields\.io|repo-banners\/|^<p align="center">$|^\s*<a href="https:\/\/www\.asbuiltreport\.com\/">$|^<\/p>$/.test(line), `unexpected change: ${line}`);
assert.ok(/section-icons\/|highlight-swatches\/|img\.shields\.io|repo-banners\/|^<p align="center">$|^\s*<a href="https:\/\/www\.asbuiltreport\.com\/">$|^<\/p>$/.test(line), `unexpected change: ${line}`);
}
});
}
Expand Down
Loading
Loading