mina 1.2.3 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +26 -0
  3. data/.gitignore +0 -1
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +28 -1126
  6. data/CHANGELOG.md +126 -3
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +73 -0
  9. data/Rakefile +2 -0
  10. data/Readme.md +8 -12
  11. data/bin/mina +2 -0
  12. data/data/deploy.rb +10 -6
  13. data/docs/3rd_party_plugins.md +3 -0
  14. data/docs/assets/images/mina.png +0 -0
  15. data/docs/cookbook.md +1 -1
  16. data/docs/default_plugins.md +5 -5
  17. data/docs/how_mina_works.md +3 -3
  18. data/lib/Minafile +1 -0
  19. data/lib/mina/application.rb +45 -35
  20. data/lib/mina/backend/local.rb +2 -0
  21. data/lib/mina/backend/remote.rb +3 -1
  22. data/lib/mina/commands.rb +10 -7
  23. data/lib/mina/configuration.rb +6 -3
  24. data/lib/mina/dsl.rb +2 -2
  25. data/lib/mina/helpers/internal.rb +9 -9
  26. data/lib/mina/helpers/output.rb +5 -3
  27. data/lib/mina/runner/exec.rb +2 -0
  28. data/lib/mina/runner/pretty.rb +25 -19
  29. data/lib/mina/runner/printer.rb +2 -0
  30. data/lib/mina/runner/system.rb +2 -0
  31. data/lib/mina/runner.rb +9 -10
  32. data/lib/mina/version.rb +3 -1
  33. data/lib/mina/windows_patches.rb +4 -2
  34. data/lib/mina.rb +4 -3
  35. data/mina.gemspec +8 -7
  36. data/spec/configs/default.rb +8 -0
  37. data/spec/configs/dsl.rb +55 -0
  38. data/spec/configs/e2e.rb +25 -0
  39. data/spec/e2e/docker-compose.yml +21 -0
  40. data/spec/e2e/e2e_run.sh +11 -0
  41. data/spec/e2e/e2e_spec.rb +35 -0
  42. data/spec/e2e/ssh +27 -0
  43. data/spec/e2e/ssh.pub +1 -0
  44. data/spec/lib/mina/application_spec.rb +94 -35
  45. data/spec/lib/mina/backend/local_spec.rb +5 -2
  46. data/spec/lib/mina/backend/remote_spec.rb +5 -3
  47. data/spec/lib/mina/commands_spec.rb +7 -7
  48. data/spec/lib/mina/configuration_spec.rb +63 -3
  49. data/spec/lib/mina/dsl_spec.rb +94 -0
  50. data/spec/lib/mina/helpers/internal_spec.rb +89 -11
  51. data/spec/lib/mina/helpers/output_spec.rb +13 -10
  52. data/spec/lib/mina/runner/exec_spec.rb +19 -0
  53. data/spec/lib/mina/runner/pretty_spec.rb +17 -0
  54. data/spec/lib/mina/runner/printer_spec.rb +19 -0
  55. data/spec/lib/mina/runner/system_spec.rb +19 -0
  56. data/spec/lib/mina/runner_spec.rb +6 -10
  57. data/spec/spec_helper.rb +33 -14
  58. data/spec/support/outputs/bundle_clean.txt +2 -2
  59. data/spec/support/outputs/chruby_with_env.txt +7 -0
  60. data/spec/support/outputs/chruby_without_env.txt +2 -0
  61. data/spec/support/outputs/debug_configuration_variables.txt +11 -0
  62. data/spec/support/outputs/dsl_deploy.txt +4 -0
  63. data/spec/support/outputs/dsl_in_path.txt +1 -0
  64. data/spec/support/outputs/dsl_local_run.txt +5 -0
  65. data/spec/support/outputs/dsl_on.txt +6 -0
  66. data/spec/support/outputs/dsl_remote_run.txt +5 -0
  67. data/spec/support/outputs/dsl_reset.txt +2 -0
  68. data/spec/support/outputs/e2e_deploy_after_setup.txt +1 -0
  69. data/spec/support/outputs/e2e_deploy_without_setup.txt +1 -0
  70. data/spec/support/outputs/e2e_setup.txt +1 -0
  71. data/spec/support/outputs/environment.txt +1 -0
  72. data/spec/support/outputs/git_clone.txt +1 -1
  73. data/spec/support/outputs/git_clone_commit.txt +1 -1
  74. data/spec/support/outputs/git_ensure_pushed.txt +15 -0
  75. data/spec/support/outputs/rails_assets_precompile_force_precompile.txt +2 -0
  76. data/spec/support/outputs/rails_assets_precompile_outside_deploy_block.txt +1 -0
  77. data/spec/support/outputs/rails_assets_precompile_with_diff.txt +7 -0
  78. data/spec/support/outputs/rails_console.txt +1 -0
  79. data/spec/support/outputs/rails_db_migrate_force_migrate.txt +2 -0
  80. data/spec/support/outputs/rails_db_migrate_outside_deploy_block.txt +1 -0
  81. data/spec/support/outputs/rails_db_migrate_with_diff.txt +7 -0
  82. data/spec/support/outputs/rails_log.txt +1 -0
  83. data/spec/support/outputs/rails_with_arguments.txt +1 -0
  84. data/spec/support/outputs/rails_without_arguments.txt +1 -0
  85. data/spec/support/outputs/rake_with_arguments.txt +1 -0
  86. data/spec/support/outputs/rake_without_arguments.txt +1 -0
  87. data/spec/support/outputs/rbenv_load.txt +9 -1
  88. data/spec/support/outputs/rvm_use_with_env.txt +8 -0
  89. data/spec/support/outputs/rvm_use_without_env.txt +2 -0
  90. data/spec/support/outputs/rvm_wrapper_with_arguments.txt +8 -0
  91. data/spec/support/outputs/rvm_wrapper_without_arguments.txt +2 -0
  92. data/spec/support/outputs/ry_with_env.txt +13 -0
  93. data/spec/support/outputs/ry_without_env.txt +13 -0
  94. data/spec/support/outputs/ssh.txt +1 -0
  95. data/spec/support/outputs/ssh_keyscan_domain.txt +3 -0
  96. data/spec/support/rake_example_group.rb +23 -19
  97. data/spec/tasks/bundler_spec.rb +6 -0
  98. data/spec/tasks/chruby_spec.rb +29 -0
  99. data/spec/tasks/default_spec.rb +79 -7
  100. data/spec/tasks/deploy_spec.rb +6 -0
  101. data/spec/tasks/git_spec.rb +12 -0
  102. data/spec/tasks/init_spec.rb +13 -4
  103. data/spec/tasks/rails_spec.rb +126 -15
  104. data/spec/tasks/rbenv_spec.rb +15 -0
  105. data/spec/tasks/rvm_spec.rb +51 -0
  106. data/spec/tasks/ry_spec.rb +43 -0
  107. data/tasks/mina/bundler.rb +7 -5
  108. data/tasks/mina/chruby.rb +7 -5
  109. data/tasks/mina/default.rb +19 -12
  110. data/tasks/mina/deploy.rb +27 -25
  111. data/tasks/mina/git.rb +28 -15
  112. data/tasks/mina/install.rb +9 -0
  113. data/tasks/mina/rails.rb +29 -27
  114. data/tasks/mina/rbenv.rb +8 -6
  115. data/tasks/mina/rvm.rb +13 -11
  116. data/tasks/mina/ry.rb +11 -11
  117. data/test_env/config/deploy.rb +9 -8
  118. metadata +69 -37
  119. data/spec/support/outputs/chruby.txt +0 -9
  120. data/spec/support/outputs/console.txt +0 -1
  121. data/spec/support/outputs/log.txt +0 -1
  122. data/spec/support/outputs/rails_db_migrate.txt +0 -1
  123. data/spec/support/outputs/rvm_use.txt +0 -1
  124. data/spec/support/outputs/ry.txt +0 -15
  125. data/spec/tasks/ruby_managers_spec.rb +0 -33
@@ -1,23 +1,63 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'rails', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'console' do
5
11
  it 'starts console' do
6
- expect { invoke_all }.to output(output_file('console')).to_stdout
12
+ expect { invoke_all }.to output(output_file('rails_console')).to_stdout
7
13
  end
8
14
  end
9
15
 
10
16
  describe 'log' do
11
17
  it 'tails log' do
12
- expect { invoke_all }.to output(output_file('log')).to_stdout
18
+ expect { invoke_all }.to output(output_file('rails_log')).to_stdout
13
19
  end
14
20
  end
15
21
 
16
22
  describe 'rails:db_migrate' do
17
- it 'rails db migrate' do
18
- Mina::Configuration.instance.set(:deploy_block, true)
19
- expect { invoke_all }.to output(output_file('rails_db_migrate')).to_stdout
20
- Mina::Configuration.instance.set(:deploy_block, false)
23
+ let(:task_name) { 'rails:db_migrate' }
24
+
25
+ context 'when outside deploy block' do
26
+ before do
27
+ Mina::Configuration.instance.remove(:deploy_block)
28
+ end
29
+
30
+ it 'exits with an error message' do
31
+ expect do
32
+ invoke_all
33
+ end.to raise_error(SystemExit)
34
+ .and output(output_file('rails_db_migrate_outside_deploy_block')).to_stdout
35
+ end
36
+ end
37
+
38
+ context 'with force_migrate flag' do
39
+ before do
40
+ Mina::Configuration.instance.set(:force_migrate, true)
41
+ Mina::Configuration.instance.set(:deploy_block, true)
42
+ end
43
+
44
+ it 'runs rails db:migrate' do
45
+ expect do
46
+ invoke_all
47
+ end.to output(output_file('rails_db_migrate_force_migrate')).to_stdout
48
+ end
49
+ end
50
+
51
+ context 'without force_migrate flag' do
52
+ before do
53
+ Mina::Configuration.instance.set(:deploy_block, true)
54
+ end
55
+
56
+ it 'runs rails db:migrate but checks for changes first' do
57
+ expect do
58
+ invoke_all
59
+ end.to output(output_file('rails_db_migrate_with_diff')).to_stdout
60
+ end
21
61
  end
22
62
  end
23
63
 
@@ -34,10 +74,44 @@ RSpec.describe 'rails', type: :rake do
34
74
  end
35
75
 
36
76
  describe 'rails:assets_precompile' do
37
- it 'rails assets precompile' do
38
- Mina::Configuration.instance.set(:deploy_block, true)
39
- expect { invoke_all }.to output(output_file('rails_assets_precompile')).to_stdout
40
- Mina::Configuration.instance.set(:deploy_block, false)
77
+ let(:task_name) { 'rails:assets_precompile' }
78
+
79
+ context 'when outside deploy block' do
80
+ before do
81
+ Mina::Configuration.instance.remove(:deploy_block)
82
+ end
83
+
84
+ it 'exits with an error message' do
85
+ expect do
86
+ invoke_all
87
+ end.to raise_error(SystemExit)
88
+ .and output(output_file('rails_assets_precompile_outside_deploy_block')).to_stdout
89
+ end
90
+ end
91
+
92
+ context 'with force_asset_precompile flag' do
93
+ before do
94
+ Mina::Configuration.instance.set(:force_asset_precompile, true)
95
+ Mina::Configuration.instance.set(:deploy_block, true)
96
+ end
97
+
98
+ it 'runs rails assets:precompile' do
99
+ expect do
100
+ invoke_all
101
+ end.to output(output_file('rails_assets_precompile_force_precompile')).to_stdout
102
+ end
103
+ end
104
+
105
+ context 'without force_asset_precompile flag' do
106
+ before do
107
+ Mina::Configuration.instance.set(:deploy_block, true)
108
+ end
109
+
110
+ it 'runs rails assets:precompile but checks for changes first' do
111
+ expect do
112
+ invoke_all
113
+ end.to output(output_file('rails_assets_precompile_with_diff')).to_stdout
114
+ end
41
115
  end
42
116
  end
43
117
 
@@ -52,9 +126,46 @@ RSpec.describe 'rails', type: :rake do
52
126
  expect { invoke_all }.to output(output_file('rails_db_schema_load')).to_stdout
53
127
  end
54
128
  end
55
- # describe 'rollback' do
56
- # it 'rollback' do
57
- # expect { invoke_all }.to output(output_file('rollback')).to_stdout
58
- # end
59
- # end
129
+
130
+ describe 'rails' do
131
+ let(:task_name) { 'rails' }
132
+
133
+ context 'without arguments' do
134
+ it 'exits with an error message' do
135
+ expect do
136
+ invoke_all
137
+ end.to raise_error(SystemExit)
138
+ .and output(output_file('rails_without_arguments')).to_stdout
139
+ end
140
+ end
141
+
142
+ context 'with arguments' do
143
+ it 'executes the arguments' do
144
+ expect do
145
+ invoke_all('db:rollback STEP=2')
146
+ end.to output(output_file('rails_with_arguments')).to_stdout
147
+ end
148
+ end
149
+ end
150
+
151
+ describe 'rake' do
152
+ let(:task_name) { 'rake' }
153
+
154
+ context 'without arguments' do
155
+ it 'exits with an error message' do
156
+ expect do
157
+ invoke_all
158
+ end.to raise_error(SystemExit)
159
+ .and output(output_file('rake_without_arguments')).to_stdout
160
+ end
161
+ end
162
+
163
+ context 'with arguments' do
164
+ it 'executes the arguments' do
165
+ expect do
166
+ invoke_all('db:primary:migrate')
167
+ end.to output(output_file('rake_with_arguments')).to_stdout
168
+ end
169
+ end
170
+ end
60
171
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'rbenv', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'rbenv:load' do
11
+ it 'loads rbenv' do
12
+ expect { invoke_all }.to output(output_file('rbenv_load')).to_stdout
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'rvm', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'rvm:use' do
11
+ let(:task_name) { 'rvm:use' }
12
+
13
+ context 'without an argument' do
14
+ it 'exits with an error message' do
15
+ expect do
16
+ invoke_all
17
+ end.to raise_error(SystemExit)
18
+ .and output(output_file('rvm_use_without_env')).to_stdout
19
+ end
20
+ end
21
+
22
+ context 'with an argument' do
23
+ it 'sets ruby version' do
24
+ expect do
25
+ invoke_all('3.0.0')
26
+ end.to output(output_file('rvm_use_with_env')).to_stdout
27
+ end
28
+ end
29
+ end
30
+
31
+ describe 'rvm:wrapper' do
32
+ let(:task_name) { 'rvm:wrapper' }
33
+
34
+ context 'without all arguments' do
35
+ it 'exits with an error message' do
36
+ expect do
37
+ invoke_all('ruby-3.0.0')
38
+ end.to raise_error(SystemExit)
39
+ .and output(output_file('rvm_wrapper_without_arguments')).to_stdout
40
+ end
41
+ end
42
+
43
+ context 'with all arguments' do
44
+ it 'calls rvm wrapper' do
45
+ expect do
46
+ invoke_all('3.0.0', 'myapp', 'unicorn')
47
+ end.to output(output_file('rvm_wrapper_with_arguments')).to_stdout
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'ry', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'ry' do
11
+ let(:task_name) { 'ry' }
12
+
13
+ let(:default_version_warning) { /Task 'ry' without argument will use default Ruby version\./ }
14
+
15
+ context 'without an argument' do
16
+ it 'prints a warning' do
17
+ expect do
18
+ invoke_all
19
+ end.to output(default_version_warning).to_stdout
20
+ end
21
+
22
+ it 'sets ruby version' do
23
+ expect do
24
+ invoke_all
25
+ end.to output(output_file('ry_without_env')).to_stdout
26
+ end
27
+ end
28
+
29
+ context 'with an argument' do
30
+ it "doesn't print a warning" do
31
+ expect do
32
+ invoke_all('3.0.0')
33
+ end.not_to output(default_version_warning).to_stdout
34
+ end
35
+ end
36
+
37
+ it 'sets ruby version' do
38
+ expect do
39
+ invoke_all('3.0.0')
40
+ end.to output(output_file('ry_with_env')).to_stdout
41
+ end
42
+ end
43
+ end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mina/default'
2
4
 
3
5
  set :bundle_bin, 'bundle'
4
6
  set :bundle_path, 'vendor/bundle'
5
7
  set :bundle_withouts, 'development test'
6
- set :bundle_options, -> { %{--without #{fetch(:bundle_withouts)} --path "#{fetch(:bundle_path)}" --deployment} }
8
+ set :bundle_options, -> { %(--without #{fetch(:bundle_withouts)} --path "#{fetch(:bundle_path)}" --deployment) }
7
9
  set :shared_dirs, fetch(:shared_dirs, []).push(fetch(:bundle_path))
8
10
 
9
11
  namespace :bundle do
10
12
  desc 'Install gem dependencies using Bundler.'
11
13
  task :install do
12
- comment %{Installing gem dependencies using Bundler}
13
- command %{#{fetch(:bundle_bin)} install #{fetch(:bundle_options)}}
14
+ comment %(Installing gem dependencies using Bundler)
15
+ command %(#{fetch(:bundle_bin)} install #{fetch(:bundle_options)})
14
16
  end
15
17
 
16
18
  desc 'Cleans up unused gems in your bundler directory'
17
19
  task :clean do
18
- comment %{Cleans up unsed gems}
19
- command %{#{fetch(:bundle_bin)} clean #{fetch(:bundle_options)}}
20
+ comment %(Cleaning up unused gems)
21
+ command %(#{fetch(:bundle_bin)} clean)
20
22
  end
21
23
  end
data/tasks/mina/chruby.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  set :chruby_path, '/etc/profile.d/chruby.sh'
2
4
 
3
5
  task :chruby, :env do |_, args|
@@ -7,13 +9,13 @@ task :chruby, :env do |_, args|
7
9
  exit 1
8
10
  end
9
11
 
10
- comment %{chruby to version: \\"#{args[:env]}\\"}
11
- command %{
12
+ comment %(chruby to version: \\"#{args[:env]}\\")
13
+ command %(
12
14
  if [[ ! -s "#{fetch(:chruby_path)}" ]]; then
13
15
  echo "! chruby.sh init file not found"
14
16
  exit 1
15
17
  fi
16
- }
17
- command %{source #{fetch(:chruby_path)}}
18
- command %{chruby "#{args[:env]}" || exit 1}
18
+ )
19
+ command %(source #{fetch(:chruby_path)})
20
+ command %(chruby "#{args[:env]}" || exit 1)
19
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mina/install'
2
4
 
3
5
  set :port, 22
@@ -32,27 +34,28 @@ end
32
34
 
33
35
  task :debug_configuration_variables do
34
36
  if fetch(:debug_configuration_variables)
35
- puts
36
- puts '------- Printing current config variables -------'
37
- configuration.variables.each do |key, value|
38
- puts "#{key.inspect} => #{value.inspect}"
37
+ puts '========== Configuration variables =========='
38
+ configuration.variables.each_key do |key|
39
+ puts "#{key.inspect} => #{fetch(key).inspect}"
39
40
  end
41
+ puts '========== Configuration variables =========='
42
+ puts
40
43
  end
41
44
  end
42
45
 
43
46
  desc 'Adds repo host to the known hosts'
44
47
  task :ssh_keyscan_repo do
45
48
  ensure!(:repository)
46
- repo_host = fetch(:repository).split(%r{@|://}).last.split(%r{:|\/}).first
49
+ repo_host = fetch(:repository).split(%r{@|://}).last.split(%r{:|/}).first
47
50
  repo_port = /:([0-9]+)/.match(fetch(:repository)) && /:([0-9]+)/.match(fetch(:repository))[1] || '22'
48
51
 
49
- next if repo_host == ""
52
+ next if repo_host == ''
50
53
 
51
- command %{
54
+ command %(
52
55
  if ! ssh-keygen -H -F #{repo_host} &>/dev/null; then
53
56
  ssh-keyscan -t rsa -p #{repo_port} -H #{repo_host} >> ~/.ssh/known_hosts
54
57
  fi
55
- }
58
+ )
56
59
  end
57
60
 
58
61
  desc 'Adds domain to the known hosts'
@@ -60,11 +63,11 @@ task :ssh_keyscan_domain do
60
63
  ensure!(:domain)
61
64
  ensure!(:port)
62
65
  run :local do
63
- command %{
66
+ command %(
64
67
  if ! ssh-keygen -H -F #{fetch(:domain)} &>/dev/null; then
65
68
  ssh-keyscan -p #{fetch(:port)} #{fetch(:domain)} >> ~/.ssh/known_hosts
66
69
  fi
67
- }
70
+ )
68
71
  end
69
72
  end
70
73
 
@@ -83,7 +86,11 @@ task :run, [:command] do |_, args|
83
86
  end
84
87
  end
85
88
 
86
- desc 'Open an ssh session to the server and cd to deploy_to folder'
89
+ desc 'Open an SSH connection and position to :deploy_to folder'
87
90
  task :ssh do
88
- exec %{#{Mina::Backend::Remote.new(nil).ssh} 'cd #{fetch(:deploy_to)} && exec $SHELL'}
91
+ ensure!(:deploy_to)
92
+
93
+ set :execution_mode, :exec
94
+
95
+ command "cd #{fetch(:deploy_to)} && exec $SHELL"
89
96
  end
data/tasks/mina/deploy.rb CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mina/default'
2
4
 
3
5
  set :releases_path, -> { "#{fetch(:deploy_to)}/releases" }
4
6
  set :shared_path, -> { "#{fetch(:deploy_to)}/shared" }
5
7
  set :current_path, -> { "#{fetch(:deploy_to)}/current" }
6
8
  set :lock_file, 'deploy.lock'
7
- set :deploy_script, 'data/deploy.sh.erb'
9
+ set :deploy_script, Mina.root_path('data/deploy.sh.erb')
8
10
  set :keep_releases, 5
9
11
  set :version_scheme, :sequence
10
12
  set :execution_mode, :pretty
@@ -12,30 +14,30 @@ set :execution_mode, :pretty
12
14
  namespace :deploy do
13
15
  desc 'Forces a deploy unlock.'
14
16
  task :force_unlock do
15
- comment %{Unlocking}
16
- command %{rm -f "#{fetch(:deploy_to)}/#{fetch(:lock_file)}"}
17
+ comment %(Unlocking)
18
+ command %(rm -f "#{fetch(:deploy_to)}/#{fetch(:lock_file)}")
17
19
  end
18
20
 
19
21
  desc 'Links paths set in :shared_dirs and :shared_files.'
20
22
  task :link_shared_paths do
21
- comment %{Symlinking shared paths}
23
+ comment %(Symlinking shared paths)
22
24
 
23
25
  fetch(:shared_dirs, []).each do |linked_dir|
24
- command %{
26
+ command %(
25
27
  if [ ! -d "#{fetch(:shared_path)}/#{linked_dir}" ]; then
26
28
  echo "! ERROR: not set up."
27
29
  echo "The directory '#{fetch(:shared_path)}/#{linked_dir}' does not exist on the server"
28
30
  echo "You may need to run 'mina setup' first"
29
31
  exit 18
30
32
  fi
31
- }
32
- command %{mkdir -p #{File.dirname("./#{linked_dir}")}}
33
- command %{rm -rf "./#{linked_dir}"}
34
- command %{ln -s "#{fetch(:shared_path)}/#{linked_dir}" "./#{linked_dir}"}
33
+ )
34
+ command %(mkdir -p #{File.dirname("./#{linked_dir}")})
35
+ command %(rm -rf "./#{linked_dir}")
36
+ command %(ln -s "#{fetch(:shared_path)}/#{linked_dir}" "./#{linked_dir}")
35
37
  end
36
38
 
37
39
  fetch(:shared_files, []).each do |linked_path|
38
- command %{ln -sf "#{fetch(:shared_path)}/#{linked_path}" "./#{linked_path}"}
40
+ command %(ln -sf "#{fetch(:shared_path)}/#{linked_path}" "./#{linked_path}")
39
41
  end
40
42
  end
41
43
 
@@ -45,26 +47,26 @@ namespace :deploy do
45
47
  ensure!(:deploy_to)
46
48
 
47
49
  comment %{Cleaning up old releases (keeping #{fetch(:keep_releases)})}
48
- in_path "#{fetch(:releases_path)}" do
50
+ in_path fetch(:releases_path) do
49
51
  command %{count=$(ls -A1 | sort -rn | wc -l)}
50
52
  command %{remove=$((count > #{fetch(:keep_releases)} ? count - #{fetch(:keep_releases)} : 0))}
51
- command %{ls -A1 | sort -rn | tail -n $remove | xargs rm -rf {}}
53
+ command %(ls -A1 | sort -rn | tail -n $remove | xargs rm -rf {})
52
54
  end
53
55
  end
54
56
  end
55
57
 
56
58
  desc 'Rollbacks the latest release'
57
59
  task :rollback do
58
- comment %{Rolling back to previous release}
60
+ comment %(Rolling back to previous release)
59
61
 
60
- in_path "#{fetch(:releases_path)}" do
62
+ in_path fetch(:releases_path) do
61
63
  # TODO: add check if there are more than 1 release
62
64
  command %{rollback_release=$(ls -1A | sort -n | tail -n 2 | head -n 1)}
63
- comment %{Rollbacking to release: $rollback_release}
64
- command %{ln -nfs #{fetch(:releases_path)}/$rollback_release #{fetch(:current_path)}}
65
+ comment %(Rollbacking to release: $rollback_release)
66
+ command %(ln -nfs #{fetch(:releases_path)}/$rollback_release #{fetch(:current_path)})
65
67
  command %{current_release=$(ls -1A | sort -n | tail -n 1)}
66
- comment %{Deleting current release: $current_release}
67
- command %{rm -rf #{fetch(:releases_path)}/$current_release}
68
+ comment %(Deleting current release: $current_release)
69
+ command %(rm -rf #{fetch(:releases_path)}/$current_release)
68
70
  end
69
71
  end
70
72
 
@@ -72,17 +74,17 @@ desc 'Sets up a site.'
72
74
  task :setup do
73
75
  ensure!(:deploy_to)
74
76
 
75
- comment %{Setting up #{fetch(:deploy_to)}}
76
- command %{mkdir -p "#{fetch(:deploy_to)}"}
77
- command %{mkdir -p "#{fetch(:releases_path)}"}
78
- command %{mkdir -p "#{fetch(:shared_path)}"}
77
+ comment %(Setting up #{fetch(:deploy_to)})
78
+ command %(mkdir -p "#{fetch(:deploy_to)}")
79
+ command %(mkdir -p "#{fetch(:releases_path)}")
80
+ command %(mkdir -p "#{fetch(:shared_path)}")
79
81
 
80
- in_path "#{fetch(:shared_path)}" do
82
+ in_path fetch(:shared_path) do
81
83
  fetch(:shared_dirs, []).each do |linked_dir|
82
- command %{mkdir -p "#{linked_dir}"}
84
+ command %(mkdir -p "#{linked_dir}")
83
85
  end
84
86
  fetch(:shared_files, []).each do |linked_path|
85
- command %{mkdir -p "#{File.dirname(linked_path)}"}
87
+ command %(mkdir -p "#{File.dirname(linked_path)}")
86
88
  end
87
89
  end
88
90
 
data/tasks/mina/git.rb CHANGED
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mina/default'
2
4
 
3
5
  set :branch, 'master'
4
6
  set :remove_git_dir, true
5
7
  set :remote, 'origin'
6
8
  set :git_not_pushed_message, -> { "Your branch #{fetch(:branch)} needs to be pushed to #{fetch(:remote)} before deploying" }
9
+ set :git_local_branch_missing_message, -> { "Branch #{fetch(:branch)} doesn't exist" }
10
+ set :git_remote_branch_missing_message, -> { "Branch #{fetch(:remote)}/#{fetch(:branch)} doesn't exist" }
7
11
 
8
12
  namespace :git do
9
13
  desc 'Clones the Git repository to the current path.'
@@ -11,42 +15,51 @@ namespace :git do
11
15
  ensure!(:repository)
12
16
  ensure!(:deploy_to)
13
17
  if set?(:commit)
14
- comment %{Using git commit \\"#{fetch(:commit)}\\"}
15
- command %{git clone "#{fetch(:repository)}" . --recursive}
16
- command %{git checkout -b current_release "#{fetch(:commit)}" --force}
18
+ comment %(Using git commit \\"#{fetch(:commit)}\\")
19
+ command %(git clone "#{fetch(:repository)}" . --recursive)
20
+ command %(git checkout -b current_release "#{fetch(:commit)}" --force)
17
21
  else
18
- command %{
22
+ command %(
19
23
  if [ ! -d "#{fetch(:deploy_to)}/scm/objects" ]; then
20
24
  echo "-----> Cloning the Git repository"
21
- #{echo_cmd %[git clone "#{fetch(:repository)}" "#{fetch(:deploy_to)}/scm" --bare]}
25
+ #{echo_cmd %(git clone "#{fetch(:repository)}" "#{fetch(:deploy_to)}/scm" --bare)}
22
26
  else
23
27
  echo "-----> Fetching new git commits"
24
28
  #{echo_cmd %[(cd "#{fetch(:deploy_to)}/scm" && git fetch "#{fetch(:repository)}" "#{fetch(:branch)}:#{fetch(:branch)}" --force)]}
25
29
  fi &&
26
30
  echo "-----> Using git branch '#{fetch(:branch)}'" &&
27
- #{echo_cmd %[git clone "#{fetch(:deploy_to)}/scm" . --recursive --branch "#{fetch(:branch)}"]}
28
- }, quiet: true
31
+ #{echo_cmd %(git clone "#{fetch(:deploy_to)}/scm" . --recursive --branch "#{fetch(:branch)}")}
32
+ ), quiet: true
29
33
  end
30
-
31
- comment %{Using this git commit}
32
- command %{git rev-parse HEAD > .mina_git_revision}
34
+ comment %(Updating submodules)
35
+ command %(git submodule update)
36
+ comment %(Using this git commit)
37
+ command %(git rev-parse HEAD > .mina_git_revision)
33
38
  command %{git --no-pager log --format="%aN (%h):%n> %s" -n 1}
34
- if fetch(:remove_git_dir)
35
- command %{rm -rf .git}
36
- end
39
+ command %(rm -rf .git) if fetch(:remove_git_dir)
37
40
  end
38
41
 
39
42
  desc 'Prints out current revision'
40
43
  task :revision do
41
44
  ensure!(:deploy_to)
42
- command %{cat #{fetch(:current_path)}/.mina_git_revision}
45
+ command %(cat #{fetch(:current_path)}/.mina_git_revision)
43
46
  end
44
47
 
45
48
  desc 'Ensures local repository is pushed to remote'
46
49
  task :ensure_pushed do
47
50
  run :local do
48
- comment %{Ensuring everyting is pushed to git}
51
+ comment %(Ensuring everything is pushed to git)
49
52
  command %{
53
+ if [ $(git branch --list #{fetch(:branch)} | wc -l) -eq 0 ]; then
54
+ echo "! #{fetch(:git_local_branch_missing_message)}"
55
+ exit 1
56
+ fi
57
+
58
+ if [ $(git branch -r --list #{fetch(:remote)}/#{fetch(:branch)} | wc -l) -eq 0 ]; then
59
+ echo "! #{fetch(:git_remote_branch_missing_message)}"
60
+ exit 1
61
+ fi
62
+
50
63
  if [ $(git log #{fetch(:remote)}/#{fetch(:branch)}..#{fetch(:branch)} | wc -l) -ne 0 ]; then
51
64
  echo "! #{fetch(:git_not_pushed_message)}"
52
65
  exit 1
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  desc 'Creates a sample config file.'
2
4
  task :init do
3
5
  name = Rake.application.name
@@ -9,6 +11,13 @@ task :init do
9
11
  end
10
12
 
11
13
  outfile = './config/deploy.rb'
14
+
15
+ if File.exist?(outfile)
16
+ print 'deploy.rb already exists, do you want to overwrite it? (y/n) '
17
+
18
+ exit(8) if $stdin.readline.chomp.downcase != 'y'
19
+ end
20
+
12
21
  require 'fileutils'
13
22
  FileUtils.mkdir_p './config'
14
23
  FileUtils.cp Mina.root_path('data/deploy.rb'), outfile