github-pages-deploy-action/entrypoint.sh

57 lines
1.5 KiB
Bash
Raw Normal View History

2019-03-03 07:43:28 +08:00
#!/bin/sh -l
2019-03-04 05:12:26 +08:00
if [ -z "$ACCESS_TOKEN" ]
then
echo "You must provide the action with a GitHub Personal Access Token secret in order to deploy."
exit 1
fi
2019-03-03 07:43:28 +08:00
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
2019-03-04 05:12:26 +08:00
if [ -z "$COMMIT_EMAIL" ]
2019-03-04 04:45:52 +08:00
then
2019-03-04 05:12:26 +08:00
COMMIT_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com"
2019-03-04 04:45:52 +08:00
fi
2019-03-04 05:12:26 +08:00
if [ -z "$COMMIT_NAME" ]
then
COMMIT_NAME="${GITHUB_ACTOR}"
2019-03-04 04:57:51 +08:00
fi
2019-03-04 05:12:26 +08:00
## Initializes the repository path using the access token.
2019-03-04 04:14:05 +08:00
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
2019-03-04 05:12:26 +08:00
2019-03-03 07:43:28 +08:00
# Installs Git.
apt-get update && \
apt-get install -y git && \
2019-03-04 05:12:26 +08:00
# Directs the action to the the Github workspace.
2019-03-03 07:43:28 +08:00
cd $GITHUB_WORKSPACE && \
# Configures Git and checks out the base branch.
2019-03-04 04:14:05 +08:00
git init && \
2019-03-04 05:12:26 +08:00
git config --global user.email "${COMMIT_EMAIL}" && \
git config --global user.name "${COMMIT_NAME}" && \
2019-03-04 00:17:43 +08:00
git checkout "${BASE_BRANCH:-master}" && \
2019-03-03 07:43:28 +08:00
2019-03-04 05:12:26 +08:00
# Builds the project if a build script is provided.
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-04 05:12:26 +08:00
echo "Deploying to GitHub..." && \
2019-03-03 23:26:44 +08:00
git add -f $FOLDER && \
2019-03-04 05:12:26 +08:00
git commit -m "Deploying to ${BRANCH} - $(date +"%T")" && \
2019-03-04 04:57:51 +08:00
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH --force && \
2019-03-04 05:12:26 +08:00
echo "Deployment Succesful!"