Skip to content

Commit 0e5ddf6

Browse files
authored
Merge pull request #3154 from ehuss/ci-version-string
Show the correct version in CI install docs
2 parents 8b53f1b + f4ddbff commit 0e5ddf6

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

guide/guide-helper/src/lib.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,30 @@ fn insert_version(book: &mut Book) {
5151
.join("Cargo.toml");
5252
let manifest_contents = std::fs::read_to_string(&path).unwrap();
5353
let manifest: toml::Value = toml::from_str(&manifest_contents).unwrap();
54-
let version = manifest["package"]["version"].as_str().unwrap();
54+
let version = Version::parse(manifest["package"]["version"].as_str().unwrap())
55+
.expect("version is parseable");
5556
const MARKER: &str = "{{ mdbook-version }}";
57+
const SEMVER_MARKER: &str = "{{ mdbook-semver }}";
58+
const SEMVER_BREAK: &str = "{{ mdbook-semver-break }}";
5659
book.for_each_chapter_mut(|ch| {
5760
if ch.content.contains(MARKER) {
58-
ch.content = ch.content.replace(MARKER, version);
61+
ch.content = ch.content.replace(MARKER, &version.to_string());
62+
}
63+
if ch.content.contains(SEMVER_MARKER) {
64+
let semver_version = if version.major == 0 {
65+
format!("{}.{}", version.major, version.minor)
66+
} else {
67+
format!("{}", version.major)
68+
};
69+
ch.content = ch.content.replace(SEMVER_MARKER, &semver_version)
70+
}
71+
if ch.content.contains(SEMVER_BREAK) {
72+
let semver_break = if version.major == 0 {
73+
format!("{}.{}.0", version.major, version.minor + 1)
74+
} else {
75+
format!("{}.0.0", version.major + 1)
76+
};
77+
ch.content = ch.content.replace(SEMVER_BREAK, &semver_break);
5978
}
6079
});
6180
}

guide/src/continuous-integration.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ We recommend using a SemVer version specifier so that you get the latest **non-b
4646
For example:
4747

4848
```sh
49-
cargo install mdbook --no-default-features --features search --vers "^0.4" --locked
49+
cargo install mdbook --no-default-features --features search --vers "^{{ mdbook-version }}" --locked
5050
```
5151

5252
This includes several recommended options:
5353

5454
* `--no-default-features` --- Disables features like the HTTP server used by `mdbook serve` that is likely not needed on CI.
5555
This will speed up the build time significantly.
5656
* `--features search` --- Disabling default features means you should then manually enable features that you want, such as the built-in [search] capability.
57-
* `--vers "^0.4"` --- This will install the most recent version of the `0.4` series.
58-
However, versions after like `0.5.0` won't be installed, as they may break your build.
57+
* `--vers "^{{ mdbook-version }}"` --- This will install the most recent version of the `{{ mdbook-semver }}` version series.
58+
However, semver-incompatible versions after like `{{ mdbook-semver-break }}` won't be installed, as they may break your build.
5959
Cargo will automatically upgrade mdBook if you have an older version already installed.
60+
If you want to stick to a specific version of mdBook, replace the `^` with an `=`.
6061
* `--locked` --- This will use the dependencies that were used when mdBook was released.
6162
Without `--locked`, it will use the latest version of all dependencies, which may include some fixes since the last release, but may also (rarely) cause build problems.
6263

0 commit comments

Comments
 (0)