Skip to content
Open
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
15 changes: 9 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6

# Cache Rust toolchain and cargo registry
- name: Cache Rust
uses: actions/cache@v4
Expand All @@ -36,24 +36,27 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('versions.txt') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Install mdBook and plugins (Linux)
if: runner.os != 'Windows'
run: |
chmod +x scripts/install-tools.sh
./scripts/install-tools.sh

- name: Install mdBook and plugins (Windows)
if: runner.os == 'Windows'
run: .\scripts\install-tools.ps1


# Install Swift for testing Swift code examples in the book
- name: Setup Swift
uses: swift-actions/setup-swift@v3

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

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: mdbook-build-${{ matrix.os }}
path: ./better-code/book
retention-days: 1

11 changes: 11 additions & 0 deletions better-code/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ description = "A principled and rigorous approach to software development"
[build]
build-dir = "book"

# Preprocessor to hide `# ` lines in Swift code blocks (like mdbook does for Rust)
# Only strips lines for HTML output; swift-test backend sees the full code
[preprocessor.swift-hidden]
command = "python3 scripts/mdbook-swift-hidden.py"
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the built-in mdbook support?

[output.html.code.hidelines]
swift = "#"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Swift has # directives so might need a different character

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems to work! Huge simplification, thanks for pointing that out.


[output.html]
git-repository-url = "https://github.com/stlab/better-code"
edit-url-template = "https://github.com/stlab/better-code/edit/main/better-code/src/{path}"
Expand All @@ -19,3 +24,9 @@ enable = true

[output.html.print]
enable = true

# Swift code example testing backend
Copy link
Collaborator

Choose a reason for hiding this comment

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

This line isn't adding anything

# Tests all Swift code blocks during `mdbook build`
# See scripts/mdbook-swift-test.py for implementation
[output.swift-test]
command = "python3 ../../../scripts/mdbook-swift-test.py"
Loading
Loading