Skip to content

Instantly share code, notes, and snippets.

@arunthampi
Created January 3, 2012 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arunthampi/1554094 to your computer and use it in GitHub Desktop.
Save arunthampi/1554094 to your computer and use it in GitHub Desktop.
Set Asset Fingerprint as part of the deployment workflow
def set_asset_fingerprint!
# -- First see if the files have changed
puts "-----> Calculating Asset Fingerprint"
fingerprint_method = "find public -type f -exec md5 {} + | awk '{print $0}' | sort | md5"
current_fingerprint = %x{#{fingerprint_method}}
fingerprint_file = Rails.root.join('assets.fingerprint')
if !File.exists?(fingerprint_file) || current_fingerprint != File.read(fingerprint_file)
execute("#{fingerprint_method} > #{fingerprint_file}")
# -- Add it to production
execute("git add #{fingerprint_file}")
# -- Commit it to production
execute("git commit -m 'Generating new asset fingerprint at #{DateTime.now.inspect}'")
puts "-----> Committing new assets fingerprint --> #{File.read(fingerprint_file)}"
end
puts "-----> Asset Fingerprint is #{File.read(fingerprint_file)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment