|
| 1 | +name: 'Documentation' |
| 2 | + |
| 3 | +# Build and publish rustdoc to GitHub Pages. |
| 4 | +# |
| 5 | +# The workspace splits into two compilation targets: |
| 6 | +# - host (x86_64-unknown-linux-gnu) for every crate except hsm-firmware. |
| 7 | +# `cargo doc` picks them up via `default-members` in the root Cargo.toml. |
| 8 | +# - thumbv6m-none-eabi for hsm-firmware, which depends on embassy-rp and |
| 9 | +# cortex-m and only compiles for Cortex-M0. |
| 10 | +# |
| 11 | +# Each target lands in its own subdirectory under `site/`. A custom |
| 12 | +# landing page at `site/index.html` points users to either tree. |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - main |
| 18 | + pull_request: |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +env: |
| 22 | + CARGO_TERM_COLOR: always |
| 23 | + |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + name: Build documentation |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install system dependencies |
| 34 | + run: | |
| 35 | + sudo apt-get update |
| 36 | + sudo apt-get install -y \ |
| 37 | + libudev-dev \ |
| 38 | + pkg-config |
| 39 | +
|
| 40 | + - name: Install Rust toolchain |
| 41 | + uses: dtolnay/rust-toolchain@stable |
| 42 | + with: |
| 43 | + targets: thumbv6m-none-eabi |
| 44 | + |
| 45 | + - name: Cache cargo registry |
| 46 | + uses: actions/cache@v4 |
| 47 | + with: |
| 48 | + path: ~/.cargo/registry |
| 49 | + key: ${{ runner.os }}-cargo-doc-${{ hashFiles('**/Cargo.lock') }} |
| 50 | + |
| 51 | + - name: Build host documentation |
| 52 | + run: | |
| 53 | + cargo doc \ |
| 54 | + --no-deps \ |
| 55 | + --document-private-items \ |
| 56 | + --target-dir target/doc-host |
| 57 | +
|
| 58 | + - name: Build firmware documentation |
| 59 | + run: | |
| 60 | + cargo doc \ |
| 61 | + -p hsm-firmware \ |
| 62 | + --no-deps \ |
| 63 | + --document-private-items \ |
| 64 | + --target thumbv6m-none-eabi \ |
| 65 | + --target-dir target/doc-firmware |
| 66 | +
|
| 67 | + - name: Generate host index page |
| 68 | + run: | |
| 69 | + mkdir -p doc-build/host |
| 70 | + cat > doc-build/host-index.html << 'EOF' |
| 71 | + <!DOCTYPE html> |
| 72 | + <html lang="en"> |
| 73 | + <head> |
| 74 | + <meta charset="UTF-8"> |
| 75 | + <title>mini-hsm - host crates</title> |
| 76 | + <style> |
| 77 | + body { font-family: -apple-system, "Segoe UI", sans-serif; max-width: 720px; margin: 2rem auto; padding: 0 1rem; color: #2b2b2b; line-height: 1.6; } |
| 78 | + h1 { color: #3d6b3c; border-bottom: 1px solid #ddd; padding-bottom: 0.4rem; } |
| 79 | + ul { padding-left: 1.2rem; } |
| 80 | + li { margin: 0.3rem 0; } |
| 81 | + a { color: #3d6b3c; text-decoration: none; } |
| 82 | + a:hover { text-decoration: underline; } |
| 83 | + .target { font-family: "Source Code Pro", monospace; background: #eaeaea; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.85rem; } |
| 84 | + .back { font-size: 0.9rem; } |
| 85 | + @media (prefers-color-scheme: dark) { |
| 86 | + body { background: #1a1a1a; color: #e6e6e6; } |
| 87 | + h1 { color: #b3dcb2; border-bottom-color: #3a3a3a; } |
| 88 | + a { color: #b3dcb2; } |
| 89 | + .target { background: #2e2e2e; } |
| 90 | + } |
| 91 | + </style> |
| 92 | + </head> |
| 93 | + <body> |
| 94 | + <p class="back"><a href="../">← back to index</a></p> |
| 95 | + <h1>Host crates</h1> |
| 96 | + <p>Target: <span class="target">x86_64-unknown-linux-gnu</span></p> |
| 97 | + <ul> |
| 98 | + <li><a href="atecc608b/index.html">atecc608b</a> : no_std driver for the ATECC608B</li> |
| 99 | + <li><a href="hsm_crypto_service/index.html">hsm_crypto_service</a> : business logic (PIN, PUK, sign workflow)</li> |
| 100 | + <li><a href="hsm_usb_protocol/index.html">hsm_usb_protocol</a> : HID command and response encoding</li> |
| 101 | + <li><a href="hsm_firmware_logic/index.html">hsm_firmware_logic</a> : host-testable firmware logic (state machine, debouncer)</li> |
| 102 | + <li><a href="hsm_host/index.html">hsm_host</a> : CLI client over USB-HID</li> |
| 103 | + <li><a href="config_generator/index.html">config_generator</a> : ATECC608B configuration zone blob generator</li> |
| 104 | + </ul> |
| 105 | + </body> |
| 106 | + </html> |
| 107 | + EOF |
| 108 | +
|
| 109 | + - name: Generate firmware index page |
| 110 | + run: | |
| 111 | + cat > doc-build/firmware-index.html << 'EOF' |
| 112 | + <!DOCTYPE html> |
| 113 | + <html lang="en"> |
| 114 | + <head> |
| 115 | + <meta charset="UTF-8"> |
| 116 | + <title>mini-hsm - firmware</title> |
| 117 | + <style> |
| 118 | + body { font-family: -apple-system, "Segoe UI", sans-serif; max-width: 720px; margin: 2rem auto; padding: 0 1rem; color: #2b2b2b; line-height: 1.6; } |
| 119 | + h1 { color: #3d6b3c; border-bottom: 1px solid #ddd; padding-bottom: 0.4rem; } |
| 120 | + ul { padding-left: 1.2rem; } |
| 121 | + li { margin: 0.3rem 0; } |
| 122 | + a { color: #3d6b3c; text-decoration: none; } |
| 123 | + a:hover { text-decoration: underline; } |
| 124 | + .target { font-family: "Source Code Pro", monospace; background: #eaeaea; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.85rem; } |
| 125 | + .back { font-size: 0.9rem; } |
| 126 | + @media (prefers-color-scheme: dark) { |
| 127 | + body { background: #1a1a1a; color: #e6e6e6; } |
| 128 | + h1 { color: #b3dcb2; border-bottom-color: #3a3a3a; } |
| 129 | + a { color: #b3dcb2; } |
| 130 | + .target { background: #2e2e2e; } |
| 131 | + } |
| 132 | + </style> |
| 133 | + </head> |
| 134 | + <body> |
| 135 | + <p class="back"><a href="../">← back to index</a></p> |
| 136 | + <h1>Firmware</h1> |
| 137 | + <p>Target: <span class="target">thumbv6m-none-eabi</span></p> |
| 138 | + <p>The RP2040 binary. Cross-compiled because it depends on embassy-rp and cortex-m.</p> |
| 139 | + <ul> |
| 140 | + <li><a href="hsm_firmware/index.html">hsm_firmware</a> : main binary, tasks, RP2040 HAL implementation</li> |
| 141 | + </ul> |
| 142 | + </body> |
| 143 | + </html> |
| 144 | + EOF |
| 145 | +
|
| 146 | + - name: Assemble documentation site |
| 147 | + run: | |
| 148 | + mkdir -p site/host site/firmware |
| 149 | + cp -r target/doc-host/doc/. site/host/ |
| 150 | + cp -r target/doc-firmware/thumbv6m-none-eabi/doc/. site/firmware/ |
| 151 | + cp doc-extras/index.html site/index.html |
| 152 | + cp doc-build/host-index.html site/host/index.html |
| 153 | + cp doc-build/firmware-index.html site/firmware/index.html |
| 154 | +
|
| 155 | + - name: Upload site artifact |
| 156 | + uses: actions/upload-pages-artifact@v3 |
| 157 | + with: |
| 158 | + path: site |
| 159 | + |
| 160 | + deploy: |
| 161 | + name: Deploy to GitHub Pages |
| 162 | + runs-on: ubuntu-latest |
| 163 | + needs: build |
| 164 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 165 | + |
| 166 | + permissions: |
| 167 | + contents: read |
| 168 | + pages: write |
| 169 | + id-token: write |
| 170 | + |
| 171 | + environment: |
| 172 | + name: github-pages |
| 173 | + url: ${{ steps.deployment.outputs.page_url }} |
| 174 | + |
| 175 | + steps: |
| 176 | + - name: Deploy |
| 177 | + id: deployment |
| 178 | + uses: actions/deploy-pages@v4 |
0 commit comments