Add mdbook support for the Miden-client #5
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
# Performs checks, builds and deploys the mdbook | |
name: book | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
paths: | |
- 'docs/src/SUMMARY.md' | |
- 'docs/src/IMPORTED.md' | |
jobs: | |
check-files: | |
name: check interdependent files | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if SUMMARY.md and IMPORTED.md are modified together | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
BASE_SHA=${{ github.event.pull_request.base.sha }} | |
HEAD_SHA=${{ github.event.pull_request.head.sha }} | |
else | |
# For push events, compare with the previous commit | |
BASE_SHA=${{ github.event.before }} | |
HEAD_SHA=${{ github.event.after }} | |
fi | |
# Check which files were modified | |
SUMMARY_CHANGED=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -q "src/docs/SUMMARY.md" && echo "true" || echo "false") | |
IMPORTED_CHANGED=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -q "src/docs/IMPORTED.md" && echo "true" || echo "false") | |
# If one file changed and the other didn't, fail the check | |
if [[ "$SUMMARY_CHANGED" == "true" && "$IMPORTED_CHANGED" == "false" ]]; then | |
echo "Error: src/docs/SUMMARY.md was modified but src/docs/IMPORTED.md was not. Please update both files together to make sure the local book and the Miden book are in sync." | |
exit 1 | |
fi | |
if [[ "$SUMMARY_CHANGED" == "false" && "$IMPORTED_CHANGED" == "true" ]]; then | |
echo "Error: src/docs/IMPORTED.md was modified but src/docs/SUMMARY.md was not. Please update both files together to make sure the local book and the Miden book are in sync." | |
exit 1 | |
fi | |
echo "Both files were either modified together or not modified at all. Check passes!" | |
deploy: | |
name: deploy mdbook | |
runs-on: ubuntu-latest | |
needs: check-files | |
if: github.event_name == 'push' || github.event_name == 'workflow_run' | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install latest mdBook | |
run: | | |
tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name') | |
url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz" | |
mkdir mdbook | |
curl -sSL $url | tar -xz --directory=./mdbook | |
echo `pwd`/mdbook >> $GITHUB_PATH | |
- name: Setup Rust | |
uses: dtolnay/rust-toolchain@stable | |
- name: Install mdBook plugins | |
run: | | |
cargo install mdbook-katex mdbook-linkcheck mdbook-alerts | |
- name: Build book | |
run: mdbook build docs/ | |
- name: Setup Pages | |
uses: actions/configure-pages@v4 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: "docs/book/html" | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |