Skip to content

Commit 14f2490

Browse files
authored
Merge pull request #2827 from ehuss/publish-pre-release-guide
Support publishing a pre-release version of the guide
2 parents 8f46ad8 + 0dc65a1 commit 14f2490

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,8 @@ jobs:
4646
- uses: actions/checkout@v4
4747
- name: Install Rust (rustup)
4848
run: rustup update stable --no-self-update && rustup default stable
49-
- name: Build book
50-
run: cargo run -- build guide
5149
- name: Deploy the User Guide to GitHub Pages using the gh-pages branch
52-
env:
53-
GITHUB_DEPLOY_KEY: ${{ secrets.GITHUB_DEPLOY_KEY }}
54-
run: |
55-
touch guide/book/.nojekyll
56-
curl -LsSf https://raw.githubusercontent.com/rust-lang/simpleinfra/master/setup-deploy-keys/src/deploy.rs | rustc - -o /tmp/deploy
57-
cd guide/book
58-
/tmp/deploy
50+
run: ci/publish-guide.sh
5951
publish:
6052
name: Publish to crates.io
6153
runs-on: ubuntu-latest

ci/publish-guide.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

0 commit comments

Comments
 (0)