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
11 changes: 6 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!--
Title: (<type>) <Sentence-case summary>, for example "(feat) Add the Warp tool for closing gaps".
Types: feat, fix, perf, docs, refactor, test, build, ci, chore. Add ! after the type, as in
"(feat!)", for a breaking change.
-->

## Summary

-

## Testing

-

## Release notes

- [ ] Added a release to `src/docs/changelog.ts` describing what changed for users
- [ ] Bumped the version with `npm version minor --no-git-tag-version` (features) or `patch` (fixes), matching the new release
17 changes: 0 additions & 17 deletions .github/workflows/changelog.yml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Pull request

on:
pull_request:
branches: [main]
types: [opened, edited, reopened, synchronize]

jobs:
format:
name: Title and description
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node scripts/check-pull-request.mjs

build:
name: Type check and build
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Contributing

Pull requests to `main` must pass the **Pull request** checks: the title, the
description, and a type check and build.

## Title

Start the title with a type in parentheses, then a space and a sentence-case summary
with no period:

```text
(feat) Add the Warp tool for closing gaps in scanned parts
(fix) Keep Drive connected after a reload
```

| Type | Use for |
| ---------- | ----------------------------------- |
| `feat` | A new feature |
| `fix` | A bug fix |
| `perf` | A performance improvement |
| `docs` | Documentation only |
| `refactor` | Code changes with the same behavior |
| `test` | Tests only |
| `build` | Build, dependencies, or tooling |
| `ci` | Continuous integration |
| `chore` | Other maintenance |

Add `!` after the type, as in `(feat!)`, for a breaking change.

## Description

Use the [pull request template](.github/pull_request_template.md). The description
starts with these sections, in this order:

1. `## Summary`: bullets describing what changed and why.
2. `## Testing`: what you ran and what passed, plus anything not tested.

You can add other sections, such as a review log, after the summary.

## Version and release notes

The app's version is the short hash of the commit it was built from, as GitHub shows
it. Pull requests do not change a version number.

To tell people about a change, add an entry at the top of `src/docs/changelog.ts`. It
appears on the documentation's What's new page and in the workbench's What's new
button with the commit it shipped in, which the build fills in. Entries are optional.
See
[maintaining the documentation](docs/documentation.md#whats-new).

## Check locally

```sh
npm run build
PR_TITLE="(feat) Add pins" PR_BODY_FILE=body.md node scripts/check-pull-request.mjs
```
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,10 @@ See [design specification](docs/design.md) and [verification notes](docs/verific

## Contributing

Every pull request must add a release to the documentation's **What's new** page.
Bump the version with `npm version minor --no-git-tag-version` for features or
`patch` for fixes, then add a release with the same version at the top of
`src/docs/changelog.ts` describing what changed for users. The Changelog check on
pull requests fails until both are done. See
[maintaining the documentation](docs/documentation.md#whats-new).
Pull request titles start with a type in parentheses, such as `(feat)` or `(fix)`,
and descriptions follow the template's Summary and Testing sections. Checks on pull
requests enforce both and make sure the app type-checks and builds. The app's version
is the short hash of the commit it was built from. See [CONTRIBUTING.md](CONTRIBUTING.md).

## License

Expand Down
34 changes: 16 additions & 18 deletions docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,24 @@ client-side navigation enhancement.

## What's new

`src/docs/changelog.ts` lists every version, newest first, and renders at
`?guide=whats-new`. The sidebar and the overview link to the newest release. The
workbench header's What's new button shows the three newest releases and marks
one the visitor hasn't opened yet.

Every pull request adds one release at the top of the list:

1. Run `npm version minor --no-git-tag-version` for a new feature, or `patch` for
a fix or small improvement. This updates `package.json` and `package-lock.json`.
2. Add a release with the same `version`, today's `date`, a short `title`, and one
entry per user-visible change. Mark each `new`, `improved`, or `fixed`, and set
`guide` to an article ID to link to it.
`src/docs/changelog.ts` lists releases, newest first, and renders at
`?guide=whats-new`. Each release shows the short hash of the commit it shipped in, so a
bug report can name the build. The sidebar shows the commit the documentation was
built from, and the overview links to the newest release. The workbench header's
What's new button shows the three newest releases and marks one the visitor hasn't
opened yet.

Entries are optional; add one when a change is worth telling people about. Put it at
the top of the list with today's `date`, a short, unique `title` (it becomes the
release's link), and one entry per user-visible change. Mark each `new`, `improved`,
or `fixed`, and set `guide` to an article ID to link to it. Leave out `commit`: the
build reads git history (`scripts/release-commits.mjs`) and shows the commit that
added the entry, which is the merge on `main`. Set `commit` only when the change
shipped in an earlier commit than its entry.

Write for people using Kitbasher, not for reviewers: what they can now do, or what
works differently. The Changelog workflow runs `scripts/check-changelog.mjs`, which
fails a pull request that leaves the changelog untouched, does not raise the
version above `main`, or lets `package.json`, `package-lock.json`, and the newest
release disagree. `tests/unit/changelog.test.ts` checks ordering, dates, and guide
links. If two open pull requests take the same version, the one merged second must
move to the next version.
works differently. `tests/unit/changelog.test.ts` checks ordering, dates, unique
titles, commits, and guide links.

## Images

Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "kitbasher",
"version": "1.18.1",
"description": "A local-first 3D assembly workbench for multipart models",
"scripts": {
"dev": "vite",
Expand Down
54 changes: 0 additions & 54 deletions scripts/check-changelog.mjs

This file was deleted.

22 changes: 22 additions & 0 deletions scripts/check-pull-request.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readFileSync } from 'node:fs';
import { checkBody, checkTitle, pullRequestTypes } from './pull-request-rules.mjs';

const event = process.env.GITHUB_EVENT_PATH
? JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')).pull_request
: undefined;
const title = process.env.PR_TITLE ?? event?.title ?? '';
const body = process.env.PR_BODY_FILE
? readFileSync(process.env.PR_BODY_FILE, 'utf8')
: (process.env.PR_BODY ?? event?.body ?? '');

const failures = [...checkTitle(title), ...checkBody(body)];
if (failures.length) {
console.error(`Pull request format check failed:\n- ${failures.join('\n- ')}`);
console.error(
`\nTitle types:\n${Object.entries(pullRequestTypes)
.map(([type, { label }]) => ` ${type}: ${label}`)
.join('\n')}\nSee CONTRIBUTING.md and .github/pull_request_template.md.`,
);
process.exit(1);
}
console.log(`Pull request format is valid: ${title}`);
7 changes: 7 additions & 0 deletions scripts/pull-request-rules.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const pullRequestTypes: Record<string, { label: string }>;
export const requiredSections: string[];
export function parseTitle(
title: string,
): { type: string; breaking: boolean; subject: string } | undefined;
export function checkTitle(title: string): string[];
export function checkBody(body: string | null | undefined): string[];
67 changes: 67 additions & 0 deletions scripts/pull-request-rules.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
export const pullRequestTypes = {
feat: { label: 'New feature' },
fix: { label: 'Bug fix' },
perf: { label: 'Performance' },
docs: { label: 'Documentation' },
refactor: { label: 'Refactor with no change in behavior' },
test: { label: 'Tests only' },
build: { label: 'Build, dependencies, or tooling' },
ci: { label: 'Continuous integration' },
chore: { label: 'Maintenance' },
};

export const requiredSections = ['Summary', 'Testing'];

const titlePattern = new RegExp(`^\\((${Object.keys(pullRequestTypes).join('|')})(!)?\\) (.+)$`);

export function parseTitle(title) {
const match = title.trim().match(titlePattern);
return match ? { type: match[1], breaking: !!match[2], subject: match[3] } : undefined;
}

export function checkTitle(title) {
const parsed = parseTitle(title);
if (!parsed)
return [
`Start the title with a type in parentheses, such as "(feat) Add the Warp tool". Types: ${Object.keys(pullRequestTypes).join(', ')}.`,
];
const failures = [];
if (!/^[A-Z]/.test(parsed.subject))
failures.push('Start the title after the type with a capital letter.');
if (/[.\s]$/.test(parsed.subject)) failures.push('End the title without a period or space.');
if (title.trim().length > 80) failures.push('Keep the title to 80 characters or fewer.');
return failures;
}

const meaningful = (text) =>
text
.split('\n')
.map((line) => line.replace(/^\s*(?:[-*]|\d+\.)\s*/, '').trim())
.some(Boolean);

export function checkBody(body) {
const text = (body ?? '').replace(/<!--[\s\S]*?-->/g, '').replace(/\r\n/g, '\n');
const sections = [...text.matchAll(/^## +(.+?)\s*$/gm)].map((match, i, all) => ({
title: match[1],
content: text.slice(match.index + match[0].length, all[i + 1]?.index ?? text.length),
}));
const found = sections.map((section) => section.title);
const failures = [];
const positions = requiredSections.map((title) => found.indexOf(title));
for (const [i, title] of requiredSections.entries())
if (positions[i] < 0) failures.push(`Add a "## ${title}" section.`);
if (
positions.every((position) => position >= 0) &&
positions.some((p, i) => i && p < positions[i - 1])
)
failures.push(
`Order the sections ${requiredSections.map((title) => `"${title}"`).join(', ')}.`,
);
if (found[0] !== undefined && found[0] !== 'Summary')
failures.push('Start the description with the "## Summary" section.');
const content = (title) => sections.find((section) => section.title === title)?.content ?? '';
for (const title of ['Summary', 'Testing'])
if (found.includes(title) && !meaningful(content(title)))
failures.push(`Fill in the "${title}" section.`);
return failures;
}
2 changes: 2 additions & 0 deletions scripts/release-commits.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export function firstCommits(log: string): Record<string, string>;
export function releaseCommits(path?: string): Record<string, string>;
37 changes: 37 additions & 0 deletions scripts/release-commits.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { execFileSync } from 'node:child_process';

const git = (...args) =>
execFileSync('git', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();

/** From `git log --reverse --format=%x00%h -p` output, the first commit that added each release title. */
export function firstCommits(log) {
const found = {};
let commit;
for (const line of log.split('\n')) {
// A NUL marks each commit; no diff line can start with one.
if (line.startsWith('\0')) commit = line.slice(1);
else {
const title = line.match(/^\+ {4}title: '(.*)',$/)?.[1];
if (title && commit && !(title in found)) found[title] = commit;
}
}
return found;
}

/** The short hash of the commit that added each release title to the changelog. */
export function releaseCommits(path = 'src/docs/changelog.ts') {
try {
// Builds that clone only the latest commit fetch the rest; the repository is public.
if (git('rev-parse', '--is-shallow-repository') === 'true')
git('fetch', '--unshallow', '--quiet');
} catch {
// Without history, releases that name no commit show none.
}
try {
return firstCommits(
git('log', '--reverse', '--abbrev=7', '--format=%x00%h', '-p', '-U0', '--', path),
);
} catch {
return {};
}
}
Loading
Loading