-
Notifications
You must be signed in to change notification settings - Fork 18
145 lines (127 loc) · 4.98 KB
/
mdbook.yml
File metadata and controls
145 lines (127 loc) · 4.98 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Workflow for building and deploying a mdBook site to GitHub Pages.
# - On push to main: deploys to the root of gh-pages.
# - On pull_request: deploys a preview under pr-preview/pr-<number>/ on gh-pages,
# comments the preview URL, and cleans up when the PR closes.
#
# Repo Settings required:
# Pages -> Source: "Deploy from a branch" -> gh-pages / (root)
# Actions -> General -> Workflow permissions: "Read and write permissions"
#
# See: https://rust-lang.github.io/mdBook/index.html
name: Deploy mdBook site to Pages
on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize, reopened, closed]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
deploy:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
concurrency:
group: pages
cancel-in-progress: false
env:
CARGO_HOME: ${{ github.workspace }}/.cargo
RUSTUP_HOME: ${{ github.workspace }}/.rustup
steps:
- uses: actions/checkout@v4
- name: Cache Cargo registry and git index
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/registry
${{ env.CARGO_HOME }}/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
# Cache full RUSTUP_HOME (rustc + toolchain + settings) so rustup does minimal work on restore.
- name: Cache Rust toolchain (rustc)
uses: actions/cache@v4
with:
path: ${{ env.RUSTUP_HOME }}
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-rust-toolchain-
# Exact key only (no restore-keys) so we never restore a bin/ missing a tool (e.g. linkcheck2).
- name: Cache installed mdBook binaries
id: mdbook-cache
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/bin
key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }}
# Script skips install when cached binaries already match versions in install-mdbook.sh
- name: Install mdBook
run: bash scripts/install-mdbook.sh
env:
REPO_ROOT: ${{ github.workspace }}
- name: Add Cargo bin to PATH
run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
- name: Build with mdBook
run: ${{ env.CARGO_HOME }}/bin/mdbook build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book
keep_files: true
preview:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
concurrency: preview-${{ github.ref }}
env:
CARGO_HOME: ${{ github.workspace }}/.cargo
RUSTUP_HOME: ${{ github.workspace }}/.rustup
steps:
- uses: actions/checkout@v4
- name: Cache Cargo registry and git index
if: github.event.action != 'closed'
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/registry
${{ env.CARGO_HOME }}/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
# Cache full RUSTUP_HOME (rustc + toolchain + settings) so rustup does minimal work on restore.
- name: Cache Rust toolchain (rustc)
if: github.event.action != 'closed'
uses: actions/cache@v4
with:
path: ${{ env.RUSTUP_HOME }}
key: ${{ runner.os }}-rust-toolchain-${{ hashFiles('scripts/install-mdbook.sh') }}
restore-keys: |
${{ runner.os }}-rust-toolchain-
# Exact key only (no restore-keys) so we never restore a bin/ missing a tool (e.g. linkcheck2).
- name: Cache installed mdBook binaries
if: github.event.action != 'closed'
id: mdbook-cache
uses: actions/cache@v4
with:
path: |
${{ env.CARGO_HOME }}/bin
key: ${{ runner.os }}-mdbook-bin-${{ hashFiles('scripts/install-mdbook.sh') }}
# Script skips install when cached binaries already match versions in install-mdbook.sh
- name: Install mdBook
if: github.event.action != 'closed'
run: bash scripts/install-mdbook.sh
env:
REPO_ROOT: ${{ github.workspace }}
- name: Add Cargo bin to PATH
if: github.event.action != 'closed'
run: echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
- name: Build with mdBook
if: github.event.action != 'closed'
run: ${{ env.CARGO_HOME }}/bin/mdbook build
- name: Deploy PR preview
uses: rossjrw/pr-preview-action@v1
with:
source-dir: ./book
preview-branch: gh-pages
umbrella-dir: pr-preview