mina 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +11 -3
  3. data/.gitignore +0 -1
  4. data/.rspec +1 -1
  5. data/.rubocop.yml +28 -1126
  6. data/CHANGELOG.md +89 -8
  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 +6 -4
  13. data/docs/3rd_party_plugins.md +1 -0
  14. data/docs/assets/images/mina.png +0 -0
  15. data/docs/default_plugins.md +1 -1
  16. data/docs/how_mina_works.md +2 -2
  17. data/lib/Minafile +1 -0
  18. data/lib/mina/application.rb +45 -35
  19. data/lib/mina/backend/local.rb +2 -0
  20. data/lib/mina/backend/remote.rb +3 -1
  21. data/lib/mina/commands.rb +10 -7
  22. data/lib/mina/configuration.rb +6 -3
  23. data/lib/mina/dsl.rb +2 -2
  24. data/lib/mina/helpers/internal.rb +8 -8
  25. data/lib/mina/helpers/output.rb +5 -3
  26. data/lib/mina/runner/exec.rb +2 -0
  27. data/lib/mina/runner/pretty.rb +25 -19
  28. data/lib/mina/runner/printer.rb +2 -0
  29. data/lib/mina/runner/system.rb +2 -0
  30. data/lib/mina/runner.rb +9 -10
  31. data/lib/mina/version.rb +3 -1
  32. data/lib/mina/windows_patches.rb +4 -2
  33. data/lib/mina.rb +4 -3
  34. data/mina.gemspec +8 -7
  35. data/spec/configs/default.rb +8 -0
  36. data/spec/configs/dsl.rb +55 -0
  37. data/spec/configs/e2e.rb +25 -0
  38. data/spec/e2e/docker-compose.yml +21 -0
  39. data/spec/e2e/e2e_run.sh +11 -0
  40. data/spec/e2e/e2e_spec.rb +35 -0
  41. data/spec/e2e/ssh +27 -0
  42. data/spec/e2e/ssh.pub +1 -0
  43. data/spec/lib/mina/application_spec.rb +94 -35
  44. data/spec/lib/mina/backend/local_spec.rb +5 -2
  45. data/spec/lib/mina/backend/remote_spec.rb +5 -3
  46. data/spec/lib/mina/commands_spec.rb +7 -7
  47. data/spec/lib/mina/configuration_spec.rb +63 -3
  48. data/spec/lib/mina/dsl_spec.rb +94 -0
  49. data/spec/lib/mina/helpers/internal_spec.rb +88 -10
  50. data/spec/lib/mina/helpers/output_spec.rb +13 -10
  51. data/spec/lib/mina/runner/exec_spec.rb +19 -0
  52. data/spec/lib/mina/runner/pretty_spec.rb +17 -0
  53. data/spec/lib/mina/runner/printer_spec.rb +19 -0
  54. data/spec/lib/mina/runner/system_spec.rb +19 -0
  55. data/spec/lib/mina/runner_spec.rb +6 -10
  56. data/spec/spec_helper.rb +33 -14
  57. data/spec/support/outputs/bundle_clean.txt +2 -2
  58. data/spec/support/outputs/chruby_with_env.txt +7 -0
  59. data/spec/support/outputs/chruby_without_env.txt +2 -0
  60. data/spec/support/outputs/debug_configuration_variables.txt +11 -0
  61. data/spec/support/outputs/dsl_deploy.txt +4 -0
  62. data/spec/support/outputs/dsl_in_path.txt +1 -0
  63. data/spec/support/outputs/dsl_local_run.txt +5 -0
  64. data/spec/support/outputs/dsl_on.txt +6 -0
  65. data/spec/support/outputs/dsl_remote_run.txt +5 -0
  66. data/spec/support/outputs/dsl_reset.txt +2 -0
  67. data/spec/support/outputs/e2e_deploy_after_setup.txt +1 -0
  68. data/spec/support/outputs/e2e_deploy_without_setup.txt +1 -0
  69. data/spec/support/outputs/e2e_setup.txt +1 -0
  70. data/spec/support/outputs/environment.txt +1 -0
  71. data/spec/support/outputs/git_ensure_pushed.txt +15 -0
  72. data/spec/support/outputs/rails_assets_precompile_force_precompile.txt +2 -0
  73. data/spec/support/outputs/rails_assets_precompile_outside_deploy_block.txt +1 -0
  74. data/spec/support/outputs/rails_assets_precompile_with_diff.txt +7 -0
  75. data/spec/support/outputs/rails_console.txt +1 -0
  76. data/spec/support/outputs/rails_db_migrate_force_migrate.txt +2 -0
  77. data/spec/support/outputs/rails_db_migrate_outside_deploy_block.txt +1 -0
  78. data/spec/support/outputs/rails_db_migrate_with_diff.txt +7 -0
  79. data/spec/support/outputs/rails_log.txt +1 -0
  80. data/spec/support/outputs/rails_with_arguments.txt +1 -0
  81. data/spec/support/outputs/rails_without_arguments.txt +1 -0
  82. data/spec/support/outputs/rake_with_arguments.txt +1 -0
  83. data/spec/support/outputs/rake_without_arguments.txt +1 -0
  84. data/spec/support/outputs/rbenv_load.txt +9 -1
  85. data/spec/support/outputs/rvm_use_with_env.txt +8 -0
  86. data/spec/support/outputs/rvm_use_without_env.txt +2 -0
  87. data/spec/support/outputs/rvm_wrapper_with_arguments.txt +8 -0
  88. data/spec/support/outputs/rvm_wrapper_without_arguments.txt +2 -0
  89. data/spec/support/outputs/ry_with_env.txt +13 -0
  90. data/spec/support/outputs/ry_without_env.txt +13 -0
  91. data/spec/support/outputs/ssh.txt +1 -0
  92. data/spec/support/outputs/ssh_keyscan_domain.txt +3 -0
  93. data/spec/support/rake_example_group.rb +23 -19
  94. data/spec/tasks/bundler_spec.rb +6 -0
  95. data/spec/tasks/chruby_spec.rb +29 -0
  96. data/spec/tasks/default_spec.rb +79 -7
  97. data/spec/tasks/deploy_spec.rb +6 -0
  98. data/spec/tasks/git_spec.rb +12 -0
  99. data/spec/tasks/init_spec.rb +13 -4
  100. data/spec/tasks/rails_spec.rb +126 -15
  101. data/spec/tasks/rbenv_spec.rb +15 -0
  102. data/spec/tasks/rvm_spec.rb +51 -0
  103. data/spec/tasks/ry_spec.rb +43 -0
  104. data/tasks/mina/bundler.rb +7 -5
  105. data/tasks/mina/chruby.rb +7 -5
  106. data/tasks/mina/default.rb +19 -12
  107. data/tasks/mina/deploy.rb +26 -24
  108. data/tasks/mina/git.rb +28 -16
  109. data/tasks/mina/install.rb +3 -1
  110. data/tasks/mina/rails.rb +29 -27
  111. data/tasks/mina/rbenv.rb +8 -6
  112. data/tasks/mina/rvm.rb +13 -11
  113. data/tasks/mina/ry.rb +11 -11
  114. data/test_env/config/deploy.rb +9 -8
  115. metadata +64 -32
  116. data/spec/support/outputs/chruby.txt +0 -9
  117. data/spec/support/outputs/console.txt +0 -1
  118. data/spec/support/outputs/log.txt +0 -1
  119. data/spec/support/outputs/rails_db_migrate.txt +0 -1
  120. data/spec/support/outputs/rvm_use.txt +0 -1
  121. data/spec/support/outputs/ry.txt +0 -15
  122. data/spec/tasks/ruby_managers_spec.rb +0 -33
@@ -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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mina/default'
2
4
 
3
5
  set :releases_path, -> { "#{fetch(:deploy_to)}/releases" }
@@ -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,43 +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
- comment %{Updating submodules}
31
- command %{git submodule update}
32
- comment %{Using this git commit}
33
- 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)
34
38
  command %{git --no-pager log --format="%aN (%h):%n> %s" -n 1}
35
- if fetch(:remove_git_dir)
36
- command %{rm -rf .git}
37
- end
39
+ command %(rm -rf .git) if fetch(:remove_git_dir)
38
40
  end
39
41
 
40
42
  desc 'Prints out current revision'
41
43
  task :revision do
42
44
  ensure!(:deploy_to)
43
- command %{cat #{fetch(:current_path)}/.mina_git_revision}
45
+ command %(cat #{fetch(:current_path)}/.mina_git_revision)
44
46
  end
45
47
 
46
48
  desc 'Ensures local repository is pushed to remote'
47
49
  task :ensure_pushed do
48
50
  run :local do
49
- comment %{Ensuring everything is pushed to git}
51
+ comment %(Ensuring everything is pushed to git)
50
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
+
51
63
  if [ $(git log #{fetch(:remote)}/#{fetch(:branch)}..#{fetch(:branch)} | wc -l) -ne 0 ]; then
52
64
  echo "! #{fetch(:git_not_pushed_message)}"
53
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
@@ -10,7 +12,7 @@ task :init do
10
12
 
11
13
  outfile = './config/deploy.rb'
12
14
 
13
- if File.exists?(outfile)
15
+ if File.exist?(outfile)
14
16
  print 'deploy.rb already exists, do you want to overwrite it? (y/n) '
15
17
 
16
18
  exit(8) if $stdin.readline.chomp.downcase != 'y'
data/tasks/mina/rails.rb CHANGED
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mina/deploy'
2
4
  require 'mina/bundler'
3
5
 
4
6
  set :rails_env, 'production'
5
- set :bundle_prefix, -> { %{RAILS_ENV="#{fetch(:rails_env)}" #{fetch(:bundle_bin)} exec} }
7
+ set :bundle_prefix, -> { %(RAILS_ENV="#{fetch(:rails_env)}" #{fetch(:bundle_bin)} exec) }
6
8
  set :rake, -> { "#{fetch(:bundle_prefix)} rake" }
7
9
  set :rails, -> { "#{fetch(:bundle_prefix)} rails" }
8
10
  set :compiled_asset_path, 'public/assets'
@@ -14,8 +16,8 @@ set :shared_dirs, fetch(:shared_dirs, []).push('log', 'tmp/cache', fetch(:compil
14
16
  desc 'Starts an interactive console.'
15
17
  task :console do
16
18
  set :execution_mode, :exec
17
- in_path "#{fetch(:current_path)}" do
18
- command %{#{fetch(:rails)} console}
19
+ in_path fetch(:current_path) do
20
+ command %(#{fetch(:rails)} console)
19
21
  end
20
22
  end
21
23
 
@@ -23,7 +25,7 @@ desc 'Tail log from server'
23
25
  task :log do
24
26
  set :execution_mode, :exec
25
27
  in_path "#{fetch(:shared_path)}/log" do
26
- command %{tail -f #{fetch(:rails_env)}.log}
28
+ command %(tail -f #{fetch(:rails_env)}.log)
27
29
  end
28
30
  end
29
31
 
@@ -32,72 +34,72 @@ namespace :rails do
32
34
  task :db_migrate do
33
35
  ensure!(:deploy_block, message: "Can't be run outside deploy do block. Please use mina 'rake[db_migrate]' instead")
34
36
  if fetch(:force_migrate)
35
- comment %{Migrating database}
36
- command %{#{fetch(:rake)} db:migrate}
37
+ comment %(Migrating database)
38
+ command %(#{fetch(:rake)} db:migrate)
37
39
  else
38
40
  command check_for_changes_script(
39
41
  at: fetch(:migration_dirs),
40
- skip: %{echo "-----> DB migrations unchanged; skipping DB migration"},
41
- changed: %{echo "-----> Migrating database"
42
- #{echo_cmd("#{fetch(:rake)} db:migrate")}}
42
+ skip: %(echo "-----> DB migrations unchanged; skipping DB migration"),
43
+ changed: %(echo "-----> Migrating database"
44
+ #{echo_cmd("#{fetch(:rake)} db:migrate")})
43
45
  ), quiet: true
44
46
  end
45
47
  end
46
48
 
47
49
  desc 'Create database'
48
50
  task :db_create do
49
- comment %{Creating database}
50
- command %{#{fetch(:rake)} db:create}
51
+ comment %(Creating database)
52
+ command %(#{fetch(:rake)} db:create)
51
53
  end
52
54
 
53
55
  desc 'Rollback database'
54
56
  task :db_rollback do
55
- comment %{Rollbacking database}
56
- command %{#{fetch(:rake)} db:rollback}
57
+ comment %(Rollbacking database)
58
+ command %(#{fetch(:rake)} db:rollback)
57
59
  end
58
60
 
59
61
  desc 'Precompiles assets (skips if nothing has changed since the last release).'
60
62
  task :assets_precompile do
61
63
  ensure!(:deploy_block, message: "Can't be run outside deploy do block. Please use mina 'rake[assets_precompile]' instead")
62
64
  if fetch(:force_asset_precompile)
63
- comment %{Precompiling asset files}
64
- command %{#{fetch(:rake)} assets:precompile}
65
+ comment %(Precompiling asset files)
66
+ command %(#{fetch(:rake)} assets:precompile)
65
67
  else
66
68
  command check_for_changes_script(
67
69
  at: fetch(:asset_dirs),
68
- skip: %{echo "-----> Skipping asset precompilation"},
69
- changed: %{echo "-----> Precompiling asset files"
70
- #{echo_cmd "#{fetch(:rake)} assets:precompile"}}
70
+ skip: %(echo "-----> Skipping asset precompilation"),
71
+ changed: %(echo "-----> Precompiling asset files"
72
+ #{echo_cmd "#{fetch(:rake)} assets:precompile"})
71
73
  ), quiet: true
72
74
  end
73
75
  end
74
76
 
75
77
  desc 'Clear older assets'
76
78
  task :assets_clean do
77
- comment %{Removing older assets}
78
- command %{#{fetch(:rake)} assets:clean}
79
+ comment %(Removing older assets)
80
+ command %(#{fetch(:rake)} assets:clean)
79
81
  end
80
82
 
81
83
  desc 'DB schema load'
82
84
  task :db_schema_load do
83
- comment %{DB schema load}
84
- command %{#{fetch(:rake)} db:schema:load}
85
+ comment %(DB schema load)
86
+ command %(#{fetch(:rake)} db:schema:load)
85
87
  end
86
88
  end
87
89
 
88
90
  def check_for_changes_script(options)
89
91
  diffs = options[:at].map do |path|
90
- %{diff -qrN "#{fetch(:current_path)}/#{path}" "./#{path}" 2>/dev/null}
92
+ %(diff -qrN "#{fetch(:current_path)}/#{path}" "./#{path}" 2>/dev/null)
91
93
  end.join(' && ')
92
94
 
93
- %{
95
+ %(
94
96
  if #{diffs}
95
97
  then
96
98
  #{options[:skip]}
97
99
  else
98
100
  #{options[:changed]}
99
101
  fi
100
- }
102
+ )
101
103
  end
102
104
 
103
105
  # Macro used later by :rails, :rake, etc
@@ -107,10 +109,10 @@ make_run_task = lambda { |name, example|
107
109
 
108
110
  arguments = args[:arguments]
109
111
  unless arguments
110
- puts %{You need to provide arguments. Try: mina "#{name}[#{example}]"}
112
+ puts %(You need to provide arguments. Try: mina "#{name}[#{example}]")
111
113
  exit 1
112
114
  end
113
- in_path "#{fetch(:current_path)}" do
115
+ in_path fetch(:current_path) do
114
116
  command %(#{fetch(name)} #{arguments})
115
117
  end
116
118
  end
data/tasks/mina/rbenv.rb CHANGED
@@ -1,15 +1,17 @@
1
- set :rbenv_path, "$HOME/.rbenv"
1
+ # frozen_string_literal: true
2
+
3
+ set :rbenv_path, '$HOME/.rbenv'
2
4
 
3
5
  task :'rbenv:load' do
4
- comment %{Loading rbenv}
5
- command %{export RBENV_ROOT="#{fetch(:rbenv_path)}"}
6
- command %{export PATH="#{fetch(:rbenv_path)}/bin:$PATH"}
7
- command %{
6
+ comment %(Loading rbenv)
7
+ command %(export RBENV_ROOT="#{fetch(:rbenv_path)}")
8
+ command %(export PATH="#{fetch(:rbenv_path)}/bin:$PATH")
9
+ command %(
8
10
  if ! which rbenv >/dev/null; then
9
11
  echo "! rbenv not found"
10
12
  echo "! If rbenv is installed, check your :rbenv_path setting."
11
13
  exit 1
12
14
  fi
13
- }
15
+ )
14
16
  command %{eval "$(rbenv init -)"}
15
17
  end
data/tasks/mina/rvm.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  set :rvm_use_path, '$HOME/.rvm/scripts/rvm'
2
4
 
3
5
  task :'rvm:use', :env do |_, args|
@@ -7,33 +9,33 @@ task :'rvm:use', :env do |_, args|
7
9
  exit 1
8
10
  end
9
11
 
10
- comment %{Using RVM environment \\\"#{args[:env]}\\\"}
11
- command %{
12
+ comment %(Using RVM environment \\\"#{args[:env]}\\\")
13
+ command %(
12
14
  if [[ ! -s "#{fetch(:rvm_use_path)}" ]]; then
13
15
  echo "! Ruby Version Manager not found"
14
16
  echo "! If RVM is installed, check your :rvm_use_path setting."
15
17
  exit 1
16
18
  fi
17
- }
18
- command %{source #{fetch(:rvm_use_path)}}
19
- command %{rvm use "#{args[:env]}" --create}
19
+ )
20
+ command %(source #{fetch(:rvm_use_path)})
21
+ command %(rvm use "#{args[:env]}" --create)
20
22
  end
21
23
 
22
24
  task :'rvm:wrapper', :env, :name, :bin do |_, args|
23
25
  unless args[:env] && args[:name] && args[:bin]
24
- puts "Task 'rvm:wrapper' needs an RVM environment name, an wrapper name and the binary name as arguments"
26
+ puts "Task 'rvm:wrapper' needs an RVM environment name, a wrapper name and the binary name as arguments"
25
27
  puts "Example: invoke :'rvm:wrapper', 'ruby-1.9.2@myapp,myapp,unicorn_rails'"
26
28
  exit 1
27
29
  end
28
30
 
29
- comment %{creating RVM wrapper "#{args[:name]}_#{args[:bin]}" using \\"#{args[:env]}\\"}
30
- command %{
31
+ comment %(creating RVM wrapper "#{args[:name]}_#{args[:bin]}" using \\"#{args[:env]}\\")
32
+ command %(
31
33
  if [[ ! -s "#{fetch(:rvm_use_path)}" ]]; then
32
34
  echo "! Ruby Version Manager not found"
33
35
  echo "! If RVM is installed, check your :rvm_use_path setting."
34
36
  exit 1
35
37
  fi
36
- }
37
- command %{source #{fetch(:rvm_use_path)}}
38
- command %{rvm wrapper #{args[:env]} #{args[:name]} #{args[:bin]} || exit 1}
38
+ )
39
+ command %(source #{fetch(:rvm_use_path)})
40
+ command %(rvm wrapper #{args[:env]} #{args[:name]} #{args[:bin]} || exit 1)
39
41
  end