Merge pull request #16 from leanprover/cicd

CI and auto documentation preview for mathlib4
main
Henrik Böving 2022-01-07 10:32:49 +01:00
commit 08c1770655
2 changed files with 90 additions and 0 deletions

47
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: build and deploy docs
on:
schedule:
- cron: '0 */2 * * *' # every 2 hours
push:
pull_request:
jobs:
build:
name: build and deploy docs
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: install elan
run: |
set -o pipefail
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh -s -- --default-toolchain none -y
~/.elan/bin/lean --version
echo "$HOME/.elan/bin" >> $GITHUB_PATH
- name: compile doc-gen4
run: |
lake build
- name: Checkout and compile mathlib4
run: |
cd ../
git clone https://github.com/leanprover-community/mathlib4
cd mathlib4
lake build
- name: generate and deploy docs
run: |
if [ "$github_repo" = "leanprover/doc-gen4" ] && [ "$github_ref" = "refs/heads/main" ]; then
deploy="true"
else
deploy="false"
fi
cd ../
./doc-gen4/deploy_docs.sh "mathlib4" "doc-gen4" "$deploy"
env:
MATHLIB4_DOCS_KEY: ${{ secrets.MATHLIB4_DOCS_KEY }}
github_repo: ${{ github.repository }}
github_ref: ${{ github.ref }}

43
deploy_docs.sh Executable file
View File

@ -0,0 +1,43 @@
# Arguments:
# $1 : path to mathlib4 from working directory
# $2 : path to doc-gen4 from working directory
# $3 : whether to deploy
set -e
set -x
cd $1
mathlib_short_git_hash="$(git log -1 --pretty=format:%h)"
cd ../$2
docgen_git_hash="$(git log -1 --pretty=format:%h)"
cd ../
git clone "https://github.com/leanprover-community/mathlib4_docs.git" mathlib4_docs
# skip if docs for this commit have already been generated
if [ "$(cd mathlib4_docs && git log -1 --pretty=format:%s)" == "automatic update to mathlib4 $mathlib_short_git_hash using doc-gen4 $docgen_git_hash" ]; then
exit 0
fi
# generate the docs
cd $1
../$2/build/bin/doc-gen4 Mathlib
if [ "$3" = "true" ]; then
cd ..
rm -rf mathlib4_docs/docs/
cp -r "$1/build/doc" mathlib4_docs/docs
mkdir ~/.ssh
echo "$MATHLIB4_DOCS_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
cd mathlib4_docs/docs
git remote set-url origin "git@github.com:leanprover-community/mathlib4_docs.git"
git config user.email "hargonix@gmail.com"
git config user.name "doc-gen4-bot"
git add -A .
git checkout --orphan master2
git commit -m "automatic update to mathlib4 $mathlib_short_git_hash using doc-gen4 $docgen_git_hash"
git push -f origin HEAD:master
fi