Skip to content

Commit 8a26a0c

Browse files
committed
What's new entries as separate files, so pull requests stop conflicting
Each pull request now adds e63334287a3deaa3/news/<name>.json instead of editing the top of NEWS in news.js. After the merge, whats-new-publish.yml gives it the next version and the merge date, adds it to news.js and news-es.js, and deletes the file. whats-new.yml checks the file and stops new entries being added to news.js directly. CLAUDE.md, README and the how-to in news.js describe the new way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ZY4GZnqpViom1bxpWJCnY
1 parent e925005 commit 8a26a0c

9 files changed

Lines changed: 275 additions & 13 deletions

File tree

‎.github/scripts/news.js‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#!/usr/bin/env node
2+
// What's new entries as separate files, so pull requests stop colliding.
3+
//
4+
// Each pull request adds one file, e63334287a3deaa3/news/<name>.json, instead of editing the top of NEWS in
5+
// e63334287a3deaa3/news.js. Nobody else edits that file, so open pull requests no longer conflict there, and
6+
// nobody has to guess the next version or the merge date: after the merge, the "What's new: publish" workflow
7+
// runs this script, which gives the entry the next version and today's date, puts it at the top of NEWS (and its
8+
// Spanish in news-es.js), and deletes the file. See e63334287a3deaa3/news/README.md for the format.
9+
//
10+
// node .github/scripts/news.js check <file.json> ... check entries (the pull request check)
11+
// node .github/scripts/news.js publish publish every waiting entry, oldest first
12+
//
13+
// Files whose names start with _ (like _example.json) are templates and are never published.
14+
'use strict';
15+
const fs = require('fs');
16+
const path = require('path');
17+
const { execFileSync } = require('child_process');
18+
19+
const ROOT = path.resolve(__dirname, '..', '..');
20+
const DIR = 'e63334287a3deaa3/news';
21+
const NEWS_JS = 'e63334287a3deaa3/news.js';
22+
const NEWS_ES = 'e63334287a3deaa3/news-es.js';
23+
const TZ = process.env.NEWS_TZ || 'America/New_York';
24+
const KINDS = ['game', 'feature', 'fix', 'soon'];
25+
const FIELDS = ['kind', 'title', 'items', 'games', 'img', 'tags', 'link', 'date', 'noVersion', 'es'];
26+
27+
const abs = (p) => path.join(ROOT, p);
28+
29+
function read(file) {
30+
let e;
31+
try { e = JSON.parse(fs.readFileSync(abs(file), 'utf8')); }
32+
catch (err) { return { errors: [`isn't valid JSON: ${err.message}`] }; }
33+
const errors = [], warnings = [];
34+
if (!e || typeof e !== 'object' || Array.isArray(e)) return { errors: ['must be one JSON object {...}'] };
35+
const isStr = (v) => typeof v === 'string' && v.trim() !== '';
36+
const strList = (v) => Array.isArray(v) && v.length > 0 && v.every(isStr);
37+
for (const k of Object.keys(e)) if (!FIELDS.includes(k) && k !== 'version') errors.push(`unknown field "${k}" (allowed: ${FIELDS.join(', ')})`);
38+
if (!KINDS.includes(e.kind)) errors.push(`"kind" must be one of ${KINDS.join(', ')}`);
39+
if (!isStr(e.title)) errors.push('"title" is missing');
40+
if (!strList(e.items)) errors.push('"items" must be a list of one or more sentences');
41+
if ('version' in e) errors.push('leave "version" out: it is filled in when the pull request is merged');
42+
if (e.games !== undefined && !strList(e.games)) errors.push('"games" must be a list of game names');
43+
if (e.kind === 'game' && !e.games) errors.push('a new game needs "games": ["Its Name"] so it shows in "New games!"');
44+
if (e.img !== undefined && !(isStr(e.img) || (strList(e.img) && e.img.length <= 3))) errors.push('"img" must be a path or a list of up to 3');
45+
for (const p of [].concat(e.img || [])) if (!/^[\w./-]+\.(jpe?g|png|webp)$/i.test(p) || p.includes('..')) errors.push(`"img" ${p}: use a plain path inside the Back Room folder, like m/thumbs/<folder>.jpg`);
46+
for (const p of [].concat(e.img || [])) if (/^[\w./-]+$/.test(p) && !p.includes('..') && !fs.existsSync(abs('e63334287a3deaa3/' + p))) warnings.push(`"img" ${p} isn't in the Back Room folder yet`);
47+
if (e.tags !== undefined && !(strList(e.tags) && e.tags.length <= 4)) errors.push('"tags" must be a list of up to 4 words');
48+
if (e.link !== undefined && !(e.link && isStr(e.link.text) && /^\/(?!\/)/.test(e.link.href || ''))) errors.push('"link" must be {"text": "...", "href": "/a-page-on-this-site/"}');
49+
if (e.date !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(e.date)) errors.push('"date" must be YYYY-MM-DD (leave it out to use the merge day)');
50+
if (e.noVersion !== undefined && e.noVersion !== true) errors.push('"noVersion" can only be true');
51+
if (e.es !== undefined && !(e.es && typeof e.es === 'object' && !Array.isArray(e.es) && Object.values(e.es).every(isStr))) errors.push('"es" must be {"English line": "Spanish line", ...}');
52+
if (!errors.length) {
53+
const es = e.es || {};
54+
const lines = [e.title, ...e.items, ...(e.tags || []), ...(e.link ? [e.link.text] : [])];
55+
const missing = lines.filter((l) => !es[l]);
56+
if (missing.length) warnings.push(`no Spanish yet for: ${missing.map((l) => JSON.stringify(l)).join(', ')} (these show in English)`);
57+
for (const k of Object.keys(es)) if (!lines.includes(k)) warnings.push(`"es" has ${JSON.stringify(k)}, which isn't a line of this entry`);
58+
}
59+
return { entry: e, errors, warnings };
60+
}
61+
62+
// ---- versions ----
63+
const parseV = (s) => s.split('.').map(Number);
64+
const cmpV = (a, b) => { for (let i = 0; i < 3; i++) { const d = (a[i] || 0) - (b[i] || 0); if (d) return d; } return 0; };
65+
function latestVersion(src) {
66+
const all = [...src.matchAll(/\bversion:\s*'(\d+(?:\.\d+){1,2})'/g)].map((m) => parseV(m[1]));
67+
if (!all.length) throw new Error(`no versions found in ${NEWS_JS}`);
68+
return all.sort(cmpV).pop();
69+
}
70+
function bump(v, kind) {
71+
// a new game or a big feature bumps the minor number and drops the patch; a fix (or a teaser) bumps the patch
72+
if (kind === 'game' || kind === 'feature') return `${v[0]}.${(v[1] || 0) + 1}`;
73+
return `${v[0]}.${v[1] || 0}.${(v[2] || 0) + 1}`;
74+
}
75+
76+
// ---- writing in news.js's own style ----
77+
const q = (s) => "'" + String(s).replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\r?\n/g, ' ') + "'";
78+
const list = (a) => '[' + a.map(q).join(', ') + ']';
79+
function render(e, date, version) {
80+
let head = `{date: ${q(date)}, ` + (version ? `version: ${q(version)}, ` : '') + `title: ${q(e.title)}, kind: ${q(e.kind)},`;
81+
const extra = [];
82+
if (e.games) extra.push(`games: ${list(e.games)}`);
83+
if (e.img) extra.push(`img: ${Array.isArray(e.img) ? list(e.img) : q(e.img)}`);
84+
if (e.tags) extra.push(`tags: ${list(e.tags)}`);
85+
if (e.link) extra.push(`link: {text: ${q(e.link.text)}, href: ${q(e.link.href)}}`);
86+
extra.push('items: [');
87+
const items = e.items.map((s) => ' ' + q(s)).join(',\n');
88+
return ` ${head}\n ${extra.join(', ')}\n${items}]},\n`;
89+
}
90+
91+
function insertAfter(src, marker, text, file) {
92+
const i = src.indexOf(marker);
93+
if (i < 0) throw new Error(`couldn't find "${marker}" in ${file}`);
94+
const at = src.indexOf('\n', i) + 1;
95+
return src.slice(0, at) + text + src.slice(at);
96+
}
97+
98+
function today() {
99+
return new Intl.DateTimeFormat('en-CA', { timeZone: TZ, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date());
100+
}
101+
102+
function addedAt(file) {
103+
// when the file first reached main, so entries merged in one push keep their merge order
104+
try {
105+
const out = execFileSync('git', ['log', '--diff-filter=A', '--format=%ct', '--', file], { cwd: ROOT, encoding: 'utf8' }).trim().split('\n');
106+
return Number(out[out.length - 1]) || 0;
107+
} catch { return 0; }
108+
}
109+
110+
function pending() {
111+
if (!fs.existsSync(abs(DIR))) return [];
112+
return fs.readdirSync(abs(DIR)).filter((f) => f.endsWith('.json') && !f.startsWith('_')).map((f) => `${DIR}/${f}`);
113+
}
114+
115+
function check(files) {
116+
let bad = 0;
117+
for (const f of files) {
118+
const r = read(f);
119+
for (const w of r.warnings || []) console.log(`::warning file=${f}::${w}`);
120+
for (const er of r.errors) { console.log(`::error file=${f}::${er}`); bad++; }
121+
if (!r.errors.length) console.log(`${f}: OK (${r.entry.kind}: ${r.entry.title})`);
122+
}
123+
return bad;
124+
}
125+
126+
function publish() {
127+
const files = pending().sort((a, b) => addedAt(a) - addedAt(b) || a.localeCompare(b));
128+
if (!files.length) { console.log('No waiting What\'s new entries.'); return []; }
129+
if (check(files)) throw new Error('fix the entries above, then push again');
130+
let js = fs.readFileSync(abs(NEWS_JS), 'utf8');
131+
let es = fs.readFileSync(abs(NEWS_ES), 'utf8');
132+
const done = [];
133+
for (const f of files) {
134+
const e = read(f).entry;
135+
const version = e.noVersion ? null : bump(latestVersion(js), e.kind);
136+
const date = e.date || today();
137+
js = insertAfter(js, 'var NEWS = [', render(e, date, version), NEWS_JS);
138+
const pairs = Object.entries(e.es || {});
139+
if (pairs.length) es = insertAfter(es, 'BackRoomLang.add({', pairs.map(([k, v]) => ` ${JSON.stringify(k)}: ${JSON.stringify(v)},\n`).join(''), NEWS_ES);
140+
done.push({ file: f, version, date, title: e.title });
141+
console.log(`${f} -> ${version || '(no version)'} ${date} ${e.title}`);
142+
}
143+
fs.writeFileSync(abs(NEWS_JS), js);
144+
fs.writeFileSync(abs(NEWS_ES), es);
145+
for (const d of done) fs.unlinkSync(abs(d.file));
146+
const summary = done.map((d) => `${d.version || 'no version'}: ${d.title}`).join('; ');
147+
if (process.env.GITHUB_OUTPUT) fs.appendFileSync(process.env.GITHUB_OUTPUT, `summary<<EOF\n${summary}\nEOF\n`);
148+
return done;
149+
}
150+
151+
const [mode, ...args] = process.argv.slice(2);
152+
try {
153+
if (mode === 'check') process.exit(check(args) ? 1 : 0);
154+
else if (mode === 'publish') publish();
155+
else { console.error('usage: news.js check <file.json>... | news.js publish'); process.exit(2); }
156+
} catch (err) { console.error(`::error::${err.message}`); process.exit(1); }
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# After a pull request with a What's new entry (a file in e63334287a3deaa3/news/) is merged, this gives the entry
2+
# the next version number and today's date (New York time), puts it at the top of NEWS in e63334287a3deaa3/news.js
3+
# with its Spanish in news-es.js, deletes the file and pushes the result to main. That way pull requests never edit
4+
# the same lines of news.js, so they don't conflict with each other there. See e63334287a3deaa3/news/README.md.
5+
name: "What's new: publish"
6+
on:
7+
push:
8+
branches: [main]
9+
paths: ['e63334287a3deaa3/news/*.json']
10+
workflow_dispatch:
11+
permissions:
12+
contents: write
13+
concurrency:
14+
group: whats-new-publish
15+
cancel-in-progress: false
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with: { fetch-depth: 200 }
22+
- name: Publish waiting entries
23+
id: news
24+
env: { NEWS_TZ: America/New_York }
25+
run: node .github/scripts/news.js publish
26+
- name: Push to main
27+
# The titles come from pull requests, so they reach the shell only as an environment variable, never pasted into the script.
28+
env: { SUMMARY: "${{ steps.news.outputs.summary }}" }
29+
run: |
30+
git add -A e63334287a3deaa3
31+
if git diff --cached --quiet; then echo "Nothing to publish."; exit 0; fi
32+
git config user.name "github-actions[bot]"
33+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
34+
git commit -m "What's new: $SUMMARY"
35+
# If something else reached main meanwhile, redo the publish on top of it so versions stay in order.
36+
for i in 1 2 3; do
37+
git push origin HEAD:main && exit 0
38+
git fetch origin main && git reset --hard origin/main
39+
node .github/scripts/news.js publish
40+
git add -A e63334287a3deaa3
41+
git diff --cached --quiet && exit 0
42+
git commit -m "What's new: published waiting entries"
43+
done
44+
exit 1

‎.github/workflows/whats-new.yml‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Every pull request that changes something players can see must add a What's new entry
2-
# (e63334287a3deaa3/news.js) - see CLAUDE.md. Changes to only docs (README, CLAUDE.md, comments in .github) pass
3-
# without one, and a pull request labelled "no-news" skips the check.
1+
# Every pull request that changes something players can see must add a What's new entry as its own file,
2+
# e63334287a3deaa3/news/<name>.json (see e63334287a3deaa3/news/README.md and CLAUDE.md). The entry gets its version
3+
# and date when it is merged (whats-new-publish.yml), so pull requests never edit the same lines of news.js.
4+
# Changes to only docs (README, CLAUDE.md, .github) pass without one, and a pull request labelled "no-news" skips
5+
# the check.
46
name: What's new entry
57
on:
68
pull_request:
@@ -11,17 +13,21 @@ jobs:
1113
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-news') }}
1214
steps:
1315
- uses: actions/checkout@v4
14-
with: { fetch-depth: 0 }
16+
with: { fetch-depth: 0, persist-credentials: false }
1517
- name: Check for a What's new entry
1618
run: |
1719
base="${{ github.event.pull_request.base.sha }}"
1820
files="$(git diff --name-only "$base"...HEAD)"
1921
echo "$files"
2022
visible="$(echo "$files" | grep -vE '^(README\.md|CLAUDE\.md|\.github/)' || true)"
2123
if [ -z "$visible" ]; then echo "Docs only: no entry needed."; exit 0; fi
22-
if echo "$files" | grep -qx 'e63334287a3deaa3/news.js' && git diff "$base"...HEAD -- e63334287a3deaa3/news.js | grep -qE "^\+\s*\{date: '"; then
23-
echo "What's new entry found."
24-
else
25-
echo "::error file=e63334287a3deaa3/news.js::Add an entry to the top of NEWS in e63334287a3deaa3/news.js for this change (see CLAUDE.md), or label the pull request no-news if players can't notice it."
24+
if git diff "$base"...HEAD -- e63334287a3deaa3/news.js | grep -qE "^\+\s*\{date: '"; then
25+
echo "::error file=e63334287a3deaa3/news.js::Don't add entries to news.js directly: it makes open pull requests conflict. Put the entry in its own file in e63334287a3deaa3/news/ instead (see the README there); it is added to news.js with its version and date when this is merged."
2626
exit 1
2727
fi
28+
entries="$(git diff --name-only --diff-filter=AM "$base"...HEAD -- 'e63334287a3deaa3/news/*.json' | grep -v '/_' || true)"
29+
if [ -z "$entries" ]; then
30+
echo "::error::Add a What's new entry for this change as a new file in e63334287a3deaa3/news/ (copy _example.json; see the README there), or label the pull request no-news if players can't notice it."
31+
exit 1
32+
fi
33+
node .github/scripts/news.js check $entries

‎CLAUDE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ When adding a game:
2626
- Don't change Firebase security rules or the Firebase config. If a game needs storage the current rules don't allow, say so in the pull request instead.
2727
- If the game shows ads, follow the existing `AD_SLOT` pattern and leave `AD_SLOT` empty; Arjun fills it in, and load `/adrefresh.js` in the `<head>`. Mark in-game touch buttons that aren't inside `#touch` with `data-no-ad-refresh`, so tapping them during play never reloads an ad.
2828
- Add a section for the game to `README.md`, in the same style as the others: what it is, how it stores data, and anything a later editor needs to know.
29-
- Add a `kind: 'game'` entry for it to What's new (`e63334287a3deaa3/news.js`, with its Spanish in `news-es.js`), with the game in `games` and its phone thumbnail as `img`, so it appears in the "New games!" row.
29+
- Add a `kind: 'game'` What's new entry for it as a new file in `e63334287a3deaa3/news/` (see the README there), with the game in `games`, its phone thumbnail as `img` and its Spanish in `es`, so it appears in the "New games!" row.
3030
- Make it playable on a phone: on-screen touch controls shown only on touch screens (see how Shell Crackers or Kartwheel do it), with nothing overlapping in portrait or with the phone sideways. Then add it to the phone page: a row in `GROUPS` in `e63334287a3deaa3/m/index.html` and a 560 × 350 thumbnail in `e63334287a3deaa3/m/thumbs/`.
3131

3232
## Skills
@@ -36,7 +36,7 @@ When adding a game:
3636
## Rules
3737

3838
- Keep each pull request to one feature or fix, and leave unrelated code alone.
39-
- Every update and pull request adds an entry to the top of `NEWS` in `e63334287a3deaa3/news.js` (the Back Room's What's new strip and its "New games!" row), following the how-to at the top of that file: the merge date, the next version number, `kind` (`game`, `feature` or `fix`), a short title and bullet points written for players. A new game also lists its name in `games` so it shows as a "New games!" chip for a week. Add the Spanish for each new line to `e63334287a3deaa3/news-es.js` too. The only exception is a change players can't notice at all (a README or comment edit); say so in the pull request.
39+
- Every pull request that changes something players will notice adds its What's new entry as **one new file** in `e63334287a3deaa3/news/` (copy `_example.json`; the README there lists the fields): `kind` (`game`, `feature`, `fix` or `soon`), a short title, bullet points written for players, a new game's name in `games` so it shows as a "New games!" chip for a week, and the Spanish for every line in `es`. Don't edit the top of `NEWS` in `news.js` and don't pick a version or date: when the pull request is merged, a workflow gives the entry the next version and the merge date, adds it to `news.js` and `news-es.js`, and deletes the file, so open pull requests never conflict there. The only exception is a change players can't notice at all (a README or comment edit); say so in the pull request and label it `no-news`. (Commits pushed straight to `main` can do the same, or edit `news.js` directly as before, since nothing else is editing it at that moment.)
4040
- Don't change these without saying so clearly in the pull request: `.github/workflows/`, `_redirects`, `_routes.json`, `functions/`, `ads.txt`, `privacy.html`, `robots.txt`, `sitemap.xml`, `account/`, `analytics/`, AdSense code, or Firebase config.
4141
- Never commit secrets, API keys, passwords or private files. `rounds.json` for Hype Cycle Exchange is deliberately kept out of the repo.
4242
- Don't add outside scripts, trackers or ads unless the pull request is specifically about that.

0 commit comments

Comments
 (0)