From 0147681fad7245d96b208d1aeb19d7f7b3832d0d Mon Sep 17 00:00:00 2001 From: Casper Welzel Andersen Date: Fri, 23 Apr 2021 11:25:36 +0200 Subject: [PATCH] Scaffold for automating GH Pages build --- .github/workflows/gh_pages.yml | 42 ++++++++++++++++++++++++++++++ ontology/gh_pages/commit.sh | 32 +++++++++++++++++++++++ ontology/gh_pages/requirements.txt | 1 + 3 files changed, 75 insertions(+) create mode 100644 .github/workflows/gh_pages.yml create mode 100755 ontology/gh_pages/commit.sh create mode 100644 ontology/gh_pages/requirements.txt diff --git a/.github/workflows/gh_pages.yml b/.github/workflows/gh_pages.yml new file mode 100644 index 0000000..57bbb7a --- /dev/null +++ b/.github/workflows/gh_pages.yml @@ -0,0 +1,42 @@ +name: GH Pages deployment + +on: + release: + types: [published] + +jobs: + + gh-pages_build: + name: Build GH Pages + runs-on: ubuntu-latest + + env: + COMMIT_AUTHOR: CIF-ontology Team + COMMIT_AUTHOR_EMAIL: cif-ontology@emmo-repo.org + BUILD_FOLDER: "ontology/build" + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: Install Python dependencies + run: + python -m pip install -U pip setuptools + pip install -r ontology/gh_pages/requirements.txt + + - name: Make GH Pages + run: # Command here to generate GH pages files + + - name: Commit to branch `gh-pages` + run: ./ontology/gh_pages/commit.sh + + - name: Push changes to GitHub remote + uses: ad-m/github-push-action@v0.6.0 + with: + branch: gh-pages + force: true + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/ontology/gh_pages/commit.sh b/ontology/gh_pages/commit.sh new file mode 100755 index 0000000..c022dca --- /dev/null +++ b/ontology/gh_pages/commit.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +# Exit with nonzero exit code if anything fails (-e) +# Print all executed lines (-x) +set -ex + +# Commit sha of main branch +SHA=`git rev-parse --verify HEAD` +TARGET_BRANCH="gh-pages" + +if [ "${GITHUB_ACTIONS}" != "true" ]; then + echo "Skipping deploy; just doing a build." + exit 0 +fi + +# Move html to temp dir +mv "${BUILD_FOLDER}" ../page-build +git checkout "${TARGET_BRANCH}" || git checkout --orphan "${TARGET_BRANCH}" +rm -rf * || exit 0 +cp -r ../page-build/* . + +git config user.name "${COMMIT_AUTHOR}" +git config user.email "${COMMIT_AUTHOR_EMAIL}" + +git add -A . +# If there are no changes to the compiled out (e.g. this is a README update) then just bail. +if git diff --cached --quiet; then + echo "No changes to the output on this push; exiting." + exit 0 +fi + +git commit -m "Deploy to GitHub Pages: ${SHA}" diff --git a/ontology/gh_pages/requirements.txt b/ontology/gh_pages/requirements.txt new file mode 100644 index 0000000..eaf1e67 --- /dev/null +++ b/ontology/gh_pages/requirements.txt @@ -0,0 +1 @@ +jinja2==3.0.0rc1