Skip to content

Commit

Permalink
Automatically deploy the book
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Oct 12, 2023
1 parent 33b287a commit 0929708
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ jobs:
target/
key: ${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ hashFiles('rust-toolchain.toml') }}
- run: sudo apt-get update
- run: ./scripts/setup.sh
- run: ./scripts/ci.sh
21 changes: 21 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Deploy Github Pages

on:
push:
branches:
- main

jobs:
pages:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: ./scripts/setup.sh
- run: git config --global user.name 'Julien Cretin'
- run: git config --global user.email [email protected]
- run: ./scripts/pages.sh
- run: git push -f origin gh-pages
9 changes: 6 additions & 3 deletions scripts/pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ set -e
# This script synchronizes the gh-pages branch from a clean main.

[ -z "$(git status -s)" ] || e 'not clean'
[ "$(git symbolic-ref -q HEAD)" = refs/heads/main ] || e 'not main'
[ -n "$CI" -o "$(git symbolic-ref -q HEAD)" = refs/heads/main ] || e 'not main'
COMMIT="$(git rev-parse -q --verify HEAD)"
[ -n "$COMMIT" ] || e 'failed to get commit hash'

git diff --quiet "$(git log --pretty=format:%f origin/gh-pages)".. -- book \
&& d "origin/gh-pages is already up-to-date"

WASEFIRE_WRAPPER_EXEC=n ./scripts/wrapper.sh mdbook
( cd book
../scripts/wrapper.sh mdbook build 2>/dev/null )
mv book/book html
Expand All @@ -32,9 +35,9 @@ git show-ref -q --verify refs/heads/gh-pages && git branch -qD gh-pages
git checkout -q --orphan gh-pages
git rm -qrf .
git clean -qfxde/html
mv html/* html/.* .
find html -mindepth 1 -maxdepth 1 -exec mv {} . \;
rmdir html
git add .
git commit -qm"$(git rev-parse -q --verify main)"
git commit -qm"$COMMIT"
git checkout -q main
d "gh-pages has been updated"

0 comments on commit 0929708

Please sign in to comment.