From b2438240635fb782acc3d6e5aecc4369dbb6e58e Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 15:34:47 +1300 Subject: [PATCH] Case studies: a draft of Bootstrap's conversion, built by the dev server only A caseStudies collection and a /case-studies// route. A study with draft: true is built by the dev server only, so a production build never publishes it. The Bootstrap study is the template: what the project's CI runs, the whole config (tested by docs_examples, which now reads the case studies too), the replay estimate with its method and assumptions, what the conversion found, and what modules would change. --- docs/README.md | 10 +- docs/src/content.config.ts | 18 +- docs/src/content/case-studies/bootstrap.md | 381 +++++++++++++++++++++ docs/src/pages/case-studies/[slug].astro | 35 ++ docs/src/styles/docs.css | 6 + internal_docs/STATUS.md | 5 +- tests/docs_examples.rs | 4 +- 7 files changed, 452 insertions(+), 7 deletions(-) create mode 100644 docs/src/content/case-studies/bootstrap.md create mode 100644 docs/src/pages/case-studies/[slug].astro diff --git a/docs/README.md b/docs/README.md index c30ba62..edd53e2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,13 +11,17 @@ pnpm --dir docs build # writes docs/dist - **Docs pages** are plain Markdown in `src/content/docs/`. Their order and sections are in `src/lib/docs.ts`; the build fails if a page is missing there or listed but missing. +- **Case studies** are Markdown in `src/content/case-studies/`, one per converted project, served at + `/case-studies//`. A study with `draft: true` is built by the dev server only, so `pnpm --dir docs build` never + publishes it. `bootstrap.md` is the first, and the template for the rest: what the project's CI runs, the whole + config, the replay estimate with its method and assumptions, what the conversion found, and what modules would change. - **Every page is also served as Markdown** at `/docs/.md`, and `/llms.txt`, `/llms-full.txt` and `/install.md` are generated from the same files (`src/pages/`). - **`/install.sh`** is the repository's root `install.sh`, copied at build time (`src/lib/install-script.mjs`). Never add a second copy in `public/`. -- **YAML examples are tested.** `tests/docs_examples.rs` runs every YAML block in the docs and the README through - `cigen generate`. Each block's first line says what it is: `# cigen.yml`, `# .cigen/`, `# fragment` or - `# generated: `. A second line `# error: ` means the example must fail with that text. The homepage's +- **YAML examples are tested.** `tests/docs_examples.rs` runs every YAML block in the docs, the case studies and the + README through `cigen generate`. Each block's first line says what it is: `# cigen.yml`, `# .cigen/`, + `# fragment` or `# generated: `. A second line `# error: ` means the example must fail with that text. The homepage's config is `src/examples/home.cigen.yml`, tested the same way. - **The homepage** is `src/pages/index.astro`, with its content in `src/lib/home.ts`. Design tokens are in `src/styles/tokens.css`; colours and fonts are always referenced through them. diff --git a/docs/src/content.config.ts b/docs/src/content.config.ts index 08f70ae..f8f0f6b 100644 --- a/docs/src/content.config.ts +++ b/docs/src/content.config.ts @@ -10,4 +10,20 @@ const docs = defineCollection({ }), }); -export const collections = { docs }; +/** Real projects converted to cigen. A draft is built only by the dev server, never deployed. */ +const caseStudies = defineCollection({ + loader: glob({ pattern: "**/*.md", base: "./src/content/case-studies" }), + schema: z.object({ + title: z.string(), + description: z.string(), + /** The project, as `owner/name`. */ + project: z.string(), + repository: z.string().url(), + /** The full commit the conversion was written against. */ + commit: z.string().regex(/^[0-9a-f]{40}$/), + studied: z.coerce.date(), + draft: z.boolean(), + }), +}); + +export const collections = { docs, caseStudies }; diff --git a/docs/src/content/case-studies/bootstrap.md b/docs/src/content/case-studies/bootstrap.md new file mode 100644 index 0000000..da540f9 --- /dev/null +++ b/docs/src/content/case-studies/bootstrap.md @@ -0,0 +1,381 @@ +--- +title: Bootstrap +description: Bootstrap's seven push and pull-request workflows as one cigen config, and an estimate from its last 100 commits of how many job runs cigen would have skipped. +project: twbs/bootstrap +repository: https://github.com/twbs/bootstrap +commit: c9a2cbf109604d0c4e9b293b487d1d255b50ffa6 +studied: 2026-12-04 +draft: true +--- + + + +Bootstrap is a CSS and JavaScript framework with a busy main branch: 100 first-parent commits between 30 October and +1 December 2026. Its CI runs seven workflows on every push and pull request. We converted those seven to one cigen +config without changing Bootstrap, then replayed its last 100 commits to estimate what cigen would have skipped. + +**The estimate: 245 of 700 job runs skipped (35%).** It's an estimate from git history, not a measurement of real CI, +and the method and its limits are below. + +## The project's CI + +Bootstrap has 15 workflow files. Seven run on every push to `main` and on every pull request, and those are the ones +skipping can help: + +| Workflow | Job | What it does | +| ----------- | ----------- | ----------------------------------------------------------------------- | +| Bundlewatch | bundlewatch | Builds `dist/` and reports bundle sizes to bundlewatch | +| CodeQL | analyze | GitHub's code scanning over the JavaScript | +| cspell | cspell | Spell-checks Markdown, YAML, JSON and scripts | +| CSS | css | Builds the CSS, runs its tests, and tests the grid in three browsers | +| Docs | docs | Builds the docs site and validates its HTML | +| JS Tests | run | Builds the JavaScript, runs its tests in Chromium, uploads coverage | +| Lint | lint | `npm run lint`: JavaScript, TypeScript, SCSS, Markdown and the lockfile | + +The other eight publish releases, run on a schedule, react to issues, run only for image changes in pull requests, or +deploy the docs by hand. None of them run on every push, so they stay as they are. + +## The conversion + +The whole config, written by reading `.github/workflows/` at the commit above: + +```yaml +# cigen.yml +provider: github + +input_groups: + # What every npm-based job depends on beyond its own sources. package-lock.json and .nvmrc are + # derived by cigen (lockfile, toolchain pin); package.json isn't, but its `scripts` define what + # `npm run x` does, so it's declared. + npm: ['package.json'] + build_scripts: ['build/**'] + css_sources: + ['scss/**', '.browserslistrc', 'stylelint.config.mjs', '.stylelintignore'] + js_sources: ['js/**', '/tsconfig.json', '.browserslistrc'] + docs_sources: ['site/**', '/config.yml', 'pagefind.yml', 'dist/**'] + +commands: + setup_node: + description: Node from .nvmrc with the npm cache, then npm ci + steps: + - name: Set up Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: '.nvmrc' + cache: npm + - name: Install npm dependencies + run: npm ci + +workflows: + bundlewatch: + github: + name: Bundlewatch + on: + push: { branches: [main] } + pull_request: {} + workflow_dispatch: {} + env: { FORCE_COLOR: 2 } + permissions: { contents: read } + jobs: + bundlewatch: + image: ubuntu-latest + checkout: { persist-credentials: false } + inputs: + [ + '@npm', + '@build_scripts', + '@css_sources', + '@js_sources', + '.bundlewatch.config.json', + ] + steps: + - setup_node + - name: Run dist + run: npm run dist + - name: Run bundlewatch + run: npm run bundlewatch + env: + BUNDLEWATCH_GITHUB_TOKEN: '${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}' + CI_BRANCH_BASE: main + + codeql: + github: + name: CodeQL + on: + push: { branches: [main, v4-dev, '!dependabot/**'] } + pull_request: { branches: [main, v4-dev, '!dependabot/**'] } + schedule: [{ cron: '0 2 * * 4' }] + workflow_dispatch: {} + jobs: + analyze: + image: ubuntu-latest + checkout: { persist-credentials: false } + # CodeQL analyses the repository's JavaScript, minus the paths-ignore in its config. + inputs: ['*.js', '*.mjs', '*.cjs', '*.ts', '.github/codeql/**'] + github: + name: Analyze + permissions: { security-events: write } + steps: + - name: Initialize CodeQL + uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4 + with: + config-file: ./.github/codeql/codeql-config.yml + languages: javascript + queries: +security-and-quality + - name: Autobuild + uses: github/codeql-action/autobuild@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4 + with: + category: '/language:javascript' + + cspell: + github: + name: cspell + on: + push: { branches: [main] } + pull_request: {} + workflow_dispatch: {} + env: { FORCE_COLOR: 2 } + permissions: { contents: read } + jobs: + cspell: + image: ubuntu-latest + checkout: { persist-credentials: false } + # The files cspell checks. A glob with no `/` matches at any depth. + inputs: + - '.gitignore' + - '.cspell.json' + - '*.md' + - '*.mdx' + - '*.yml' + - '*.yaml' + - '*.json' + - '*.js' + - '*.cjs' + - '*.mjs' + - '*.ts' + github: + permissions: { contents: read, pull-requests: read } + steps: + - name: Run cspell + uses: streetsidesoftware/cspell-action@ce1816e4ce36532956ac6e983737392774b6e169 # v9.2.0 + with: + config: '.cspell.json' + files: | + .gitignore + **/*.{md,mdx,yml,yaml,json,js,cjs,mjs,ts} + inline: error + incremental_files_only: false + + css: + github: + name: CSS + on: + push: { branches: [main] } + pull_request: {} + workflow_dispatch: {} + env: { FORCE_COLOR: 2 } + permissions: { contents: read } + jobs: + css: + image: ubuntu-latest + checkout: { persist-credentials: false } + inputs: ['@npm', '@build_scripts', '@css_sources'] + steps: + - setup_node + - name: Build CSS + run: npm run css + - name: Run CSS tests + run: npm run css-test + - name: Install grid test browsers + run: npx playwright install --with-deps chromium firefox webkit + - name: Test grid layout in Chromium, Firefox, and WebKit + run: | + npm run css-test-grid + GRID_TEST_BROWSER=firefox npm run css-test-grid + GRID_TEST_BROWSER=webkit npm run css-test-grid + + docs: + github: + name: Docs + on: + push: { branches: [main] } + pull_request: {} + workflow_dispatch: {} + env: { FORCE_COLOR: 2 } + permissions: { contents: read } + jobs: + docs: + image: ubuntu-latest + checkout: { persist-credentials: false } + inputs: + [ + '@npm', + '@build_scripts', + '@css_sources', + '@js_sources', + '@docs_sources', + ] + steps: + - setup_node + - name: Generate utilities metadata + run: npm run css-docs + - name: Build docs + run: npm run docs-build + - name: Validate HTML + run: npm run docs-html-validate + + js: + github: + name: JS Tests + on: + push: { branches: [main] } + pull_request: {} + workflow_dispatch: {} + env: { FORCE_COLOR: 2 } + permissions: { contents: read } + jobs: + run: + image: ubuntu-latest + checkout: { persist-credentials: false } + inputs: ['@npm', '@build_scripts', '@js_sources'] + github: + name: JS Tests + permissions: { checks: write, contents: read } + steps: + - setup_node + - name: Install Playwright Chromium + run: npx playwright install --with-deps chromium + - name: Run dist + run: npm run js + - name: Run JS tests + run: npm run js-test + - name: Run Coveralls + uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8 + if: ${{ !github.event.repository.fork }} + with: + github-token: '${{ secrets.GITHUB_TOKEN }}' + path-to-lcov: './js/coverage/lcov.info' + + lint: + github: + name: Lint + on: + push: { branches: [main] } + pull_request: {} + workflow_dispatch: {} + env: { FORCE_COLOR: 2 } + permissions: { contents: read } + jobs: + lint: + image: ubuntu-latest + checkout: { persist-credentials: false } + # `npm run lint` covers JS, TS, SCSS, the docs site, Markdown and the lockfile: nearly + # the whole repository. Only .github/ changes can't affect it. + inputs: + - '@npm' + - '@build_scripts' + - '@css_sources' + - '@js_sources' + - '@docs_sources' + - 'skills/**' + - '*.md' + - '*.js' + - '*.json' + - '.markdownlint.json' + - '.prettierignore' + - '.editorconfig' + steps: + - setup_node + - name: Lint + run: npm run lint +``` + +How to read it: + +- **Inputs are the files each job's result depends on.** The five input groups at the top are shared between jobs. + cigen adds what it finds for itself: `package-lock.json` and `.nvmrc`, the `setup_node` command each job uses, and + each job's own definition. +- **A glob with no `/` matches at any depth**, as in gitignore, so `*.md` is every Markdown file. `/tsconfig.json` + is the root one only; Bootstrap also has `site/tsconfig.json`, which the docs job already covers through `site/**`. +- **Each workflow keeps its triggers and settings in a `github:` block.** cigen has no triggers of its own yet, so + the branch filters, `schedule` and `workflow_dispatch` are written as GitHub YAML. +- **`setup_node` is a cigen command**: Node from `.nvmrc` with npm's cache, then `npm ci`, shared by five jobs. + +Every action the config names stays pinned to the commit SHA Bootstrap pins. The checkout and cache actions cigen +generates aren't pinned yet ([#32](https://github.com/DocSpring/cigen/issues/32)). + +## The estimate + +`cigen replay` walks the last 100 first-parent commits of `main`, computes each job's hash at every commit with the +config above, and counts a job as skipped when that hash already ran on an earlier commit of the replay. + +| Job (workflow) | Ran | Skipped | Skip rate | +| ------------------ | --- | ------- | --------- | +| analyze (CodeQL) | 36 | 64 | 64% | +| run (JS Tests) | 37 | 63 | 63% | +| css | 53 | 47 | 47% | +| bundlewatch | 67 | 33 | 33% | +| cspell | 78 | 22 | 22% | +| docs | 91 | 9 | 9% | +| lint | 93 | 7 | 7% | +| **All seven jobs** | 455 | 245 | **35%** | + +The skips land where the jobs are narrow. CodeQL and the JavaScript tests skip every commit that only touches the docs +site or the SCSS. The docs build and lint skip rarely: of the 100 commits, 56 touched `site/`, 42 `scss/`, 25 `js/` +and 12 `package.json` or the lockfile, and docs depends on all of those while lint reads nearly the whole repository. + +### What the estimate assumes + +- **Every run passed.** A real failure means the next commit runs the job again, so real CI would skip a little less. +- **One branch.** Only `main`'s first-parent history is replayed. Pull requests aren't modelled; in CI they can reuse + the passes `main` records, so this undercounts their skips. +- **Triggers aren't modelled.** Every workflow is replayed on every commit. That matches Bootstrap here: all seven run + on every push to `main`. +- **A pass expires after 7 days unused**, as GitHub's cache evicts it, measured by commit dates. Turning expiry off + gives the same numbers: Bootstrap commits often enough that a pass is never idle for 7 days. +- **No minutes.** Without each job's average duration there's no figure for time saved. + +To run it yourself, clone Bootstrap, save the config above as `cigen.yml` outside the clone, and run: + +```sh +cigen replay --config path/to/cigen.yml --repo path/to/bootstrap --last 100 +``` + +## What the conversion found + +Converting a real project found two bugs in cigen, both fixed before this page: + +- **Globs missed root files** ([#28](https://github.com/DocSpring/cigen/pull/28)). cspell's inputs were first + written as `**/*.md`, to match cspell's own glob, and the hashed file list had no `README.md`. A commit that only + fixed a typo in the README would have skipped cspell: a false skip, the worst bug cigen can have. cigen now matches + globs with gitignore's rules. +- **Container jobs hashed the wrong files** (also #28). In a container job the checkout belongs to another user, git + refused to list files, and cigen silently fell back to every file on disk. It now tells git to trust the checkout. +- **`package.json` wasn't an input.** `npm run x` runs whatever `package.json`'s scripts say, so changing a script + should run the job. The config declares it by hand (`@npm`); cigen now adds every `package.json` itself. + +And gaps, filed as issues: + +- [#32](https://github.com/DocSpring/cigen/issues/32): the generated checkout and cache actions use version tags. + Bootstrap pins every action to a commit SHA, and cigen gives it no way to pin these two. +- [#33](https://github.com/DocSpring/cigen/issues/33): `# v7.1.0` comments after pinned SHAs are dropped, and + Dependabot reads them to update the pins. +- [#34](https://github.com/DocSpring/cigen/issues/34): every job gets a step that only runs under `act`, for local + testing. +- [#35](https://github.com/DocSpring/cigen/issues/35): bundlewatch reports sizes to a service, and the JS job uploads + coverage to Coveralls. A skipped run reports nothing, so those services see a gap for that commit. +- [#36](https://github.com/DocSpring/cigen/issues/36): triggers have to be written as GitHub YAML. + +## What modules would change + +A `node` module would replace the `setup_node` command and the npm cache, and a `playwright` module the browser +installs in the CSS and JS jobs, with the browsers cached by Playwright's version. Each job would come down to its +inputs and two or three `npm run` steps. Both modules are in progress. diff --git a/docs/src/pages/case-studies/[slug].astro b/docs/src/pages/case-studies/[slug].astro new file mode 100644 index 0000000..92ef68a --- /dev/null +++ b/docs/src/pages/case-studies/[slug].astro @@ -0,0 +1,35 @@ +--- +import { getCollection, render } from 'astro:content'; +import Base from '../../layouts/Base.astro'; +import '../../styles/docs.css'; + +// Drafts are built by the dev server only, so `astro build` never publishes one. +export async function getStaticPaths() { + const studies = await getCollection('caseStudies', (study) => import.meta.env.DEV || !study.data.draft); + return studies.map((study) => ({ params: { slug: study.id }, props: { study } })); +} + +const { study } = Astro.props; +const { Content } = await render(study); +const { title, description, project, repository, commit, studied, draft } = study.data; +--- + + +
+
+
+ {draft &&

Draft: built by the dev server only

} +

{title}

+

{description}

+

+ {project} + at {commit.slice(0, 9)} + {studied.toISOString().slice(0, 10)} +

+
+
+ +
+
+
+ diff --git a/docs/src/styles/docs.css b/docs/src/styles/docs.css index f640205..43a915e 100644 --- a/docs/src/styles/docs.css +++ b/docs/src/styles/docs.css @@ -293,3 +293,9 @@ grid-column: 1; } } + +/* A page without the docs menu or contents, such as a case study. */ +.docs--single { + grid-template-columns: minmax(0, 48rem); + justify-content: center; +} diff --git a/internal_docs/STATUS.md b/internal_docs/STATUS.md index 15850d0..110acc1 100644 --- a/internal_docs/STATUS.md +++ b/internal_docs/STATUS.md @@ -127,8 +127,9 @@ What the code does today, checked against the code in December 2026. Where cigen - `tests/derived_inputs.rs`: changing a script a step runs, a command the job uses or a toolchain pin makes the job run in mockci, and changing a used command, a named service, a top-level provider block, a local action, a lockfile or the `packageManager` pin changes the job's hash; an unused command or service doesn't. -- `tests/docs_examples.rs`: every YAML example in the docs (`docs/src/content/docs/`) and the README, and the homepage's - config, is run through `cigen generate`; examples of errors must fail with the error they show. +- `tests/docs_examples.rs`: every YAML example in the docs (`docs/src/content/docs/`), the case studies + (`docs/src/content/case-studies/`, drafts included) and the README, and the homepage's config, is run through + `cigen generate`; examples of errors must fail with the error they show. - `tests/module_scenarios.rs`: a job using the `rust` module installs nothing when it skips, and reruns in mockci when a file the module contributes or its parameters change; the generated `--modules-digest` changes the hash; unknown modules and parameters fail generation with a fix. diff --git a/tests/docs_examples.rs b/tests/docs_examples.rs index 65995b0..a346825 100644 --- a/tests/docs_examples.rs +++ b/tests/docs_examples.rs @@ -1,4 +1,4 @@ -//! Every YAML example in the docs and the README must do what the docs say: a config loads and +//! Every YAML example in the docs, the case studies and the README must do what the docs say: a config loads and //! generates, an example of an error fails with that error. So the docs can't drift from the //! schema. How a block says what it is: `tests/support/doc_examples.rs`. The site's own example //! configs (`docs/src/examples/*.yml`, shown on the homepage) must generate too. @@ -8,12 +8,14 @@ mod support; use support::doc_examples::{Example, examples_in, markdown_files}; const DOCS_DIR: &str = "docs/src/content/docs"; +const CASE_STUDIES_DIR: &str = "docs/src/content/case-studies"; const SITE_EXAMPLES_DIR: &str = "docs/src/examples"; fn pages() -> Vec<(String, String)> { let root = support::repo_root(); let mut files = markdown_files(&root.join(DOCS_DIR)); assert!(!files.is_empty(), "no docs found in {DOCS_DIR}"); + files.extend(markdown_files(&root.join(CASE_STUDIES_DIR))); files.push(root.join("README.md")); files .into_iter()