Skip to content

Commit 4e4621f

Browse files
authored
Deploy RFC book (#9)
* feat: add mdBook generation * ci: deploy RFC book to GitHub Pages * docs: link to deployed RFC book
1 parent 3b07f19 commit 4e4621f

5 files changed

Lines changed: 120 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
# renovate: datasource=crate depName=mdbook versioning=semver
10+
MDBOOK_VERSION: 0.5.3
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
fetch-depth: 0
19+
- name: Install mdbook
20+
run: |
21+
mkdir mdbook
22+
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v${{ env.MDBOOK_VERSION }}/mdbook-v${{ env.MDBOOK_VERSION }}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
23+
echo `pwd`/mdbook >> $GITHUB_PATH
24+
- name: Generate Book
25+
run: |
26+
./generate-book.py
27+
- name: Upload Artifact
28+
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
29+
with:
30+
path: ./book
31+
32+
deploy:
33+
needs: build
34+
35+
permissions:
36+
pages: write
37+
id-token: write
38+
39+
environment:
40+
name: github-pages
41+
url: ${{ steps.deployment.outputs.page_url }}
42+
43+
runs-on: ubuntu-latest
44+
steps:
45+
- id: deployment
46+
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ Cargo.lock
1212

1313
# MSVC Windows builds of rustc generate these, which store debugging information
1414
*.pdb
15+
16+
# Generated by mdBook
17+
book/
18+
src/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Safety-Critical Rust Consortium RFCs
1+
# Safety-Critical Rust Consortium RFCs - [RFC Book](https://rfcs.arewesafetycriticalyet.org/)
22

33
[Safety-Critical Rust Consortium RFCs]: #scrc-rfcs
44

book.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[book]
2+
title = "The Safety-Critical Rust Consortium RFC Book"
3+
4+
[output.html]
5+
smart-punctuation = true
6+
no-section-label = true
7+
git-repository-url = "https://github.com/PLeVasseur/safety-critical-rust-consortium-rfcs"
8+
site-url = "/"
9+
10+
[output.html.search]
11+
heading-split-level = 0
12+
13+
[output.html.playground]
14+
runnable = false
15+
16+
[build]
17+
extra-watch-dirs = ["text"]

generate-book.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Generate the mdBook source tree from the RFC repository layout.
5+
6+
This mirrors the rust-lang/rfcs approach: RFCs live under text/, while src/
7+
is generated just before building the book.
8+
"""
9+
10+
import os
11+
import shutil
12+
import subprocess
13+
14+
15+
def main():
16+
if os.path.exists("src"):
17+
shutil.rmtree("src")
18+
os.mkdir("src")
19+
20+
for path in os.listdir("text"):
21+
symlink(f"../text/{path}", f"src/{path}")
22+
symlink("../README.md", "src/introduction.md")
23+
symlink("../SUBCOMMITTEES.md", "src/subcommittees.md")
24+
25+
with open("src/SUMMARY.md", "w") as summary:
26+
summary.write("[Introduction](introduction.md)\n\n")
27+
summary.write("- [Subcommittees](subcommittees.md)\n")
28+
collect(summary, "text", 0)
29+
30+
subprocess.call(["mdbook", "build"])
31+
32+
33+
def collect(summary, path, depth):
34+
entries = [entry for entry in os.scandir(path) if entry.name.endswith(".md")]
35+
entries.sort(key=lambda entry: entry.name)
36+
for entry in entries:
37+
indent = " " * depth
38+
name = entry.name[:-3]
39+
link_path = entry.path[5:]
40+
summary.write(f"{indent}- [{name}]({link_path})\n")
41+
maybe_subdir = os.path.join(path, name)
42+
if os.path.isdir(maybe_subdir):
43+
collect(summary, maybe_subdir, depth + 1)
44+
45+
46+
def symlink(src, dst):
47+
if not os.path.exists(dst):
48+
os.symlink(src, dst)
49+
50+
51+
if __name__ == "__main__":
52+
main()

0 commit comments

Comments
 (0)