-
Notifications
You must be signed in to change notification settings - Fork 87
/
build-commit.sh
executable file
·68 lines (56 loc) · 1.68 KB
/
build-commit.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
set -e
if [ $# -lt 1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo "Does a clean build of a specific git ref and commits to result to the local 'gh-pages' branch."
echo "Will NOT push the branch to GitHub, this will need to be done manually after the script completes."
echo ""
echo "Usage:"
echo " $(basename "$0") <ref>"
exit 1
fi
# Make temp dir and clean it up on exit
tmp="$( mktemp -d )"
function cleanup {
rm -rf "$tmp"
}
trap cleanup EXIT
resolved="$(git rev-parse "$1")"
repodir=$(dirname "$(readlink -f "$0")")
cd "$tmp"
echo "Cloning repo into a temp directory..."
git clone "$repodir" repo
cd repo
git -c advice.detachedHead=false checkout --detach "$resolved"
rm -rf dist
echo ""
echo "Installing deps..."
npm install
npx bower install
echo ""
echo "Building..."
npx grunt build
# We only want to commit files in the "dist" folder
# To do this, we move the "dist" folder up a level, then move the ".git" folder within it
echo ""
echo "Committing built files"
mv dist ..
if git rev-parse --quiet --verify origin/gh-pages >/dev/null; then
git checkout --force gh-pages
else
git checkout --orphan gh-pages
fi
mv .git ../dist
cd ../dist
if git diff --quiet --exit-code; then
echo ""
echo "No changes since the last build - nothing to commit"
exit 0
fi
# Commit the results and push them to the original repo
short="$(git rev-parse --short "$resolved")"
git add .
git commit -m "Deploy commit $short: $(git show -s --format=%s "$resolved")"
git push origin gh-pages
echo ""
echo "Commit '$short' has been built and committed locally to the 'gh-pages' branch"
echo "To publish the commit, push the gh-pages branch to GitHub"