github-pages-deploy-action/entrypoint.sh

35 lines
965 B
Bash
Raw Normal View History

2019-03-03 07:43:28 +08:00
#!/bin/sh -l
if [ -z "$BRANCH" ]
then
2019-03-04 00:26:20 +08:00
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
2019-03-03 07:43:28 +08:00
exit 1
fi
if [ -z "$FOLDER" ]
then
2019-03-03 23:05:36 +08:00
echo "You must provide the action with the folder name in the repository where your compiled page lives."
2019-03-03 23:59:11 +08:00
exit 1
2019-03-03 07:43:28 +08:00
fi
# Installs Git.
apt-get update && \
apt-get install -y git && \
# Re-directs to the the Github workspace.
cd $GITHUB_WORKSPACE && \
# Configures Git and checks out the base branch.
git config --global user.email "${COMMIT_EMAIL:-gh-pages-deploy@jives.dev}" && \
git config --global user.name "${COMMIT_NAME:-Github Pages Deploy}" && \
2019-03-04 00:17:43 +08:00
git checkout "${BASE_BRANCH:-master}" && \
2019-03-03 07:43:28 +08:00
2019-03-03 23:07:27 +08:00
# Builds the project if applicable.
2019-03-04 00:21:41 +08:00
echo "Running build scripts... $BUILD_SCRIPT"
2019-03-04 00:16:36 +08:00
eval "$BUILD_SCRIPT"
2019-03-03 07:43:28 +08:00
# Commits the data to Github.
2019-03-03 23:26:44 +08:00
git add -f $FOLDER && \
2019-03-03 07:43:28 +08:00
git commit -m "Deploying $(date +"%T")" && \
git push origin `git subtree split --prefix $FOLDER master`:$BRANCH --force