Class: Takeoff::Stage::Heroku::PrecompileAndSyncAssets

Inherits:
Base
  • Object
show all
Defined in:
lib/takeoff/stage/heroku/precompile_and_sync_assets.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Helpers

#branches_up_to_date?, #diff, #execute, #file_has_changed_locally?, #files_have_changed?, #latest_commit, #log

Constructor Details

This class inherits a constructor from Takeoff::Stage::Base

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/takeoff/stage/heroku/precompile_and_sync_assets.rb', line 12

def call(env)
  unless run?(env)
    log "Skipping precompilation of assets"
    
    return @app.call(env)
  end

  begin
    log     "Precompiling assets"
    execute "RAILS_ENV=#{env[:environment]} bundle exec rake assets:precompile"

    log     "Syncing assets"
    execute "RAILS_ENV=#{env[:environment]} bundle exec rake assets:sync"

    if file_has_changed_locally?("public/assets/manifest-#{env[:environment]}.json")
      log     "Committing updated asset manifests"
      execute "git add public/assets/manifest-#{env[:environment]}.json"            
      execute "git commit -m 'Update asset manifest for #{env[:environment]}.' -m '[ci skip]'"

      log     "Pushing development branch to GitHub"
      execute "git push github #{env[:development_branch]}:#{env[:development_branch]} --force"
    end
  ensure
    log     "Deleting precompiled assets"
    execute "git ls-files -o --exclude-standard public/assets | xargs rm"
    # We can't use `rm -r ./public/assets` because we still need the manifest files.
  end

  @app.call(env)
end

#run?(env) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/takeoff/stage/heroku/precompile_and_sync_assets.rb', line 7

def run?(env)
  files = %w(app/assets lib/assets vendor/assets Gemfile.lock config/initializers/assets.rb)
  files_have_changed?(env[:deployed_commit], env[:new_commit], files)
end