forked from h5bp/html5-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_dist_directory.sh
executable file
·70 lines (52 loc) · 1.74 KB
/
update_dist_directory.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
69
70
#!/bin/bash
# [!] This script is intended for Travis. If the tests pass, Travis will
# automatically execute this script, regenerating the `dist` directory and
# committing any new changes to the `master` branch.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit_and_push_changes() {
# Check if there are unstaged changes, and
# if there are, commit and push them upstream
if [ $(git diff --exit-code > /dev/null; printf $?;) -eq 1 ]; then
git config --global user.email ${GH_USER_EMAIL} \
&& git config --global user.name ${GH_USER_NAME} \
&& git checkout master &> /dev/null \
&& git add -A \
&& git commit --message "Update content from the \`dist\` directory [skip ci]" > /dev/null \
&& git push --quiet "$(get_repository_url)" master > /dev/null
print_result $? "Commit and push changes"
fi
}
get_repository_url() {
printf "https://${GH_TOKEN}@$(git config --get remote.origin.url | sed 's/git:\/\///g')"
}
print_error() {
# Print output in red
printf "\e[0;31m [✖] $1\e[0m\n"
}
print_result() {
[ $1 -eq 0 ] \
&& print_success "$2" \
|| print_error "$2"
if [ $1 -ne 0 ]; then
exit 1
fi
}
print_success() {
# Print output in green
printf "\e[0;32m [✔] $1\e[0m\n"
}
update_content() {
npm -q install \
&& npm run build > /dev/null
print_result $? "Update content"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main() {
# Only execute the following if the
# changes were made in the `master` branch
if [ "$TRAVIS_BRANCH" == "master" ]; then
update_content
commit_and_push_changes
fi
}
main