-
Notifications
You must be signed in to change notification settings - Fork 48
94 lines (78 loc) · 3.21 KB
/
book.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Performs checks, builds and deploys the mdbook
name: book
on:
push:
branches: [main, next]
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
# Only run deployment on push to main/next branches, not on PRs
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