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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Mina::Runner do
@@ -6,19 +8,13 @@ describe Mina::Runner do
6
8
  describe '#initialize' do
7
9
  it 'raises an error if execution mode is not set' do
8
10
  instance.remove(:execution_mode)
9
- expect { Mina::Runner.new(nil, nil) }.to raise_error('You must specify execution mode')
10
- end
11
-
12
- it 'raises an error when run on windows and pretty print' do
13
- instance.set(:execution_mode, :pretty)
14
- allow(Gem::Platform.local).to receive(:os).and_return(:windows)
15
- expect { Mina::Runner.new(nil, nil) }.to raise_error('Unsuported execution mode (pretty on windows)')
11
+ expect { described_class.new(nil, nil) }.to raise_error('You must specify execution mode')
16
12
  end
17
13
 
18
14
  it 'sets execution mode to printer if simulate is true' do
19
15
  instance.set(:execution_mode, :pretty)
20
- instance.set(:simulate, :true)
21
- expect(Mina::Runner.new(nil, nil).execution_mode).to eq(:printer)
16
+ instance.set(:simulate, true)
17
+ expect(described_class.new(nil, nil).execution_mode).to eq(:printer)
22
18
  instance.remove(:simulate)
23
19
  end
24
20
  end
@@ -26,7 +22,7 @@ describe Mina::Runner do
26
22
  describe '#run' do
27
23
  it 'runs the commands on a backend' do
28
24
  instance.set(:execution_mode, :printer)
29
- runner = Mina::Runner.new(['ls -al'], :local)
25
+ runner = described_class.new(['ls -al'], :local)
30
26
  expect { runner.run }.to output("\\[\\\"ls\\ -al\\\"\\]\n").to_stdout
31
27
  end
32
28
  end
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
 
3
- SimpleCov.start
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
4
7
 
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ enable_coverage :branch
9
+ primary_coverage :branch
10
+ end
7
11
 
8
12
  require 'mina'
9
13
  require 'rspec'
10
14
  require 'pry'
15
+ require 'set'
11
16
 
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
17
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
13
18
  Rake.application = Mina::Application.new
14
- Dir["./tasks/mina/**/*.rb"].each { |f| require f }
19
+ Dir['./tasks/mina/**/*.rb'].sort.each { |f| require f }
15
20
 
16
21
  RSpec.configure do |config|
17
22
  config.include RakeExampleGroup, type: :rake
@@ -19,16 +24,30 @@ RSpec.configure do |config|
19
24
  config.raise_errors_for_deprecations!
20
25
  config.order = 'random'
21
26
 
22
- config.before(:all, type: :rake) do
23
- Mina::Configuration.instance.set :simulate, true
24
- Mina::Configuration.instance.set :domain, 'localhost'
25
- Mina::Configuration.instance.set :deploy_to, "#{Dir.pwd}/deploy"
26
- Mina::Configuration.instance.set :repository, "#{Mina.root_path}"
27
- Mina::Configuration.instance.set :shared_paths, ['config/database.yml', 'log']
28
- Mina::Configuration.instance.set :keep_releases, 2
27
+ initial_task_names = Rake.application.tasks.to_set(&:name)
28
+ initial_variables = Mina::Configuration.instance.variables
29
+
30
+ config.before do
31
+ Mina::Configuration.instance.instance_variable_set(:@variables, initial_variables.clone)
32
+ end
33
+
34
+ config.after do
35
+ Rake.application.tasks.each(&:reenable)
36
+ Rake.application.instance_variable_get(:@tasks).keep_if { |task_name, _| initial_task_names.include?(task_name) }
37
+ end
38
+
39
+ config.around(:each, :suppressed_output) do |example|
40
+ original_stdout, $stdout = $stdout, File.open(File::NULL, 'w')
41
+ original_stderr, $stderr = $stderr, File.open(File::NULL, 'w')
42
+
43
+ example.run
44
+
45
+ $stdout, $stderr = original_stdout, original_stderr
29
46
  end
30
47
 
31
- config.after(:all, type: :rake) do
32
- Mina::Configuration.instance.remove :simulate
48
+ config.around do |example|
49
+ example.run
50
+ rescue SystemExit
51
+ raise "Unhandled system exit (you're probably missing a raise_error(SystemExit) matcher somewhere)"
33
52
  end
34
53
  end
@@ -1,2 +1,2 @@
1
- echo "-----> Cleans up unsed gems"
2
- bundle clean --without development test --path "vendor/bundle" --deployment
1
+ echo "-----> Cleaning up unused gems"
2
+ bundle clean
@@ -0,0 +1,7 @@
1
+ echo "-----> chruby to version: \\"123\\""
2
+ if \[\[ ! -s "/etc/profile\.d/chruby\.sh" \]\]; then
3
+ echo "! chruby\.sh init file not found"
4
+ exit 1
5
+ fi
6
+ source /etc/profile\.d/chruby\.sh
7
+ chruby "123" \|\| exit 1
@@ -0,0 +1,2 @@
1
+ Task 'chruby' needs a Ruby version as an argument\.
2
+ Example: invoke :chruby, 'ruby-2.4'
@@ -0,0 +1,11 @@
1
+ ========== Configuration variables ==========
2
+ (.|\n)*
3
+ :bundle_bin => "bundle"
4
+ (.|\n)*
5
+ :releases_path => ".*/releases"
6
+ (.|\n)*
7
+ :keep_releases => "1234"
8
+ (.|\n)*
9
+ :migration_dirs => \["db/migrate"\]
10
+ (.|\n)*
11
+ ========== Configuration variables ==========
@@ -0,0 +1,4 @@
1
+ (?m)#!/usr/bin/env bash
2
+ # Executing the following via 'ssh localhost -p 22 -tt':
3
+ .*
4
+ echo Hello there
@@ -0,0 +1 @@
1
+ \(cd /path && echo Hello there && cd -\)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # Executing the following:
3
+ #
4
+ echo "-----> I am a comment"
5
+ echo Hello there
@@ -0,0 +1,6 @@
1
+ # ============================
2
+ # === Start up server => \(in deployer\)
3
+ \(
4
+ cd ".*/deploy/current"
5
+ echo Hello there
6
+ \) &&
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # Executing the following via 'ssh localhost -p 22 -tt':
3
+ #
4
+ echo "-----> I am a comment"
5
+ echo Hello there
@@ -0,0 +1,2 @@
1
+ ^((?!echo Hello there).)*$
2
+ echo New command
@@ -0,0 +1 @@
1
+ (?m)Cloning the Git repository.*Done\. Deployed version 1
@@ -0,0 +1 @@
1
+ The directory '/app/releases' does not exist on the server\.
@@ -0,0 +1 @@
1
+ Setting up /app
@@ -0,0 +1 @@
1
+ environment is DEPRECATED! Please use local_environment and remote_environment
@@ -1 +1 @@
1
- if\ \[\ !\ \-d\ ".*/deploy/scm/objects"\ \];\ then\s*echo\ "\-\-\-\-\->\ Cloning\ the\ Git\ repository"\s*git\ clone\ ".*"\ ".*/deploy/scm"\ \-\-bare\s*else\s*echo\ "\-\-\-\-\->\ Fetching\ new\ git\ commits"\s*\(cd\ ".*/deploy/scm"\ &&\ git\ fetch\ ".*"\ "master:master"\ \-\-force\)\s*fi\ &&\s*echo\ "\-\-\-\-\->\ Using\ git\ branch\ 'master'"\ &&\s*git\ clone\ ".*/deploy/scm"\ \.\ \-\-recursive\ \-\-branch\ "master"\necho\ "\-\-\-\-\->\ Using\ this\ git\ commit"\ngit\ rev\-parse\ HEAD\ >\ \.mina_git_revision\ngit\ \-\-no\-pager\ log\ \-\-format="%aN\ \(%h\):%n>\ %s"\ \-n\ 1\nrm\ \-rf\ \.git
1
+ if\ \[\ !\ \-d\ ".*/deploy/scm/objects"\ \];\ then\s*echo\ "\-\-\-\-\->\ Cloning\ the\ Git\ repository"\s*git\ clone\ ".*"\ ".*/deploy/scm"\ \-\-bare\s*else\s*echo\ "\-\-\-\-\->\ Fetching\ new\ git\ commits"\s*\(cd\ ".*/deploy/scm"\ &&\ git\ fetch\ ".*"\ "master:master"\ \-\-force\)\s*fi\ &&\s*echo\ "\-\-\-\-\->\ Using\ git\ branch\ 'master'"\ &&\s*git\ clone\ ".*/deploy/scm"\ \.\ \-\-recursive\ \-\-branch\ "master"\necho\ "\-\-\-\-\->\ Updating\ submodules"\ngit\ submodule\ update\necho\ "\-\-\-\-\->\ Using\ this\ git\ commit"\ngit\ rev\-parse\ HEAD\ >\ \.mina_git_revision\ngit\ \-\-no\-pager\ log\ \-\-format="%aN\ \(%h\):%n>\ %s"\ \-n\ 1\nrm\ \-rf\ \.git
@@ -1 +1 @@
1
- echo\ "\-\-\-\-\->\ Using\ git\ commit\ \\"123456\\""\ngit\ clone\ ".*"\ \.\ \-\-recursive\ngit\ checkout\ \-b\ current_release\ "123456"\ \-\-force\necho\ "\-\-\-\-\->\ Using\ this\ git\ commit"\ngit\ rev\-parse\ HEAD\ >\ \.mina_git_revision\ngit\ \-\-no\-pager\ log\ \-\-format="%aN\ \(%h\):%n>\ %s"\ \-n\ 1\nrm\ \-rf\ \.git
1
+ echo\ "\-\-\-\-\->\ Using\ git\ commit\ \\"123456\\""\ngit\ clone\ ".*"\ \.\ \-\-recursive\ngit\ checkout\ \-b\ current_release\ "123456"\ \-\-force\necho\ "\-\-\-\-\->\ Updating\ submodules"\ngit\ submodule\ update\necho\ "\-\-\-\-\->\ Using\ this\ git\ commit"\ngit\ rev\-parse\ HEAD\ >\ \.mina_git_revision\ngit\ \-\-no\-pager\ log\ \-\-format="%aN\ \(%h\):%n>\ %s"\ \-n\ 1\nrm\ \-rf\ \.git
@@ -0,0 +1,15 @@
1
+ echo "-----> Ensuring everything is pushed to git"
2
+ if \[ \$\(git branch --list master \| wc -l\) -eq 0 \]; then
3
+ echo "! Branch master doesn't exist"
4
+ exit 1
5
+ fi
6
+
7
+ if \[ \$\(git branch -r --list origin/master \| wc -l\) -eq 0 \]; then
8
+ echo "! Branch origin/master doesn't exist"
9
+ exit 1
10
+ fi
11
+
12
+ if \[ \$\(git log origin/master..master \| wc -l\) -ne 0 \]; then
13
+ echo "! Your branch master needs to be pushed to origin before deploying"
14
+ exit 1
15
+ fi
@@ -0,0 +1,2 @@
1
+ echo "-----> Precompiling asset files"
2
+ RAILS_ENV="production" bundle exec rake assets:precompile
@@ -0,0 +1 @@
1
+ Can't be run outside deploy do block. Please use mina 'rake\[assets_precompile\]' instead
@@ -0,0 +1,7 @@
1
+ if diff -qrN ".*/deploy/current/vendor/assets/" "\./vendor/assets/" 2>/dev/null && diff -qrN ".*/deploy/current/app/assets/" "\./app/assets/" 2>/dev/null
2
+ then
3
+ echo "-----> Skipping asset precompilation"
4
+ else
5
+ echo "-----> Precompiling asset files"
6
+ RAILS_ENV="production" bundle exec rake assets:precompile
7
+ fi
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/current && RAILS_ENV="production" bundle exec rails console && cd -\)
@@ -0,0 +1,2 @@
1
+ echo "-----> Migrating database"
2
+ RAILS_ENV="production" bundle exec rake db:migrate
@@ -0,0 +1 @@
1
+ Can't be run outside deploy do block\. Please use mina 'rake\[db_migrate\]' instead
@@ -0,0 +1,7 @@
1
+ if diff -qrN ".*/deploy/current/db/migrate" "\./db/migrate" 2>/dev/null
2
+ then
3
+ echo "-----> DB migrations unchanged; skipping DB migration"
4
+ else
5
+ echo "-----> Migrating database"
6
+ RAILS_ENV="production" bundle exec rake db:migrate
7
+ fi
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/shared/log && tail -f production\.log && cd -\)
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/current && RAILS_ENV="production" bundle exec rails db:rollback STEP=2 && cd -\)
@@ -0,0 +1 @@
1
+ You need to provide arguments. Try: mina "rails\[console\]"
@@ -0,0 +1 @@
1
+ \(cd .*/deploy/current && RAILS_ENV="production" bundle exec rake db:primary:migrate && cd -\)
@@ -0,0 +1 @@
1
+ You need to provide arguments. Try: mina "rake\[db:migrate\]"
@@ -1 +1,9 @@
1
- echo\ "\-\-\-\-\->\ Loading\ rbenv"\nexport\ RBENV_ROOT="\$HOME/\.rbenv"\nexport\ PATH="\$HOME/\.rbenv/bin:\$PATH"\s*if\ !\ which\ rbenv\ >/dev/null;\ then\s*echo\ "!\ rbenv\ not\ found"\s*echo\ "!\ If\ rbenv\ is\ installed,\ check\ your\ :rbenv_path\ setting\."\s*exit\ 1\s*fi\s*eval\ "\$\(rbenv\ init\ \-\)"
1
+ echo "-----> Loading rbenv"
2
+ export RBENV_ROOT="\$HOME/\.rbenv"
3
+ export PATH="\$HOME/\.rbenv/bin:\$PATH"
4
+ if ! which rbenv >/dev/null; then
5
+ echo "! rbenv not found"
6
+ echo "! If rbenv is installed, check your :rbenv_path setting\."
7
+ exit 1
8
+ fi
9
+ eval "\$\(rbenv init -\)"
@@ -0,0 +1,8 @@
1
+ echo "-----> Using RVM environment \\"3\.0\.0\\""
2
+ if \[\[ ! -s "\$HOME/\.rvm/scripts/rvm" \]\]; then
3
+ echo "! Ruby Version Manager not found"
4
+ echo "! If RVM is installed, check your :rvm_use_path setting\."
5
+ exit 1
6
+ fi
7
+ source \$HOME/\.rvm/scripts/rvm
8
+ rvm use "3\.0\.0" --create
@@ -0,0 +1,2 @@
1
+ Task 'rvm:use' needs an RVM environment name as an argument\.
2
+ Example: invoke :'rvm:use', 'ruby-1\.9\.2@default'
@@ -0,0 +1,8 @@
1
+ echo "-----> creating RVM wrapper "myapp_unicorn" using \\"3\.0\.0\\""
2
+ if \[\[ ! -s "\$HOME/\.rvm/scripts/rvm" \]\]; then
3
+ echo "! Ruby Version Manager not found"
4
+ echo "! If RVM is installed, check your :rvm_use_path setting\."
5
+ exit 1
6
+ fi
7
+ source \$HOME/\.rvm/scripts/rvm
8
+ rvm wrapper 3\.0\.0 myapp unicorn \|\| exit 1
@@ -0,0 +1,2 @@
1
+ Task 'rvm:wrapper' needs an RVM environment name, a wrapper name and the binary name as arguments
2
+ Example: invoke :'rvm:wrapper', 'ruby-1\.9\.2@myapp,myapp,unicorn_rails'
@@ -0,0 +1,13 @@
1
+ echo "-----> ry to version: \\\"3\.0\.0\\\""
2
+ echo "-----> Loading ry"
3
+ if \[\[ ! -e "\$HOME/\.local/bin" \]\]; then
4
+ echo "! ry not found"
5
+ echo "! If ry is installed, check your :ry_path setting."
6
+ exit 1
7
+ fi
8
+ export PATH="\$HOME/\.local/bin:\$PATH"
9
+ eval "\$\(ry setup\)"
10
+ RY_RUBY="3\.0\.0"
11
+ if \[ -n "\$RY_RUBY" \]; then
12
+ ry use \$RY_RUBY \|\| exit 1
13
+ fi
@@ -0,0 +1,13 @@
1
+ echo "-----> ry to version: \\"\*\*not specified\*\*\\""
2
+ echo "-----> Loading ry"
3
+ if \[\[ ! -e "\$HOME/\.local/bin" \]\]; then
4
+ echo "! ry not found"
5
+ echo "! If ry is installed, check your :ry_path setting."
6
+ exit 1
7
+ fi
8
+ export PATH="\$HOME/\.local/bin:\$PATH"
9
+ eval "\$\(ry setup\)"
10
+ RY_RUBY=""
11
+ if \[ -n "\$RY_RUBY" \]; then
12
+ ry use \$RY_RUBY \|\| exit 1
13
+ fi
@@ -0,0 +1 @@
1
+ cd .*/deploy && exec \$SHELL
@@ -0,0 +1,3 @@
1
+ if ! ssh-keygen -H -F localhost &>/dev/null; then
2
+ ssh-keyscan -p 22 localhost >> ~/.ssh/known_hosts
3
+ fi
@@ -1,25 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeExampleGroup
2
- extend RSpec::Matchers::DSL
3
-
4
- def self.included(klass)
5
- klass.instance_eval do
6
- let(:rake) { Rake.application }
7
- let(:task_name) { self.class.description }
8
- let(:run_commands) { rake['run_commands']}
9
- let(:reset!) { rake['reset!'] }
10
- subject { rake[task_name] }
11
-
12
- after do
13
- subject.reenable
14
- run_commands.reenable
15
- reset!.invoke
16
- reset!.reenable
17
- end
18
- end
4
+ extend RSpec::SharedContext
5
+
6
+ subject(:task) { rake[task_name] }
7
+
8
+ let(:rake) { Rake.application }
9
+ let(:task_name) { self.class.description }
10
+ let(:run_commands) { rake['run_commands'] }
11
+ let(:reset!) { rake['reset!'] }
12
+
13
+ after do
14
+ reset!.invoke
15
+ end
16
+
17
+ def load_default_config
18
+ load_config 'default'
19
+ end
20
+
21
+ def load_config(config_name)
22
+ Rake.load_rakefile(Dir.pwd + "/spec/configs/#{config_name}.rb")
19
23
  end
20
24
 
21
- def invoke_all(args = nil)
22
- subject.invoke(args)
25
+ def invoke_all(*args)
26
+ task.invoke(*args)
23
27
  run_commands.invoke
24
28
  end
25
29
 
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'bundler', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'bundle:install' do
5
11
  it 'bundle install' do
6
12
  expect { invoke_all }.to output(output_file('bundle_install')).to_stdout
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe 'chruby', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'chruby' do
11
+ let(:task_name) { 'chruby' }
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).and output(output_file('chruby_without_env')).to_stdout
18
+ end
19
+ end
20
+
21
+ context 'with an argument' do
22
+ it 'sets ruby version' do
23
+ expect do
24
+ invoke_all('123')
25
+ end.to output(output_file('chruby_with_env')).to_stdout
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'default', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
10
+ describe 'environment' do
11
+ it 'outputs a deprecation warning' do
12
+ expect { invoke_all }.to output(output_file('environment')).to_stdout
13
+ end
14
+ end
15
+
4
16
  describe 'ssh_keyscan_repo' do
5
17
  it 'scans ssh' do
6
18
  Mina::Configuration.instance.set(:repository, 'git@github.com/exapmle')
@@ -8,29 +20,89 @@ RSpec.describe 'default', type: :rake do
8
20
  end
9
21
  end
10
22
 
23
+ describe 'ssh_keyscan_domain' do
24
+ let(:task_name) { 'ssh_keyscan_domain' }
25
+
26
+ context "when domain isn't set" do
27
+ before do
28
+ Mina::Configuration.instance.remove(:domain)
29
+ end
30
+
31
+ it 'exits with an error message' do
32
+ expect do
33
+ invoke_all
34
+ end.to raise_error(SystemExit)
35
+ .and output(/domain must be defined!/).to_stdout
36
+ end
37
+ end
38
+
39
+ context "when port isn't set" do
40
+ before do
41
+ Mina::Configuration.instance.remove(:port)
42
+ end
43
+
44
+ it 'exits with an error message' do
45
+ expect do
46
+ invoke_all
47
+ end.to raise_error(SystemExit)
48
+ .and output(/port must be defined!/).to_stdout
49
+ end
50
+ end
51
+
52
+ context 'when conditions are met' do
53
+ it 'scans ssh' do
54
+ expect do
55
+ invoke_all
56
+ end.to output(output_file('ssh_keyscan_domain')).to_stdout
57
+ end
58
+ end
59
+ end
60
+
11
61
  describe 'run' do
12
62
  it 'runs command' do
13
- subject.invoke('ls -al')
63
+ task.invoke('ls -al')
14
64
  expect { run_commands.invoke }.to output(output_file('run')).to_stdout
15
65
  end
16
66
 
17
67
  it 'exits if no command given' do
18
- expect { subject.invoke }.to raise_error(SystemExit)
68
+ expect { task.invoke }.to raise_error(SystemExit)
69
+ .and output(/You need to provide a command/).to_stdout
19
70
  end
20
71
  end
21
72
 
22
73
  describe 'ssh' do
23
- it 'runs ssh' do
24
- expect_any_instance_of(Kernel).to receive(:exec)
25
- subject.invoke
74
+ it 'opens an SSH connection when :deploy_to exists' do
75
+ expect do
76
+ invoke_all
77
+ end.to change { Mina::Configuration.instance.fetch(:execution_mode) }.to(:exec)
78
+ .and output(output_file('ssh')).to_stdout
79
+ end
80
+
81
+ it "exits with an error message when :deploy_to isn't set" do
82
+ Mina::Configuration.instance.remove(:deploy_to)
83
+
84
+ expect do
85
+ invoke_all
86
+ end.to raise_error(SystemExit)
87
+ .and output(/deploy_to must be defined!/).to_stdout
26
88
  end
27
89
  end
28
90
 
29
91
  describe 'debug_configuration_variables' do
30
- it 'prints configrtion variables' do
92
+ before do
31
93
  Mina::Configuration.instance.set(:debug_configuration_variables, true)
32
- expect { invoke_all }.to output(/------- Printing current config variables -------/).to_stdout
94
+ ENV['keep_releases'] = '1234'
95
+ end
96
+
97
+ after do
33
98
  Mina::Configuration.instance.remove(:debug_configuration_variables)
99
+ ENV.delete('keep_releases')
100
+ end
101
+
102
+ it 'prints configuration variables' do
103
+ expect do
104
+ invoke_all
105
+ end.to output(output_file('debug_configuration_variables')).to_stdout
34
106
  end
35
107
  end
36
108
  end
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'deploy', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'deploy:force_unlock' do
5
11
  it 'deploy force_unlock' do
6
12
  expect { invoke_all }.to output(output_file('deploy_force_unlock')).to_stdout
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'git', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  describe 'git:clone' do
5
11
  it 'git clone' do
6
12
  expect { invoke_all }.to output(output_file('git_clone')).to_stdout
@@ -18,4 +24,10 @@ RSpec.describe 'git', type: :rake do
18
24
  expect { invoke_all }.to output(output_file('git_revision')).to_stdout
19
25
  end
20
26
  end
27
+
28
+ describe 'git:ensure_pushed' do
29
+ it 'git ensure pushed' do
30
+ expect { invoke_all }.to output(output_file('git_ensure_pushed')).to_stdout
31
+ end
32
+ end
21
33
  end
@@ -1,16 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'init', type: :rake do
6
+ before do
7
+ load_default_config
8
+ end
9
+
4
10
  it 'creates new deploy rb' do
5
11
  allow(File).to receive(:exist?).and_return(true)
6
- expect(FileUtils).to receive(:mkdir_p)
7
- expect(FileUtils).to receive(:cp)
12
+ allow(File).to receive(:exist?).with('./config/deploy.rb').and_return(false)
13
+ allow(FileUtils).to receive(:mkdir_p).and_return(true)
14
+ allow(FileUtils).to receive(:cp).and_return(true)
8
15
 
9
- expect { subject.invoke }.to output("-----> Created ./config/deploy.rb\nEdit this file, then run `mina setup` after.\n").to_stdout
16
+ expect do
17
+ task.invoke
18
+ end.to output("-----> Created ./config/deploy.rb\nEdit this file, then run `mina setup` after.\n").to_stdout
10
19
  end
11
20
 
12
21
  it 'doesnt create deploy rb if already exists' do
13
22
  allow(File).to receive(:exist?).and_return(false)
14
- expect { subject.invoke }.to raise_error(SystemExit)
23
+ expect { task.invoke }.to raise_error(SystemExit).and output(/You already have/).to_stdout
15
24
  end
16
25
  end