Module: Deploy
- Defined in:
- lib/phase/tasks/deploy.rb
Constant Summary collapse
- VERSION_LOCKFILE_PATH =
"VERSION"
- VERSION_RBFILE_PATH =
"lib/harpoon/version.rb"
Class Method Summary collapse
- .ask(str) ⇒ Object
- .commit_deployment! ⇒ Object
- .current_version ⇒ Object
- .environment ⇒ Object
- .fail(str) ⇒ Object
- .log(str) ⇒ Object
- .precompile_assets ⇒ Object
- .raise_on_dirty_index! ⇒ Object
- .raise_on_incorrect_branch! ⇒ Object
- .stage_changes! ⇒ Object
- .sync_assets ⇒ Object
- .write_version(version_num) ⇒ Object
Class Method Details
.ask(str) ⇒ Object
44 45 46 47 |
# File 'lib/phase/tasks/deploy.rb', line 44 def ask(str) print "[deploy] ".green + str STDIN.gets.chomp end |
.commit_deployment! ⇒ Object
49 50 51 |
# File 'lib/phase/tasks/deploy.rb', line 49 def commit_deployment! system("git commit -m 'Preparing to release v#{ current_version }' -e") end |
.current_version ⇒ Object
53 54 55 56 57 |
# File 'lib/phase/tasks/deploy.rb', line 53 def current_version ::File.open(VERSION_LOCKFILE_PATH) do |file| file.read.chomp end end |
.environment ⇒ Object
59 60 61 |
# File 'lib/phase/tasks/deploy.rb', line 59 def environment ARGV[1] || "staging" end |
.fail(str) ⇒ Object
63 64 65 |
# File 'lib/phase/tasks/deploy.rb', line 63 def fail(str) abort("[deploy] error: ".red + str) end |
.log(str) ⇒ Object
67 68 69 |
# File 'lib/phase/tasks/deploy.rb', line 67 def log(str) puts "[deploy] ".green + str end |
.precompile_assets ⇒ Object
71 72 73 |
# File 'lib/phase/tasks/deploy.rb', line 71 def precompile_assets system("RAILS_GROUPS=assets RAILS_ENV=#{ environment } rake assets:precompile") end |
.raise_on_dirty_index! ⇒ Object
75 76 77 78 79 |
# File 'lib/phase/tasks/deploy.rb', line 75 def raise_on_dirty_index! unless system('git diff-index --quiet --cached HEAD') fail "other changes are already staged. Commit them or 'git reset HEAD' first." end end |
.raise_on_incorrect_branch! ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/phase/tasks/deploy.rb', line 81 def raise_on_incorrect_branch! current_branch = `git rev-parse --abbrev-ref HEAD`.chomp needed_branch = ::Deploy.environment == "staging" ? "develop" : "master" if current_branch != needed_branch fail "your current branch is #{current_branch}. Switch to #{needed_branch}." end end |
.stage_changes! ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/phase/tasks/deploy.rb', line 90 def stage_changes! files = [ ::Rails.root.join("public", ::Rails.application.config.assets.prefix, "manifest*.json"), ::Rails.root.join(::Deploy::VERSION_LOCKFILE_PATH), ::Rails.root.join(::Deploy::VERSION_RBFILE_PATH) ] system("git add #{ files.join(" ") }") end |
.sync_assets ⇒ Object
100 101 102 |
# File 'lib/phase/tasks/deploy.rb', line 100 def sync_assets system("RAILS_GROUPS=assets RAILS_ENV=#{ environment } rake assets:sync") end |
.write_version(version_num) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/phase/tasks/deploy.rb', line 104 def write_version(version_num) ::File.open(VERSION_LOCKFILE_PATH, 'w') do |file| file.write(version_num) end ::File.open(VERSION_RBFILE_PATH, 'w') do |file| file.write <<-VERSION.strip_heredoc module Harpoon VERSION = "#{version_num}" end VERSION end end |