Debian Codegraph @

ci/publish-guide.sh

raw
1 #!/usr/bin/env bash
2 # This publishes the user guide to GitHub Pages.
3 #
4 # If this is a pre-release, then it goes in a separate directory called "pre-release".
5 # Commits are amended to avoid keeping history which can balloon the repo size.
6 set -ex
7
8 cargo run --no-default-features -F search -- build guide
9
10 VERSION=$(cargo metadata --format-version 1 --no-deps | jq '.packages[] | select(.name == "mdbook") | .version')
11
12 if [[ "$VERSION" == *-* ]]; then
13 PRERELEASE=true
14 else
15 PRERELEASE=false
16 fi
17
18 git fetch origin gh-pages
19 git worktree add gh-pages gh-pages
20 git config user.name "Deploy from CI"
21 git config user.email ""
22 cd gh-pages
23 if [[ "$PRERELEASE" == "true" ]]
24 then
25 rm -rf pre-release
26 mv ../guide/book pre-release
27 git add pre-release
28 git commit --amend -m "Deploy $GITHUB_SHA pre-release to gh-pages"
29 else
30 # Delete everything except pre-release and .git.
31 find . -mindepth 1 -maxdepth 1 -not -name "pre-release" -not -name ".git" -exec rm -rf {} +
32 # Copy the guide here.
33 find ../guide/book/ -mindepth 1 -maxdepth 1 -exec mv {} . \;
34 git add .
35 git commit --amend -m "Deploy $GITHUB_SHA to gh-pages"
36 fi
37
38 git push --force origin +gh-pages