Skip to content

Commit

Permalink
Scaffold for automating GH Pages build
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Aug 18, 2021
1 parent 8d5b7bd commit 0147681
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/gh_pages.yml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
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/[email protected]
with:
branch: gh-pages
force: true
github_token: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions ontology/gh_pages/commit.sh
Original file line number Diff line number Diff line change
@@ -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}"
1 change: 1 addition & 0 deletions ontology/gh_pages/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jinja2==3.0.0rc1

0 comments on commit 0147681

Please sign in to comment.