capistrano 2.8.0 → 3.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.docker/Dockerfile +7 -0
- data/.docker/ssh_key_rsa +49 -0
- data/.docker/ssh_key_rsa.pub +1 -0
- data/.docker/ubuntu_setup.sh +23 -0
- data/.github/issue_template.md +19 -0
- data/.github/pull_request_template.md +22 -0
- data/.github/release-drafter.yml +25 -0
- data/.github/workflows/ci.yml +80 -0
- data/.github/workflows/release-drafter.yml +18 -0
- data/.gitignore +23 -8
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +1 -0
- data/CONTRIBUTING.md +63 -0
- data/DEVELOPMENT.md +112 -0
- data/Gemfile +42 -9
- data/LICENSE.txt +21 -0
- data/README.md +221 -0
- data/RELEASING.md +17 -0
- data/Rakefile +17 -8
- data/UPGRADING-3.7.md +86 -0
- data/bin/cap +2 -3
- data/bin/capify +7 -89
- data/capistrano.gemspec +29 -43
- data/docker-compose.yml +8 -0
- data/features/configuration.feature +28 -0
- data/features/deploy.feature +92 -0
- data/features/deploy_failure.feature +17 -0
- data/features/doctor.feature +11 -0
- data/features/installation.feature +21 -0
- data/features/sshconnect.feature +11 -0
- data/features/stage_failure.feature +9 -0
- data/features/step_definitions/assertions.rb +162 -0
- data/features/step_definitions/cap_commands.rb +21 -0
- data/features/step_definitions/setup.rb +91 -0
- data/features/subdirectory.feature +9 -0
- data/features/support/docker_gateway.rb +53 -0
- data/features/support/env.rb +1 -0
- data/features/support/remote_command_helpers.rb +29 -0
- data/features/support/remote_ssh_helpers.rb +33 -0
- data/lib/Capfile +3 -0
- data/lib/capistrano/all.rb +17 -0
- data/lib/capistrano/application.rb +153 -0
- data/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +26 -0
- data/lib/capistrano/configuration/host_filter.rb +29 -0
- data/lib/capistrano/configuration/null_filter.rb +9 -0
- data/lib/capistrano/configuration/plugin_installer.rb +51 -0
- data/lib/capistrano/configuration/question.rb +76 -0
- data/lib/capistrano/configuration/role_filter.rb +29 -0
- data/lib/capistrano/configuration/scm_resolver.rb +149 -0
- data/lib/capistrano/configuration/server.rb +137 -0
- data/lib/capistrano/configuration/servers.rb +56 -96
- data/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/lib/capistrano/configuration/variables.rb +79 -94
- data/lib/capistrano/configuration.rb +178 -33
- data/lib/capistrano/console.rb +1 -0
- data/lib/capistrano/defaults.rb +36 -0
- data/lib/capistrano/deploy.rb +3 -0
- data/lib/capistrano/doctor/environment_doctor.rb +19 -0
- data/lib/capistrano/doctor/gems_doctor.rb +45 -0
- data/lib/capistrano/doctor/output_helpers.rb +79 -0
- data/lib/capistrano/doctor/servers_doctor.rb +105 -0
- data/lib/capistrano/doctor/variables_doctor.rb +74 -0
- data/lib/capistrano/doctor.rb +6 -0
- data/lib/capistrano/dotfile.rb +2 -0
- data/lib/capistrano/dsl/env.rb +43 -0
- data/lib/capistrano/dsl/paths.rb +89 -0
- data/lib/capistrano/dsl/stages.rb +31 -0
- data/lib/capistrano/dsl/task_enhancements.rb +61 -0
- data/lib/capistrano/dsl.rb +95 -0
- data/lib/capistrano/framework.rb +2 -0
- data/lib/capistrano/i18n.rb +46 -0
- data/lib/capistrano/immutable_task.rb +30 -0
- data/lib/capistrano/install.rb +1 -0
- data/lib/capistrano/plugin.rb +95 -0
- data/lib/capistrano/proc_helpers.rb +13 -0
- data/lib/capistrano/scm/git.rb +105 -0
- data/lib/capistrano/scm/hg.rb +55 -0
- data/lib/capistrano/scm/plugin.rb +13 -0
- data/lib/capistrano/scm/svn.rb +56 -0
- data/lib/capistrano/scm/tasks/git.rake +84 -0
- data/lib/capistrano/scm/tasks/hg.rake +53 -0
- data/lib/capistrano/scm/tasks/svn.rake +53 -0
- data/lib/capistrano/scm.rb +115 -0
- data/lib/capistrano/setup.rb +36 -0
- data/lib/capistrano/tasks/console.rake +25 -0
- data/lib/capistrano/tasks/deploy.rake +280 -0
- data/lib/capistrano/tasks/doctor.rake +24 -0
- data/lib/capistrano/tasks/framework.rake +67 -0
- data/lib/capistrano/tasks/install.rake +41 -0
- data/lib/capistrano/templates/Capfile +38 -0
- data/lib/capistrano/templates/deploy.rb.erb +39 -0
- data/lib/capistrano/templates/stage.rb.erb +61 -0
- data/lib/capistrano/upload_task.rb +9 -0
- data/lib/capistrano/version.rb +1 -14
- data/lib/capistrano/version_validator.rb +32 -0
- data/lib/capistrano.rb +0 -3
- data/spec/integration/dsl_spec.rb +632 -0
- data/spec/integration_spec_helper.rb +5 -0
- data/spec/lib/capistrano/application_spec.rb +60 -0
- data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/filter_spec.rb +109 -0
- data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
- data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
- data/spec/lib/capistrano/configuration/question_spec.rb +92 -0
- data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
- data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +56 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +309 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +331 -0
- data/spec/lib/capistrano/configuration_spec.rb +357 -0
- data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
- data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
- data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +228 -0
- data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +108 -0
- data/spec/lib/capistrano/dsl_spec.rb +125 -0
- data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/spec/lib/capistrano/scm/git_spec.rb +194 -0
- data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
- data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
- data/spec/lib/capistrano/scm_spec.rb +103 -0
- data/spec/lib/capistrano/upload_task_spec.rb +19 -0
- data/spec/lib/capistrano/version_validator_spec.rb +118 -0
- data/spec/lib/capistrano_spec.rb +7 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/matchers.rb +5 -0
- data/spec/support/tasks/database.rake +11 -0
- data/spec/support/tasks/fail.rake +8 -0
- data/spec/support/tasks/failed.rake +5 -0
- data/spec/support/tasks/plugin.rake +6 -0
- data/spec/support/tasks/root.rake +11 -0
- data/spec/support/test_app.rb +205 -0
- metadata +234 -208
- data/.rvmrc +0 -1
- data/CHANGELOG +0 -954
- data/README.mdown +0 -76
- data/lib/capistrano/callback.rb +0 -45
- data/lib/capistrano/cli/execute.rb +0 -85
- data/lib/capistrano/cli/help.rb +0 -125
- data/lib/capistrano/cli/help.txt +0 -81
- data/lib/capistrano/cli/options.rb +0 -243
- data/lib/capistrano/cli/ui.rb +0 -40
- data/lib/capistrano/cli.rb +0 -47
- data/lib/capistrano/command.rb +0 -286
- data/lib/capistrano/configuration/actions/file_transfer.rb +0 -51
- data/lib/capistrano/configuration/actions/inspect.rb +0 -46
- data/lib/capistrano/configuration/actions/invocation.rb +0 -298
- data/lib/capistrano/configuration/callbacks.rb +0 -148
- data/lib/capistrano/configuration/connections.rb +0 -230
- data/lib/capistrano/configuration/execution.rb +0 -143
- data/lib/capistrano/configuration/loading.rb +0 -197
- data/lib/capistrano/configuration/namespaces.rb +0 -197
- data/lib/capistrano/configuration/roles.rb +0 -73
- data/lib/capistrano/errors.rb +0 -19
- data/lib/capistrano/ext/string.rb +0 -5
- data/lib/capistrano/extensions.rb +0 -57
- data/lib/capistrano/logger.rb +0 -59
- data/lib/capistrano/processable.rb +0 -53
- data/lib/capistrano/recipes/compat.rb +0 -32
- data/lib/capistrano/recipes/deploy/assets.rb +0 -57
- data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
- data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -111
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
- data/lib/capistrano/recipes/deploy/scm/base.rb +0 -196
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
- data/lib/capistrano/recipes/deploy/scm/git.rb +0 -282
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
- data/lib/capistrano/recipes/deploy/scm/none.rb +0 -44
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -138
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
- data/lib/capistrano/recipes/deploy/scm.rb +0 -19
- data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -88
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -224
- data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
- data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/recipes/deploy.rb +0 -568
- data/lib/capistrano/recipes/standard.rb +0 -37
- data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/role.rb +0 -102
- data/lib/capistrano/server_definition.rb +0 -56
- data/lib/capistrano/shell.rb +0 -260
- data/lib/capistrano/ssh.rb +0 -101
- data/lib/capistrano/task_definition.rb +0 -75
- data/lib/capistrano/transfer.rb +0 -216
- data/rvmrc.sample +0 -1
- data/test/cli/execute_test.rb +0 -132
- data/test/cli/help_test.rb +0 -165
- data/test/cli/options_test.rb +0 -329
- data/test/cli/ui_test.rb +0 -28
- data/test/cli_test.rb +0 -17
- data/test/command_test.rb +0 -289
- data/test/configuration/actions/file_transfer_test.rb +0 -61
- data/test/configuration/actions/inspect_test.rb +0 -65
- data/test/configuration/actions/invocation_test.rb +0 -247
- data/test/configuration/callbacks_test.rb +0 -220
- data/test/configuration/connections_test.rb +0 -420
- data/test/configuration/execution_test.rb +0 -175
- data/test/configuration/loading_test.rb +0 -132
- data/test/configuration/namespace_dsl_test.rb +0 -311
- data/test/configuration/roles_test.rb +0 -144
- data/test/configuration/servers_test.rb +0 -183
- data/test/configuration/variables_test.rb +0 -190
- data/test/configuration_test.rb +0 -88
- data/test/deploy/local_dependency_test.rb +0 -76
- data/test/deploy/remote_dependency_test.rb +0 -135
- data/test/deploy/scm/accurev_test.rb +0 -23
- data/test/deploy/scm/base_test.rb +0 -55
- data/test/deploy/scm/bzr_test.rb +0 -51
- data/test/deploy/scm/darcs_test.rb +0 -37
- data/test/deploy/scm/git_test.rb +0 -184
- data/test/deploy/scm/mercurial_test.rb +0 -134
- data/test/deploy/scm/none_test.rb +0 -35
- data/test/deploy/scm/subversion_test.rb +0 -32
- data/test/deploy/strategy/copy_test.rb +0 -321
- data/test/extensions_test.rb +0 -69
- data/test/fixtures/cli_integration.rb +0 -5
- data/test/fixtures/config.rb +0 -5
- data/test/fixtures/custom.rb +0 -3
- data/test/logger_test.rb +0 -123
- data/test/recipes_test.rb +0 -25
- data/test/role_test.rb +0 -11
- data/test/server_definition_test.rb +0 -121
- data/test/shell_test.rb +0 -90
- data/test/ssh_test.rb +0 -113
- data/test/task_definition_test.rb +0 -116
- data/test/transfer_test.rb +0 -160
- data/test/utils.rb +0 -37
@@ -0,0 +1,194 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "capistrano/scm/git"
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
describe SCM::Git do
|
7
|
+
subject { Capistrano::SCM::Git.new }
|
8
|
+
|
9
|
+
# This allows us to easily use `set`, `fetch`, etc. in the examples.
|
10
|
+
let(:env) { Capistrano::Configuration.env }
|
11
|
+
|
12
|
+
# Stub the SSHKit backend so we can set up expectations without the plugin
|
13
|
+
# actually executing any commands.
|
14
|
+
let(:backend) { stub }
|
15
|
+
before { SSHKit::Backend.stubs(:current).returns(backend) }
|
16
|
+
|
17
|
+
# Mimic the deploy flow tasks so that the plugin can register its hooks.
|
18
|
+
before do
|
19
|
+
Rake::Task.define_task("deploy:new_release_path")
|
20
|
+
Rake::Task.define_task("deploy:check")
|
21
|
+
Rake::Task.define_task("deploy:set_current_revision")
|
22
|
+
Rake::Task.define_task("deploy:set_current_revision_time")
|
23
|
+
end
|
24
|
+
|
25
|
+
# Clean up any tasks or variables that the plugin defined.
|
26
|
+
after do
|
27
|
+
Rake::Task.clear
|
28
|
+
Capistrano::Configuration.reset!
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#set_defaults" do
|
32
|
+
it "makes git_wrapper_path using a random hex value" do
|
33
|
+
env.set(:tmp_dir, "/tmp")
|
34
|
+
subject.set_defaults
|
35
|
+
expect(env.fetch(:git_wrapper_path)).to match(%r{/tmp/git-ssh-\h{20}\.sh})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "makes git_max_concurrent_connections" do
|
39
|
+
subject.set_defaults
|
40
|
+
expect(env.fetch(:git_max_concurrent_connections)).to eq(10)
|
41
|
+
env.set(:git_max_concurrent_connections, 7)
|
42
|
+
expect(env.fetch(:git_max_concurrent_connections)).to eq(7)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "makes git_wait_interval" do
|
46
|
+
subject.set_defaults
|
47
|
+
expect(env.fetch(:git_wait_interval)).to eq(0)
|
48
|
+
env.set(:git_wait_interval, 5)
|
49
|
+
expect(env.fetch(:git_wait_interval)).to eq(5)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#git" do
|
54
|
+
it "should call execute git in the context, with arguments" do
|
55
|
+
backend.expects(:execute).with(:git, :init)
|
56
|
+
subject.git(:init)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#repo_mirror_exists?" do
|
61
|
+
it "should call test for repo HEAD" do
|
62
|
+
env.set(:repo_path, "/path/to/repo")
|
63
|
+
backend.expects(:test).with " [ -f /path/to/repo/HEAD ] "
|
64
|
+
|
65
|
+
subject.repo_mirror_exists?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#check_repo_is_reachable" do
|
70
|
+
it "should test the repo url" do
|
71
|
+
env.set(:repo_url, "url")
|
72
|
+
backend.expects(:execute).with(:git, :'ls-remote', "url", "HEAD").returns(true)
|
73
|
+
|
74
|
+
subject.check_repo_is_reachable
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#clone_repo" do
|
79
|
+
it "should run git clone" do
|
80
|
+
env.set(:repo_url, "url")
|
81
|
+
env.set(:repo_path, "path")
|
82
|
+
backend.expects(:execute).with(:git, :clone, "--mirror", "url", "path")
|
83
|
+
|
84
|
+
subject.clone_repo
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should run git clone in shallow mode" do
|
88
|
+
env.set(:git_shallow_clone, "1")
|
89
|
+
env.set(:repo_url, "url")
|
90
|
+
env.set(:repo_path, "path")
|
91
|
+
|
92
|
+
backend.expects(:execute).with(:git, :clone, "--mirror", "--depth", "1", "--no-single-branch", "url", "path")
|
93
|
+
|
94
|
+
subject.clone_repo
|
95
|
+
end
|
96
|
+
|
97
|
+
context "with username and password specified" do
|
98
|
+
before do
|
99
|
+
env.set(:git_http_username, "hello")
|
100
|
+
env.set(:git_http_password, "topsecret")
|
101
|
+
env.set(:repo_url, "https://example.com/repo.git")
|
102
|
+
env.set(:repo_path, "path")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should include the credentials in the url" do
|
106
|
+
backend.expects(:execute).with(:git, :clone, "--mirror", "https://hello:topsecret@example.com/repo.git", "path")
|
107
|
+
subject.clone_repo
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#update_mirror" do
|
113
|
+
it "should run git update" do
|
114
|
+
env.set(:repo_url, "url")
|
115
|
+
|
116
|
+
backend.expects(:execute).with(:git, :remote, "set-url", "origin", "url")
|
117
|
+
backend.expects(:execute).with(:git, :remote, :update, "--prune")
|
118
|
+
|
119
|
+
subject.update_mirror
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should run git update in shallow mode" do
|
123
|
+
env.set(:git_shallow_clone, "1")
|
124
|
+
env.set(:branch, "branch")
|
125
|
+
env.set(:repo_url, "url")
|
126
|
+
|
127
|
+
backend.expects(:execute).with(:git, :remote, "set-url", "origin", "url")
|
128
|
+
backend.expects(:execute).with(:git, :fetch, "--depth", "1", "origin", "branch")
|
129
|
+
|
130
|
+
subject.update_mirror
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#archive_to_release_path" do
|
135
|
+
it "should run git archive without a subtree" do
|
136
|
+
env.set(:branch, "branch")
|
137
|
+
env.set(:release_path, "path")
|
138
|
+
|
139
|
+
backend.expects(:execute).with(:git, :archive, "branch", "| /usr/bin/env tar -x -f - -C", "path")
|
140
|
+
|
141
|
+
subject.archive_to_release_path
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should run git archive with a subtree" do
|
145
|
+
env.set(:repo_tree, "tree")
|
146
|
+
env.set(:branch, "branch")
|
147
|
+
env.set(:release_path, "path")
|
148
|
+
|
149
|
+
backend.expects(:execute).with(:git, :archive, "branch", "tree", "| /usr/bin/env tar -x --strip-components 1 -f - -C", "path")
|
150
|
+
|
151
|
+
subject.archive_to_release_path
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should run tar with an overridden name" do
|
155
|
+
env.set(:branch, "branch")
|
156
|
+
env.set(:release_path, "path")
|
157
|
+
SSHKit.config.command_map.expects(:[]).with(:tar).returns("/usr/bin/env gtar")
|
158
|
+
|
159
|
+
backend.expects(:execute).with(:git, :archive, "branch", "| /usr/bin/env gtar -x -f - -C", "path")
|
160
|
+
|
161
|
+
subject.archive_to_release_path
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "#fetch_revision" do
|
166
|
+
it "should capture git rev-list" do
|
167
|
+
env.set(:branch, "branch")
|
168
|
+
backend.expects(:capture).with(:git, "rev-list --max-count=1 branch").returns("81cec13b777ff46348693d327fc8e7832f79bf43")
|
169
|
+
revision = subject.fetch_revision
|
170
|
+
expect(revision).to eq("81cec13b777ff46348693d327fc8e7832f79bf43")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#fetch_revision_time" do
|
175
|
+
it "should capture git log" do
|
176
|
+
env.set(:branch, "branch")
|
177
|
+
backend.expects(:capture).with(:git, "log -1 --pretty=format:\"%ct\" branch").returns("1715828406")
|
178
|
+
revision_time = subject.fetch_revision_time
|
179
|
+
expect(revision_time).to eq("1715828406")
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "#verify_commit" do
|
184
|
+
it "should run git verify-commit" do
|
185
|
+
env.set(:branch, "branch")
|
186
|
+
|
187
|
+
backend.expects(:capture).with(:git, "rev-list --max-count=1 branch").returns("81cec13b777ff46348693d327fc8e7832f79bf43")
|
188
|
+
backend.expects(:execute).with(:git, :"verify-commit", "81cec13b777ff46348693d327fc8e7832f79bf43")
|
189
|
+
|
190
|
+
subject.verify_commit
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "capistrano/scm/hg"
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
describe SCM::Hg do
|
7
|
+
subject { Capistrano::SCM::Hg.new }
|
8
|
+
|
9
|
+
# This allows us to easily use `set`, `fetch`, etc. in the examples.
|
10
|
+
let(:env) { Capistrano::Configuration.env }
|
11
|
+
|
12
|
+
# Stub the SSHKit backend so we can set up expectations without the plugin
|
13
|
+
# actually executing any commands.
|
14
|
+
let(:backend) { stub }
|
15
|
+
before { SSHKit::Backend.stubs(:current).returns(backend) }
|
16
|
+
|
17
|
+
# Mimic the deploy flow tasks so that the plugin can register its hooks.
|
18
|
+
before do
|
19
|
+
Rake::Task.define_task("deploy:new_release_path")
|
20
|
+
Rake::Task.define_task("deploy:check")
|
21
|
+
Rake::Task.define_task("deploy:set_current_revision")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Clean up any tasks or variables that the plugin defined.
|
25
|
+
after do
|
26
|
+
Rake::Task.clear
|
27
|
+
Capistrano::Configuration.reset!
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#hg" do
|
31
|
+
it "should call execute hg in the context, with arguments" do
|
32
|
+
backend.expects(:execute).with(:hg, :init)
|
33
|
+
subject.hg(:init)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#repo_mirror_exists?" do
|
38
|
+
it "should call test for repo HEAD" do
|
39
|
+
env.set(:repo_path, "/path/to/repo")
|
40
|
+
backend.expects(:test).with " [ -d /path/to/repo/.hg ] "
|
41
|
+
|
42
|
+
subject.repo_mirror_exists?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#check_repo_is_reachable" do
|
47
|
+
it "should test the repo url" do
|
48
|
+
env.set(:repo_url, :url)
|
49
|
+
backend.expects(:execute).with(:hg, "id", :url)
|
50
|
+
|
51
|
+
subject.check_repo_is_reachable
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#clone_repo" do
|
56
|
+
it "should run hg clone" do
|
57
|
+
env.set(:repo_url, :url)
|
58
|
+
env.set(:repo_path, "path")
|
59
|
+
|
60
|
+
backend.expects(:execute).with(:hg, "clone", "--noupdate", :url, "path")
|
61
|
+
|
62
|
+
subject.clone_repo
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#update_mirror" do
|
67
|
+
it "should run hg update" do
|
68
|
+
backend.expects(:execute).with(:hg, "pull")
|
69
|
+
|
70
|
+
subject.update_mirror
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#archive_to_release_path" do
|
75
|
+
it "should run hg archive without a subtree" do
|
76
|
+
env.set(:branch, :branch)
|
77
|
+
env.set(:release_path, "path")
|
78
|
+
|
79
|
+
backend.expects(:execute).with(:hg, "archive", "path", "--rev", :branch)
|
80
|
+
|
81
|
+
subject.archive_to_release_path
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should run hg archive with a subtree" do
|
85
|
+
env.set(:repo_tree, "tree")
|
86
|
+
env.set(:branch, :branch)
|
87
|
+
env.set(:release_path, "path")
|
88
|
+
env.set(:tmp_dir, "/tmp")
|
89
|
+
|
90
|
+
SecureRandom.stubs(:hex).with(10).returns("random")
|
91
|
+
backend.expects(:execute).with(:hg, "archive -p . -I", "tree", "--rev", :branch, "/tmp/random.tar")
|
92
|
+
backend.expects(:execute).with(:mkdir, "-p", "path")
|
93
|
+
backend.expects(:execute).with(:tar, "-x --strip-components 1 -f", "/tmp/random.tar", "-C", "path")
|
94
|
+
backend.expects(:execute).with(:rm, "/tmp/random.tar")
|
95
|
+
|
96
|
+
subject.archive_to_release_path
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#fetch_revision" do
|
101
|
+
it "should capture hg log" do
|
102
|
+
env.set(:branch, :branch)
|
103
|
+
backend.expects(:capture).with(:hg, "log --rev branch --template \"{node}\n\"").returns("01abcde")
|
104
|
+
revision = subject.fetch_revision
|
105
|
+
expect(revision).to eq("01abcde")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "capistrano/scm/svn"
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
describe SCM::Svn do
|
7
|
+
subject { Capistrano::SCM::Svn.new }
|
8
|
+
|
9
|
+
# This allows us to easily use `set`, `fetch`, etc. in the examples.
|
10
|
+
let(:env) { Capistrano::Configuration.env }
|
11
|
+
|
12
|
+
# Stub the SSHKit backend so we can set up expectations without the plugin
|
13
|
+
# actually executing any commands.
|
14
|
+
let(:backend) { stub }
|
15
|
+
before { SSHKit::Backend.stubs(:current).returns(backend) }
|
16
|
+
|
17
|
+
# Mimic the deploy flow tasks so that the plugin can register its hooks.
|
18
|
+
before do
|
19
|
+
Rake::Task.define_task("deploy:new_release_path")
|
20
|
+
Rake::Task.define_task("deploy:check")
|
21
|
+
Rake::Task.define_task("deploy:set_current_revision")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Clean up any tasks or variables that the plugin defined.
|
25
|
+
after do
|
26
|
+
Rake::Task.clear
|
27
|
+
Capistrano::Configuration.reset!
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#svn" do
|
31
|
+
it "should call execute svn in the context, with arguments" do
|
32
|
+
env.set(:svn_username, "someuser")
|
33
|
+
env.set(:svn_password, "somepassword")
|
34
|
+
backend.expects(:execute).with(:svn, :init, "--username someuser", "--password somepassword")
|
35
|
+
subject.svn(:init)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#repo_mirror_exists?" do
|
40
|
+
it "should call test for repo HEAD" do
|
41
|
+
env.set(:repo_path, "/path/to/repo")
|
42
|
+
backend.expects(:test).with " [ -d /path/to/repo/.svn ] "
|
43
|
+
|
44
|
+
subject.repo_mirror_exists?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#check_repo_is_reachable" do
|
49
|
+
it "should test the repo url" do
|
50
|
+
env.set(:repo_url, :url)
|
51
|
+
env.set(:svn_username, "someuser")
|
52
|
+
env.set(:svn_password, "somepassword")
|
53
|
+
backend.expects(:test).with(:svn, :info, :url, "--username someuser", "--password somepassword").returns(true)
|
54
|
+
|
55
|
+
subject.check_repo_is_reachable
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#clone_repo" do
|
60
|
+
it "should run svn checkout" do
|
61
|
+
env.set(:repo_url, :url)
|
62
|
+
env.set(:repo_path, "path")
|
63
|
+
env.set(:svn_username, "someuser")
|
64
|
+
env.set(:svn_password, "somepassword")
|
65
|
+
|
66
|
+
backend.expects(:execute).with(:svn, :checkout, :url, "path", "--username someuser", "--password somepassword")
|
67
|
+
|
68
|
+
subject.clone_repo
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#update_mirror" do
|
73
|
+
it "should run svn update" do
|
74
|
+
env.set(:repo_url, "url")
|
75
|
+
env.set(:repo_path, "path")
|
76
|
+
backend.expects(:capture).with(:svn, :info, "path").returns("URL: url\n")
|
77
|
+
|
78
|
+
env.set(:svn_username, "someuser")
|
79
|
+
env.set(:svn_password, "somepassword")
|
80
|
+
backend.expects(:execute).with(:svn, :update, "--username someuser", "--password somepassword")
|
81
|
+
|
82
|
+
subject.update_mirror
|
83
|
+
end
|
84
|
+
|
85
|
+
context "for specific revision" do
|
86
|
+
it "should run svn update" do
|
87
|
+
env.set(:repo_url, "url")
|
88
|
+
env.set(:repo_path, "path")
|
89
|
+
backend.expects(:capture).with(:svn, :info, "path").returns("URL: url\n")
|
90
|
+
|
91
|
+
env.set(:svn_username, "someuser")
|
92
|
+
env.set(:svn_password, "somepassword")
|
93
|
+
env.set(:svn_revision, "12345")
|
94
|
+
backend.expects(:execute).with(:svn, :update, "--username someuser", "--password somepassword", "--revision 12345")
|
95
|
+
|
96
|
+
subject.update_mirror
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should run svn switch if repo_url is changed" do
|
101
|
+
env.set(:repo_url, "url")
|
102
|
+
env.set(:repo_path, "path")
|
103
|
+
backend.expects(:capture).with(:svn, :info, "path").returns("URL: old_url\n")
|
104
|
+
|
105
|
+
env.set(:svn_username, "someuser")
|
106
|
+
env.set(:svn_password, "somepassword")
|
107
|
+
backend.expects(:execute).with(:svn, :switch, "url", "--username someuser", "--password somepassword")
|
108
|
+
backend.expects(:execute).with(:svn, :update, "--username someuser", "--password somepassword")
|
109
|
+
|
110
|
+
subject.update_mirror
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#archive_to_release_path" do
|
115
|
+
it "should run svn export" do
|
116
|
+
env.set(:release_path, "path")
|
117
|
+
env.set(:svn_username, "someuser")
|
118
|
+
env.set(:svn_password, "somepassword")
|
119
|
+
|
120
|
+
backend.expects(:execute).with(:svn, :export, "--force", ".", "path", "--username someuser", "--password somepassword")
|
121
|
+
|
122
|
+
subject.archive_to_release_path
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#fetch_revision" do
|
127
|
+
it "should capture svn version" do
|
128
|
+
env.set(:repo_path, "path")
|
129
|
+
|
130
|
+
backend.expects(:capture).with(:svnversion, "path").returns("12345")
|
131
|
+
|
132
|
+
revision = subject.fetch_revision
|
133
|
+
expect(revision).to eq("12345")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "capistrano/scm"
|
4
|
+
|
5
|
+
module RaiseNotImplementedMacro
|
6
|
+
def raise_not_implemented_on(method)
|
7
|
+
it "should raise NotImplemented on #{method}" do
|
8
|
+
expect do
|
9
|
+
subject.send(method)
|
10
|
+
end.to raise_error(NotImplementedError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do
|
16
|
+
include RaiseNotImplementedMacro
|
17
|
+
end
|
18
|
+
|
19
|
+
module DummyStrategy
|
20
|
+
def test
|
21
|
+
test!("you dummy!")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module BlindStrategy; end
|
26
|
+
|
27
|
+
module Capistrano
|
28
|
+
describe SCM do
|
29
|
+
let(:context) { mock }
|
30
|
+
|
31
|
+
describe "#initialize" do
|
32
|
+
subject { Capistrano::SCM.new(context, DummyStrategy) }
|
33
|
+
|
34
|
+
it "should load the provided strategy" do
|
35
|
+
context.expects(:test).with("you dummy!")
|
36
|
+
subject.test
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Convenience methods" do
|
41
|
+
subject { Capistrano::SCM.new(context, BlindStrategy) }
|
42
|
+
|
43
|
+
describe "#test!" do
|
44
|
+
it "should return call test on the context" do
|
45
|
+
context.expects(:test).with(:x)
|
46
|
+
subject.test!(:x)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#repo_url" do
|
51
|
+
it "should return the repo url according to the context" do
|
52
|
+
context.expects(:repo_url).returns(:url)
|
53
|
+
expect(subject.repo_url).to eq(:url)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#repo_path" do
|
58
|
+
it "should return the repo path according to the context" do
|
59
|
+
context.expects(:repo_path).returns(:path)
|
60
|
+
expect(subject.repo_path).to eq(:path)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#release_path" do
|
65
|
+
it "should return the release path according to the context" do
|
66
|
+
context.expects(:release_path).returns("/path/to/nowhere")
|
67
|
+
expect(subject.release_path).to eq("/path/to/nowhere")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#fetch" do
|
72
|
+
it "should call fetch on the context" do
|
73
|
+
context.expects(:fetch)
|
74
|
+
subject.fetch(:branch)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "With a 'blind' strategy" do
|
80
|
+
subject { Capistrano::SCM.new(context, BlindStrategy) }
|
81
|
+
|
82
|
+
describe "#test" do
|
83
|
+
raise_not_implemented_on(:test)
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#check" do
|
87
|
+
raise_not_implemented_on(:check)
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#clone" do
|
91
|
+
raise_not_implemented_on(:clone)
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#update" do
|
95
|
+
raise_not_implemented_on(:update)
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#release" do
|
99
|
+
raise_not_implemented_on(:release)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Capistrano::UploadTask do
|
4
|
+
let(:app) { Rake.application = Rake::Application.new }
|
5
|
+
|
6
|
+
subject(:upload_task) { described_class.define_task("path/file.yml") }
|
7
|
+
|
8
|
+
it { is_expected.to be_a(Rake::FileCreationTask) }
|
9
|
+
it { is_expected.to be_needed }
|
10
|
+
|
11
|
+
context "inside namespace" do
|
12
|
+
let(:normal_task) { Rake::Task.define_task("path/other_file.yml") }
|
13
|
+
|
14
|
+
around { |ex| app.in_namespace("namespace", &ex) }
|
15
|
+
|
16
|
+
it { expect(upload_task.name).to eq("path/file.yml") }
|
17
|
+
it { expect(upload_task.scope.path).to eq("namespace") }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
describe VersionValidator do
|
5
|
+
let(:validator) { VersionValidator.new(version) }
|
6
|
+
let(:version) { stub }
|
7
|
+
|
8
|
+
describe "#new" do
|
9
|
+
it "takes a version" do
|
10
|
+
expect(validator)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#verify" do
|
15
|
+
let(:current_version) { "3.0.1" }
|
16
|
+
|
17
|
+
subject { validator.verify }
|
18
|
+
|
19
|
+
before do
|
20
|
+
validator.stubs(:current_version).returns(current_version)
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with exact version" do
|
24
|
+
context "valid" do
|
25
|
+
let(:version) { "3.0.1" }
|
26
|
+
it { expect(subject).to be_truthy }
|
27
|
+
end
|
28
|
+
|
29
|
+
context "invalid - lower" do
|
30
|
+
let(:version) { "3.0.0" }
|
31
|
+
|
32
|
+
it "fails" do
|
33
|
+
expect { subject }.to raise_error(RuntimeError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "invalid - higher" do
|
38
|
+
let(:version) { "3.0.2" }
|
39
|
+
|
40
|
+
it "fails" do
|
41
|
+
expect { subject }.to raise_error(RuntimeError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with optimistic versioning" do
|
47
|
+
context "valid" do
|
48
|
+
let(:version) { ">= 3.0.0" }
|
49
|
+
it { expect(subject).to be_truthy }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "invalid - lower" do
|
53
|
+
let(:version) { "<= 2.0.0" }
|
54
|
+
|
55
|
+
it "fails" do
|
56
|
+
expect { subject }.to raise_error(RuntimeError)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with pessimistic versioning" do
|
62
|
+
context "2 decimal places" do
|
63
|
+
context "valid" do
|
64
|
+
let(:version) { "~> 3.0.0" }
|
65
|
+
it { expect(subject).to be_truthy }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "invalid" do
|
69
|
+
let(:version) { "~> 3.1.0" }
|
70
|
+
|
71
|
+
it "fails" do
|
72
|
+
expect { subject }.to raise_error(RuntimeError)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "1 decimal place" do
|
78
|
+
let(:current_version) { "3.5.0" }
|
79
|
+
|
80
|
+
context "valid" do
|
81
|
+
let(:version) { "~> 3.1" }
|
82
|
+
it { expect(subject).to be_truthy }
|
83
|
+
end
|
84
|
+
|
85
|
+
context "invalid" do
|
86
|
+
let(:version) { "~> 3.6" }
|
87
|
+
it "fails" do
|
88
|
+
expect { subject }.to raise_error(RuntimeError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with multiple versions" do
|
94
|
+
let(:current_version) { "3.5.9" }
|
95
|
+
|
96
|
+
context "valid" do
|
97
|
+
let(:version) { [">= 3.5.0", "< 3.5.10"] }
|
98
|
+
it { is_expected.to be_truthy }
|
99
|
+
end
|
100
|
+
|
101
|
+
context "invalid" do
|
102
|
+
let(:version) { [">= 3.5.0", "< 3.5.8"] }
|
103
|
+
it "fails" do
|
104
|
+
expect { subject }.to raise_error(RuntimeError)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "invalid" do
|
109
|
+
let(:version) { ["> 3.5.9", "< 3.5.13"] }
|
110
|
+
it "fails" do
|
111
|
+
expect { subject }.to raise_error(RuntimeError)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|