forked from h5bp/html5-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Travis automatically update
dist
directory
Configure Travis to automatically update the content from the `dist` directory by executing a script¹ that will regenerate the content from the `dist` directory and commit any new changes to the `master` branch. This change will help in the development process by: * ensuring that the content from the `dist` directory is always in sync with the rest of the content * removing the need to execute the build step locally everytime a change is made (especially in the case of trivial changes, such as, typos) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ¹ The script (`bin/update_dist_directory.sh`) will only be executed if the tests pass, and will only run if the changes are made in the `master` branch. See also: http://docs.travis-ci.com/user/encryption-keys/ Close h5bp#1593
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters