Created
September 1, 2018 00:28
-
-
Save jpickwell/c5f1e538f047864283a54032c4825996 to your computer and use it in GitHub Desktop.
Revisions
-
jpickwell created this gist
Sep 1, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ This Capistrano task will loop through all of the repository files for the specified branch, and set the `atime` and `mtime` to the most recent (relative to each file) commit author date. I wrote this to get around a limitation in Webpacker 3.5.5 when deploying. Because of how Capistrano works, Webpacker would recompile every deploy even if no Webpack code had changed. This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ # ... # Use the task during deployment. after 'deploy:set_current_revision', :set_mtimes # ... This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ desc( 'Set the atime and mtime of all repo files based on the most recent' \ ' (relative to each file) commit author date.' ) task :set_mtimes do on release_roles :all do within repo_path do with fetch(:git_environmental_variables) do # Everything is done in a single `execute` to avoid numerous SSH # connections (one per file plus one to get the list of files). # # Because Capistrano uses `/usr/bin/env`, we need to "break out" of that # by giving it a command name and redirecting output to the null device. # `:echo` seems like the simplest and safest choice here. # # And because of SSHKit's `Symbol` quirk, the first argument must be a # `Symbol` to ensure `within` and `with` apply to the loop. execute( :echo, '> /dev/null ;', <<~CMD for path in $(git ls-tree --name-only -r "#{fetch(:branch)}"); do touch -t $(git log -1 --format=%ad --date=format:%Y%m%d%H%M.%S "#{fetch(:branch)}" -- "${path}") "#{release_path}/${path}" done CMD ) end end end end