ghaction-github-pages/entrypoint.sh

29 lines
714 B
Bash
Raw Normal View History

2019-09-01 05:16:43 +08:00
#!/bin/sh
set -e
2019-09-01 05:33:41 +08:00
TARGET_BRANCH=$1
BUILD_DIR=$2
if [ -z "$TARGET_BRANCH" ]; then
echo "⛔️ Target branch not defined"
exit 1
fi
2019-09-01 05:16:43 +08:00
if [ ! -d "$BUILD_DIR" ]; then
echo "⛔️ Build dir does not exist"
exit 1
fi
2019-09-01 05:33:41 +08:00
echo "🏃 Deploying $BUILD_DIR directory to $TARGET_BRANCH branch"
cd "$BUILD_DIR"
2019-09-01 05:16:43 +08:00
git init
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add .
git commit --allow-empty -m 'Deploy to GitHub pages'
2019-09-01 06:57:52 +08:00
git push --force --quiet "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "master:$TARGET_BRANCH"
2019-09-01 05:16:43 +08:00
rm -rf .git
cd "$GITHUB_WORKSPACE"
echo "🎉 Content of $BUILD_DIR has been deployed to GitHub Pages."