docs: update #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build docs | |
on: | |
push: | |
branches: | |
- main | |
paths: ["docs/**/*", "src/**/*.rs", ".github/workflows/docs.yml"] | |
workflow_dispatch: | |
jobs: | |
deploy: | |
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment | |
permissions: | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
# Deploy to the github-pages environment | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
# Install deps | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libssl-dev pkg-config libudev-dev | |
# Cache cargo registry | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
cache-all-crates: true | |
cache-on-failure: true | |
- run: cargo install mdbook | |
- run: cargo install mdbook-mermaid | |
- name: Build API docs | |
run: cargo doc --no-deps --all-features --all --exclude dies-protos | |
- name: Copy API docs to docs | |
run: cp -r target/doc docs/src/api | |
- name: Generate index for all crates | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = require('path'); | |
// List all directories in ./crates | |
const crates = fs.readdirSync('./crates', { withFileTypes: true }) | |
.filter(dirent => dirent.isDirectory()) | |
.map(dirent => dirent.name.replace(/-/g, '_')); | |
// Generate index.md | |
const index = crates.map(crate => `* [${crate}](/api/${crate})`).join('\n'); | |
fs.writeFileSync('./docs/src/api/index.md', index); | |
- run: mdbook build | |
working-directory: ./docs | |
- name: Fix permissions | |
run: chmod -c -R +rX "./docs/" | |
- name: Archive artifact | |
shell: sh | |
working-directory: ./docs/book | |
run: | | |
tar \ | |
--dereference --hard-dereference \ | |
-cvf "$RUNNER_TEMP/artifact.tar" \ | |
--exclude=.git \ | |
--exclude=.github \ | |
. | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: "github-pages" | |
path: ${{ runner.temp }}/artifact.tar | |
retention-days: 1 | |
if-no-files-found: error | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v2 |