Created
October 24, 2013 18:57
-
-
Save gerhard/7142994 to your computer and use it in GitHub Desktop.
Asset packaging in Rails integrated with deliver
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
#!/usr/bin/env bash | |
set -e | |
production_tag="production" | |
current_build="$production_tag" | |
compiled_assets_commit_message="Compiled assets" | |
############################################################################## EXEC # | |
setup_dependencies() { | |
[[ $(hostname) =~ "local" ]] || bundle --local | |
} | |
get_previous_build() { | |
if [[ -z $previous_build ]] | |
then | |
previous_build="$(git rev-list $production_tag 2> /dev/null | head -1)" | |
if [[ -z $previous_build ]] | |
then | |
force_assets_compilation=true | |
fi | |
fi | |
} | |
run_tests() { | |
bundle exec rake | |
} | |
all_jenkins_tags() { | |
echo $(git tag -l 'jenkins*' | sort -k3 -t- -g -r) | |
} | |
tag_for_deploy() { | |
get_previous_build && git tag -f "$current_build" | |
} | |
force_assets_compilation() { | |
force_assets=true | |
} | |
if_assets_changed() { | |
local _assets_regex='\.(js|css|scss|less|png|jpg)$' | |
[[ $(git diff $previous_build..$current_build --name-only | grep -v "public/assets" | grep -cE $_assets_regex) != 0 ]] | |
} | |
use_compiled_assets() { | |
( [[ -n $force_assets_compilation ]] || if_assets_changed && compile_assets ) || most_recent_compiled_assets | |
tag_for_deploy | |
} | |
compile_assets() { | |
echo "Assets need compiling..." | |
bundle exec rake assets:precompile RAILS_GROUPS=development LOAD_RAILS=1 | |
git add public/assets | |
git commit -m "$compiled_assets_commit_message" | |
} | |
most_recent_compiled_assets() { | |
echo "Use the most recent compiled assets" | |
local _compiled_assets_commit="$(git reflog | grep "$compiled_assets_commit_message" | head -1 | cut -d' ' -f 1)" | |
git cherry-pick "$_compiled_assets_commit" | |
} | |
_deliver() { | |
REFSPEC=$current_build deliver --plain --verbose | |
} | |
########################################################################## MANIFEST # | |
setup_dependencies | |
run_tests | |
tag_for_deploy | |
use_compiled_assets | |
_deliver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment