From 335391d1de02e060e19938ba424c9aac73870b63 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Tue, 24 Dec 2019 16:30:49 -0500 Subject: [PATCH] Added publish script --- publish-from-actions.sh | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 publish-from-actions.sh diff --git a/publish-from-actions.sh b/publish-from-actions.sh new file mode 100755 index 0000000..acf95c8 --- /dev/null +++ b/publish-from-actions.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# FROM: https://raw.githubusercontent.com/maxheld83/ghpages/master/LICENSE +# MIT License + +# Copyright (c) 2019 Maximilian Held + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +set -e + +source ./build_dir + +echo "#################################################" +echo "Changing directory to 'BUILD_DIR' $BUILD_DIR ..." +cd $BUILD_DIR + +echo "#################################################" +echo "Now deploying to GitHub Pages..." +REMOTE_REPO="https://${GITHUB_PERSONAL_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \ +REPONAME="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 2)" && \ +OWNER="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 1)" && \ +GHIO="${OWNER}.github.io" && \ +if [[ "$REPONAME" == "$GHIO" ]]; then + REMOTE_BRANCH="master" +else + REMOTE_BRANCH="gh-pages" +fi && \ +git init && \ +git config user.name "${GITHUB_ACTOR}" && \ +git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \ +if [ -z "$(git status --porcelain)" ]; then + echo "Nothing to commit" && \ + exit 0 +fi && \ +git add . && \ +git commit -m 'Deploy to GitHub Pages' && \ +echo "REMOTE_BRANCH: $REMOTE_BRANCH" && \ +git push --force $REMOTE_REPO master:$REMOTE_BRANCH && \ +rm -fr .git && \ +cd $GITHUB_WORKSPACE && \ +echo "Content of $BUILD_DIR has been deployed to GitHub Pages." \ No newline at end of file