Skip to content

Commit 8b8c5f0

Browse files
committed
Don't require $GITHUB_TOKEN to build locally
Mdbook currently gives a hard error if it's not set in the environment: ``` [2023-03-25T22:52:13Z ERROR mdbook_linkcheck::config] Unable to interpolate "authorization: Bearer $GITHUB_TOKEN" because Failed to retrieve `GITHUB_TOKEN` env var: environment variable not found ``` Dynamically add it in `linkcheck.sh` to avoid requiring it when we don't need it.
1 parent 5eca473 commit 8b8c5f0

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ To build a local static HTML site, install [`mdbook`](https://github.com/rust-la
4949
and execute the following command in the root of the repository:
5050

5151
```
52-
> mdbook build
52+
> mdbook build --open
5353
```
5454

55-
The build files are found in the `book` directory.
55+
The build files are found in the `book/html` directory.
5656

5757
### Link Validations
5858

book.toml

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ exclude = [
4343
cache-timeout = 86400
4444
warning-policy = "error"
4545

46-
[output.linkcheck.http-headers]
47-
'github\.com' = ["Authorization: Bearer $GITHUB_TOKEN"]
48-
4946
[output.html.redirect]
5047
"/compiletest.html" = "tests/compiletest.html"
5148
"/diagnostics/sessiondiagnostic.html" = "diagnostic-structs.html"

ci/linkcheck.sh

+7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
set -e
44
set -o pipefail
55

6+
set_github_token() {
7+
echo "[output.linkcheck.http-headers]
8+
'github\.com' = [\"Authorization: Bearer \$GITHUB_TOKEN\"]" >> $(git rev-parse --show-toplevel)/book.toml
9+
}
10+
611
# https://docs.github.com/en/actions/reference/environment-variables
712
if [ "$GITHUB_EVENT_NAME" = "schedule" ] ; then # running in scheduled job
813
FLAGS=""
14+
set_github_token
915

1016
echo "Doing full link check."
1117
set -x
@@ -17,6 +23,7 @@ elif [ "$GITHUB_EVENT_NAME" = "pull_request" ] ; then # running in PR CI build
1723

1824
CHANGED_FILES=$(git diff --name-only $BASE_SHA... | tr '\n' ' ')
1925
FLAGS="--no-cache -f $CHANGED_FILES"
26+
set_github_token
2027

2128
echo "Checking files changed since $BASE_SHA: $CHANGED_FILES"
2229
set -x

0 commit comments

Comments
 (0)