forked from reposense/publish-RepoSense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·48 lines (39 loc) · 1.47 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/sh
# Pushes reposense-report folder generated by RepoSense to gh-pages branch.
set -o errexit # exit with nonzero exit code if any line fails
if [ -z "$TOKEN" ] && [ -z "$DEPLOY_KEY" ]; then
echo "$TOKEN_NAME or $DEPLOY_KEY_NAME is not set up in $ENV_NAME. Skipping deploy."
exit 0
fi;
cd reposense-report
git init
git config user.name "$GIT_USERNAME"
git config user.email "$GIT_EMAIL"
git config core.sshCommand "ssh -i ~/id_git -F /dev/null"
if [ -z "$TOKEN" ]; then
echo "$DEPLOY_KEY" | base64 -d > ~/id_git
chmod 400 ~/id_git
git remote add upstream "[email protected]:${REPO_SLUG}.git"
else
git config credential.helper 'store --file=.git/credentials'
echo "https://${TOKEN}:@github.com" > .git/credentials
git remote add upstream "https://github.com/${REPO_SLUG}.git"
fi
set -o nounset # exit if variable is unset
# Reset to gh-pages branch, or create orphan branch if gh-pages does not exist in remote.
if git ls-remote --exit-code --heads upstream gh-pages; then
git fetch --depth=1 upstream gh-pages
git reset upstream/gh-pages
elif [ $? -eq 2 ]; then # exit code of git ls-remote is 2 if branch does not exist
git checkout --orphan gh-pages
else # error occurred
exit $?
fi
# Exit if there are no changes to gh-pages files.
if changes=$(git status --porcelain) && [ -z "$changes" ]; then
echo 'No changes to GitHub Pages files; exiting.'
exit 0
fi
git add -A .
git commit -m "Rebuild pages at $COMMIT"
git push --quiet upstream HEAD:gh-pages