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 7663f28
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
# TODO(debug): Enable back before merge.
# pull_request:
# branches:
# - main
schedule:
- cron: 45 3 * * 2 # every Tuesday at 3:45 UTC

Expand Down Expand Up @@ -42,6 +43,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
25 changes: 25 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy Github Pages

on:
push:
branches:
- main
# TODO(debug): Remove before merge.
pull_request:
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:test-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 7663f28

Please sign in to comment.