Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1a057a6
Centralize tool versions and improve build consistency
sean-parent Dec 23, 2025
1b2cc2c
Refactor version parsing for mdbook plugins
cursoragent Dec 23, 2025
ac5697b
Add PR preview deployment and cleanup workflows
sean-parent Dec 23, 2025
ce14abe
Merge branch 'sean-parent/dependency-management' of https://github.co…
sean-parent Dec 23, 2025
6074e3b
Improve gh-pages branch setup in deploy workflow
sean-parent Dec 23, 2025
4b39647
Set upstream when pushing gh-pages branch
sean-parent Dec 23, 2025
dc0b5be
Add Rust toolchain and cargo cache to CI workflow
sean-parent Dec 23, 2025
3025129
Simplify deploy workflow and remove PR preview
sean-parent Dec 23, 2025
38d3733
Improve mdBook install scripts and deploy workflow
sean-parent Dec 23, 2025
fb64c63
Improve cargo install error handling for existing packages
sean-parent Dec 23, 2025
881d415
Simplify cargo install error handling in tool scripts
sean-parent Dec 23, 2025
33da196
Improve version extraction in install-tools.sh
sean-parent Dec 24, 2025
c587f47
Update README.md
sean-parent Dec 24, 2025
f5fdda3
Refactor CI: simplify build, remove PR preview system
sean-parent Dec 24, 2025
0d6b35e
Merge branch 'sean-parent/dependency-management' of https://github.co…
sean-parent Dec 24, 2025
79b706f
Improve POSIX compliance in version extraction
sean-parent Dec 24, 2025
959a88d
Handle mdbook-katex install on Windows with duktape backend
sean-parent Dec 24, 2025
09869f6
Remove complexity comment from install scripts
sean-parent Dec 24, 2025
5ce6442
Migrate tool version management to versions.txt
sean-parent Dec 24, 2025
39cfff9
Fix mdBook plugin installation loop in script
sean-parent Dec 24, 2025
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
16 changes: 9 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Deploy mdBook to GitHub Pages
# Tool versions are managed in versions.toml at the repository root.
# To update mdbook or plugin versions, edit versions.toml and the CI will automatically use them.

on:
# Runs on pushes targeting the default branch
Expand Down Expand Up @@ -26,22 +28,22 @@ jobs:
runs-on: ubuntu-latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to have powershell scripts in here for running on windows, we need to do the build on Windows too, to test them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test.

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Install mdBook
run: cargo install mdbook
- name: Install mdBook and plugins
run: |
chmod +x scripts/install-tools.sh
./scripts/install-tools.sh

- name: Setup Pages
id: pages
uses: actions/configure-pages@v5

- name: Build with mdBook
run: |
cd better-code
mdbook build
run: mdbook build ./better-code

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
uses: actions/upload-pages-artifact@v4
with:
path: ./better-code/book

Expand Down
7 changes: 7 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Tool versions for asdf version manager
# See: https://asdf-vm.com/
#
# Note: For mdbook and plugin versions, see versions.toml
# Use the install scripts in better-code/ to install the correct versions
rust stable

119 changes: 75 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,121 @@ We're migrating from using Jekyll to using
[mdBook](https://github.com/rust-lang/mdBook). The mdBook version is located in
the `./better-code` directory and includes automated CI/CD deployment to GitHub Pages.

## Installing and updating mdBook
The published book is available at: https://stlab.github.io/better-code/

Install [Rust and
Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html):
## Prerequisites

Linux and macOS:
Install [Rust and Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html):

```
**Linux and macOS:**
```bash
curl https://sh.rustup.rs -sSf | sh
```

On Windows, you can download the installer from
[here](https://win.rustup.rs/).
**Windows:**
Download the installer from [here](https://win.rustup.rs/).

Once you have Rust and Cargo installed, you can install or upgrade mdBook by running:
## Installing mdBook and Plugins

```
cargo install mdbook
**Important**: To ensure consistency between local development and CI, all tool
versions are centrally managed in `versions.toml`. Use the provided installation
scripts to automatically install the correct versions:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
cargo install mdbook
**Important**: To ensure consistency between local development and CI, all tool
versions are centrally managed in `versions.toml`. Use the provided installation
scripts to automatically install the correct versions:

This doesn't belong in the installation instructions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed and made a pass to tighten up the README.


**Linux/macOS:**
```bash
./scripts/install-tools.sh
```

## Building the book
**Windows (PowerShell):**
```powershell
.\scripts\install-tools.ps1
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't these steps handled on demand by cargo as part of the build? They are dependencies, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because cargo doesn't auto-install tools as part of cargo build. I went down this path a few different times and failed.


To build the book, run:
These scripts automatically install mdBook and all required plugins using the
versions specified in `versions.toml`. This is the same file used by CI, ensuring
perfect consistency.

**Manual Installation:**
If you prefer to install manually, check `versions.toml` for the current version
numbers, then run:
```bash
cargo install mdbook --version <version-from-toml>
cargo install mdbook-katex --version <version-from-toml>
```

## Building and Serving the Book

To build and serve the book locally with live reload:

```bash
mdbook serve ./better-code
```

Open the browser to http://localhost:3000 to see the book. You can use the
This will start a local server at http://localhost:3000. You can use the
Simple Browser in VSCode/Cursor to view the book while editing.

## Automated Deployment
To build the book without serving:

The mdBook is automatically built and deployed to GitHub Pages using GitHub Actions.
When you push changes to the main branch:
```bash
mdbook build ./better-code
```

1. GitHub Actions will build the book using mdBook
2. The built book will be deployed to GitHub Pages
3. The book will be available at https://stlab.github.io/better-code/
The built book will be in the `./better-code/book/` directory.

No manual deployment steps are required!
## Adding and Editing Content

### Conventions and Guidelines
1. Edit existing chapters in `better-code/src/`
2. Add new chapters by creating new `.md` files in `better-code/src/`
3. Update `better-code/src/SUMMARY.md` to include new chapters in the table of contents
4. The book will automatically rebuild and redeploy when you push changes to the main branch

### Content Conventions

* Avoid unnecessary HTML tags; use Markdown formatting to the degree possible.
* Wrap lines at 80 columns to support diff-friendly change tracking.
* Chapters are represented as individual Markdown files in the chapters/
subdirectory.
* Each chapter begins with a 2nd-level heading, e.g. `## Chapter Name`. All
* Each chapter begins with a 2nd-level heading, e.g. `## Chapter Name`. All
other headings in a chapter are 3rd-level and below.
* Each file's name starts with a 4-digit number that determines its order in the
overall document. Initial numbering is spaced by 100s.
* Maintain stable file names and heading titles for linkability until another
solution is in place.

### Older draft
## Automated Deployment

Please see the [latest published draft](https://stlab.github.io/better-code/)
for information about the motivation for this project.
The mdBook is automatically built and deployed to GitHub Pages using GitHub Actions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems redundant with item 4 above.

When you push changes to the main branch:

### Infrastructure
1. GitHub Actions builds the book using mdBook with versions from `versions.toml`
2. The built book is deployed to GitHub Pages
3. The book becomes available at https://stlab.github.io/better-code/

The book is being migrated from [Jekyll](https://jekyllrb.com) to [mdBook](https://github.com/rust-lang/mdBook).
The new mdBook version is automatically built and deployed to [GitHub Pages](https://pages.github.com) using GitHub Actions.
No manual deployment steps are required!

The legacy Jekyll files remain in the root directory for reference during the transition.
## Dependency Management

### Running a local server
All tool versions (mdBook, plugins, and future tools like Swift) are managed in
`versions.toml` at the repository root. To update a version:

If you are able to install the necessary parts for jekyll,
1. Edit the version number in `versions.toml`
2. Run the appropriate install script to update locally
3. Test your changes
4. Commit - CI will automatically use the new version

```
## Legacy Jekyll Content

The legacy Jekyll files remain in the `archive/` directory for reference during
the transition. You can ignore these unless you're working on the migration.

**Running the Jekyll version (for reference only):**

If you need to run the legacy Jekyll site:

```bash
bundle exec jekyll serve -l
```

will start a server for the site at http://localhost:4000.
This will start a server at http://localhost:4000.

Creating a complete installation of jekyll and all the parts needed for github
pages development can be fraught. If you install
[docker-compose](https://docs.docker.com/compose/), you can start the server
by invoking
Alternatively, if you have [docker-compose](https://docs.docker.com/compose/):

```
```bash
docker-compose up
```

in the root directory of your working copy.
52 changes: 0 additions & 52 deletions better-code/README.md

This file was deleted.

1 change: 0 additions & 1 deletion better-code/book.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[book]
authors = ["Sean Parent"]
language = "en"
multilingual = false
src = "src"
title = "Better Code"
description = "A principled and rigorous approach to software development"
Expand Down
76 changes: 76 additions & 0 deletions scripts/install-tools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Install mdBook and plugins using versions from ../versions.toml
# This ensures consistency between local development and CI

$ErrorActionPreference = "Stop"

$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$VersionsFile = Join-Path (Split-Path -Parent $ScriptDir) "versions.toml"

# Function to parse TOML and extract version
Copy link
Collaborator

@dabrahams dabrahams Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contract documentation in this file is nonexistent or not up to snuff.

function Get-ToolVersion {
param (
[string]$Tool,
[string]$Section = ""
)

$content = Get-Content $VersionsFile -Raw

if ($Section) {
# Extract from section like [mdbook-plugins]
$pattern = "(?ms)\[$Section\].*?$Tool\s*=\s*`"([^`"]+)`""
} else {
# Extract from top-level section like [mdbook]
$pattern = "(?ms)\[$Tool\].*?version\s*=\s*`"([^`"]+)`""
}

if ($content -match $pattern) {
return $Matches[1]
}
return $null
}

# Function to get all plugins from [mdbook-plugins] section
function Get-MdbookPlugins {
$content = Get-Content $VersionsFile -Raw
$plugins = @{}

if ($content -match '(?ms)\[mdbook-plugins\](.*?)(\[|$)') {
$section = $Matches[1]
$lines = $section -split "`n"

foreach ($line in $lines) {
if ($line -match '^([a-zA-Z0-9_-]+)\s*=\s*"([^"]+)"') {
$plugins[$Matches[1]] = $Matches[2]
}
}
}

return $plugins
}

Write-Host "Reading versions from $VersionsFile..." -ForegroundColor Cyan

# Install mdBook
$MdbookVersion = Get-ToolVersion -Tool "mdbook"
if ($MdbookVersion) {
Write-Host "`nInstalling mdBook $MdbookVersion..." -ForegroundColor Cyan
cargo install mdbook --version $MdbookVersion
} else {
Write-Host "Error: Could not find mdbook version in versions.toml" -ForegroundColor Red
exit 1
}

# Install mdBook plugins
Write-Host "`nInstalling mdBook plugins..." -ForegroundColor Cyan

$plugins = Get-MdbookPlugins
foreach ($plugin in $plugins.GetEnumerator()) {
Write-Host "Installing $($plugin.Key) $($plugin.Value)..." -ForegroundColor Cyan
cargo install $plugin.Key --version $plugin.Value
}

Write-Host "`n✓ Installation complete!" -ForegroundColor Green
Write-Host "`nInstalled versions:" -ForegroundColor Cyan
mdbook --version
cargo install --list | Select-String "mdbook"

Loading