Skip to content

Commit 6287e6a

Browse files
authored
Merge pull request #715 from fitzgen/continuous-integration-instructions
user guide: Add instructions for running `mdbook` in CI
2 parents 953d382 + 488ace1 commit 6287e6a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

book-example/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [Editor](format/theme/editor.md)
1818
- [MathJax Support](format/mathjax.md)
1919
- [mdBook specific features](format/mdbook.md)
20+
- [Continuous Integration](continuous-integration.md)
2021
- [For Developers](for_developers/README.md)
2122
- [Preprocessors](for_developers/preprocessors.md)
2223
- [Alternate Backends](for_developers/backends.md)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Running `mdbook` in Continuous Integration
2+
3+
While the following examples use Travis CI, their principles should
4+
straightforwardly transfer to other continuous integration providers as well.
5+
6+
## Ensuring Your Book Builds and Tests Pass
7+
8+
Here is a sample Travis CI `.travis.yml` configuration that ensures `mdbook
9+
build` and `mdbook test` run successfully. The key to fast CI turnaround times
10+
is caching `mdbook` installs, so that you aren't compiling `mdbook` on every CI
11+
run.
12+
13+
```yaml
14+
language: rust
15+
sudo: false
16+
17+
cache:
18+
- cargo
19+
20+
rust:
21+
- stable
22+
23+
before_script:
24+
- (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
25+
- (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.1" mdbook)
26+
- cargo install-update -a
27+
28+
script:
29+
- cd path/to/mybook && mdbook build && mdbook test
30+
```
31+
32+
## Deploying Your Book to GitHub Pages
33+
34+
Following these instructions will result in your book being published to GitHub
35+
pages after a successful CI run on your repository's `master` branch.
36+
37+
First, create a new GitHub oauth token with the "public_repo" permissions (or
38+
"repo" for private repositories). Go to your repository's Travis CI settings
39+
page and add an environment variable named `GITHUB_TOKEN` that is marked secure
40+
and *not* shown in the logs.
41+
42+
Then, add this snippet to your `.travis.yml`:
43+
44+
```yaml
45+
deploy:
46+
provider: pages
47+
skip-cleanup: true
48+
github-token: $GITHUB_TOKEN
49+
local-dir: path/to/mybook/book
50+
keep-history: false
51+
on:
52+
branch: master
53+
```
54+
55+
That's it!

0 commit comments

Comments
 (0)