-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
35 lines (30 loc) · 1.01 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
#!/bin/bash
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
target=$dir/build/site
deploy_branch=gh-pages
if [ "$1" ]; then token="$1"; fi
remote_url="https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY"
# author, date and message for deployment commit
name=$(git log -n 1 --format='%aN')
email=$(git log -n 1 --format='%aE')
author="$name <$email>"
date=$(git log -n 1 --format='%aD')
message="Built from $(git rev-parse --short HEAD)"
# create temp dir and clone deploy repository
tempdir=$(mktemp -d -p .)
if ! git clone --single-branch --branch "$deploy_branch" "$remote_url" "$tempdir"; then exit; fi
# change to deploy repository
cd "$tempdir"
# remove existing files
git rm -rf . &>/dev/null
# copy generated files
cp -R "$target/." .
status=$(git status --porcelain)
# if there are any changes
if [ "$status" != "" ]
then
git config user.email "$email"
git config user.name "$name"
git add --all && git commit --message="$message" --author="$author" --date="$date"
git push -q origin $deploy_branch
fi