-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeploy.sh
48 lines (37 loc) · 1.6 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# This is the deploy script (to Github pages) that is run by the entrypoint,
# given that the user has specified --deploy and GITHUB_TOKEN is found
# in the environment. The script requires the token, and a filename to deploy
# (should be index.html). This script is intended to be used with Github
# actions, so the various GITHUB_* variables should be defined.
DEPLOY_FILE="${1:-}"
if [ ! -f "${DEPLOY_FILE}" ]; then
echo "Cannot find ${DEPLOY_FILE}";
exit 1;
fi
# Only deploy on change to master (or used specified branch)
GITHUB_BRANCH="${GITHUB_BRANCH:-refs/heads/master}"
# Is the branch the user specified the one we are on?
if [ "${GITHUB_BRANCH}" != "${GITHUB_REF}" ]; then
echo "${GITHUB_BRANCH} != ${GITHUB_REF}, skipping deploy"
exit 0;
fi
echo "Deploy File is ${DEPLOY_FILE}"
# Set up variables for remote repository and branch
REMOTE_REPO="https://${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
REMOTE_BRANCH="gh-pages"
# Initialize Github Pages and push
git init && \
git config user.name "${GITHUB_ACTOR}" && \
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" && \
# Checkout orphan branch, we remove all because can't add main.workflow
git checkout gh-pages || git checkout --orphan gh-pages
git pull origin gh-pages
git rm -rf .
# Add the deploy file to the PWD, an empty github pages
cp ${DEPLOY_FILE} .
git add $(basename "${DEPLOY_FILE}");
# Push to Github pages
git commit -m 'Automated deployment to Github Pages: Action deploy' --allow-empty && \
git push origin gh-pages && \
echo "Successful deploy."