bard 2.2.0 → 3.0.0
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.
- checksums.yaml +4 -4
- data/README.md +7 -487
- data/Rakefile +1 -4
- data/bard.gemspec +2 -11
- data/lib/bard/config.rb +22 -20
- data/lib/bard/plugins/ping/target_methods.rb +0 -9
- data/lib/bard/plugins/ssh/connection.rb +2 -35
- data/lib/bard/target.rb +0 -15
- data/lib/bard/version.rb +1 -1
- data/lib/bard.rb +2 -1
- data/spec/bard/capability_spec.rb +0 -8
- data/spec/bard/config_spec.rb +30 -67
- data/spec/bard/target_spec.rb +1 -36
- metadata +4 -225
- data/ARCHITECTURE.md +0 -957
- data/CUSTOM_STRATEGIES.md +0 -701
- data/MIGRATION_GUIDE.md +0 -513
- data/PLUGINS.md +0 -99
- data/bin/bard +0 -4
- data/features/ci.feature +0 -63
- data/features/data.feature +0 -13
- data/features/deploy.feature +0 -14
- data/features/deploy_git_workflow.feature +0 -89
- data/features/run.feature +0 -14
- data/features/step_definitions/bard_steps.rb +0 -136
- data/features/support/bard-coverage +0 -16
- data/features/support/env.rb +0 -22
- data/features/support/test_server.rb +0 -216
- data/lib/bard/cli.rb +0 -44
- data/lib/bard/command.rb +0 -31
- data/lib/bard/copy.rb +0 -45
- data/lib/bard/plugins/data.rb +0 -56
- data/lib/bard/plugins/deploy/ci/github_actions.rb +0 -202
- data/lib/bard/plugins/deploy/ci/jenkins.rb +0 -176
- data/lib/bard/plugins/deploy/ci/local.rb +0 -57
- data/lib/bard/plugins/deploy/ci/runner.rb +0 -112
- data/lib/bard/plugins/deploy/ci/state.rb +0 -40
- data/lib/bard/plugins/deploy/ci.rb +0 -38
- data/lib/bard/plugins/deploy/ssh_strategy.rb +0 -26
- data/lib/bard/plugins/deploy/strategy.rb +0 -60
- data/lib/bard/plugins/deploy.rb +0 -260
- data/lib/bard/plugins/git.rb +0 -45
- data/lib/bard/plugins/github.rb +0 -152
- data/lib/bard/plugins/github_pages/strategy.rb +0 -170
- data/lib/bard/plugins/github_pages.rb +0 -35
- data/lib/bard/plugins/hurt.rb +0 -13
- data/lib/bard/plugins/install/.github/dependabot.yml +0 -18
- data/lib/bard/plugins/install/.github/workflows/cache-ci.yml +0 -15
- data/lib/bard/plugins/install/.github/workflows/ci.yml +0 -74
- data/lib/bard/plugins/install/apt_dependencies.rb +0 -33
- data/lib/bard/plugins/install/ci +0 -5
- data/lib/bard/plugins/install/setup +0 -13
- data/lib/bard/plugins/install/specified_bundler.rb +0 -15
- data/lib/bard/plugins/install/specified_ruby.rb +0 -59
- data/lib/bard/plugins/install.rb +0 -9
- data/lib/bard/plugins/open.rb +0 -20
- data/lib/bard/plugins/ping/check.rb +0 -66
- data/lib/bard/plugins/ping.rb +0 -10
- data/lib/bard/plugins/run.rb +0 -19
- data/lib/bard/plugins/setup.rb +0 -75
- data/lib/bard/plugins/ssh/copy.rb +0 -95
- data/lib/bard/plugins/ssh.rb +0 -10
- data/lib/bard/plugins/vim.rb +0 -6
- data/lib/bard/retryable.rb +0 -25
- data/lib/bard/secrets.rb +0 -10
- data/spec/acceptance/.gitignore +0 -4
- data/spec/acceptance/docker/Dockerfile +0 -36
- data/spec/acceptance/docker/test_key +0 -27
- data/spec/acceptance/docker/test_key.pub +0 -1
- data/spec/bard/ci/github_actions_spec.rb +0 -138
- data/spec/bard/ci/jenkins_spec.rb +0 -139
- data/spec/bard/ci/runner_spec.rb +0 -61
- data/spec/bard/ci_spec.rb +0 -10
- data/spec/bard/cli/ci_spec.rb +0 -170
- data/spec/bard/cli/data_spec.rb +0 -58
- data/spec/bard/cli/deploy_spec.rb +0 -243
- data/spec/bard/cli/hurt_spec.rb +0 -17
- data/spec/bard/cli/install_spec.rb +0 -19
- data/spec/bard/cli/master_key_spec.rb +0 -38
- data/spec/bard/cli/open_spec.rb +0 -51
- data/spec/bard/cli/ping_spec.rb +0 -32
- data/spec/bard/cli/run_spec.rb +0 -57
- data/spec/bard/cli/setup_spec.rb +0 -99
- data/spec/bard/cli/ssh_spec.rb +0 -40
- data/spec/bard/cli/stage_spec.rb +0 -127
- data/spec/bard/cli/vim_spec.rb +0 -28
- data/spec/bard/command_spec.rb +0 -30
- data/spec/bard/copy_spec.rb +0 -69
- data/spec/bard/deploy_strategy/github_pages_spec.rb +0 -58
- data/spec/bard/deploy_strategy/ssh_spec.rb +0 -135
- data/spec/bard/deploy_strategy_spec.rb +0 -107
- data/spec/bard/dynamic_dsl_spec.rb +0 -46
- data/spec/bard/git_spec.rb +0 -101
- data/spec/bard/github_spec.rb +0 -45
- data/spec/bard/ping_spec.rb +0 -60
- data/spec/bard/ssh_copy_spec.rb +0 -44
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard deploy" do
|
|
5
|
-
let(:deploy_strategy) { double("deploy_strategy", deploy: true) }
|
|
6
|
-
let(:production_server) { double("production", run!: true, path: "/var/www/test_project", deploy_strategy: :ssh, deploy_strategy_instance: deploy_strategy) }
|
|
7
|
-
let(:config) { { production: production_server } }
|
|
8
|
-
let(:cli) { Bard::CLI.new }
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
allow(config).to receive(:ci).and_return(nil)
|
|
12
|
-
allow(cli).to receive(:config).and_return(config)
|
|
13
|
-
allow(cli).to receive(:options).and_return({ target: "production" })
|
|
14
|
-
allow(cli).to receive(:puts)
|
|
15
|
-
allow(cli).to receive(:exit)
|
|
16
|
-
allow(cli).to receive(:run!)
|
|
17
|
-
allow(cli).to receive(:invoke)
|
|
18
|
-
allow(cli).to receive(:ping)
|
|
19
|
-
allow(cli).to receive(:project_name).and_return("test_project")
|
|
20
|
-
allow(cli).to receive(:green).and_return("")
|
|
21
|
-
allow(cli).to receive(:red).and_return("")
|
|
22
|
-
allow(cli).to receive(:yellow).and_return("")
|
|
23
|
-
allow(Bard::Git).to receive(:current_branch).and_return("feature-branch")
|
|
24
|
-
allow(Bard::Git).to receive(:up_to_date_with_remote?).and_return(true)
|
|
25
|
-
allow(Bard::Git).to receive(:fast_forward_merge?).and_return(true)
|
|
26
|
-
allow(Bard::Git).to receive(:in_linked_worktree?).and_return(false)
|
|
27
|
-
allow(cli).to receive(:`).and_return("")
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe "#deploy" do
|
|
31
|
-
it "should have a deploy command" do
|
|
32
|
-
expect(cli).to respond_to(:deploy)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "when on master branch" do
|
|
36
|
-
before do
|
|
37
|
-
allow(Bard::Git).to receive(:current_branch).and_return("master")
|
|
38
|
-
allow(cli).to receive(:options).and_return({ target: "production" })
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
context "when up to date with remote" do
|
|
42
|
-
it "skips push and runs CI then deploys" do
|
|
43
|
-
allow(Bard::Git).to receive(:up_to_date_with_remote?).and_return(true)
|
|
44
|
-
|
|
45
|
-
expect(cli).not_to receive(:run!).with(/git push/)
|
|
46
|
-
expect(cli).to receive(:invoke).with(:ci, ["master"], {})
|
|
47
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
48
|
-
expect(cli).to receive(:ping).with(:production)
|
|
49
|
-
|
|
50
|
-
cli.deploy
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context "when not up to date with remote" do
|
|
55
|
-
it "pushes master then runs CI and deploys" do
|
|
56
|
-
allow(Bard::Git).to receive(:up_to_date_with_remote?).and_return(false)
|
|
57
|
-
|
|
58
|
-
expect(cli).to receive(:run!).with("git push origin master:master")
|
|
59
|
-
expect(cli).to receive(:invoke).with(:ci, ["master"], {})
|
|
60
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
61
|
-
|
|
62
|
-
cli.deploy
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context "with skip-ci option" do
|
|
67
|
-
it "skips CI step" do
|
|
68
|
-
allow(cli).to receive(:options).and_return({ "skip-ci" => true, target: "production" })
|
|
69
|
-
|
|
70
|
-
expect(cli).not_to receive(:invoke).with(:ci, anything, anything)
|
|
71
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
72
|
-
|
|
73
|
-
cli.deploy
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context "with ci disabled in config" do
|
|
78
|
-
it "skips CI step" do
|
|
79
|
-
allow(config).to receive(:ci).and_return(false)
|
|
80
|
-
|
|
81
|
-
expect(cli).not_to receive(:invoke).with(:ci, anything, anything)
|
|
82
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
83
|
-
|
|
84
|
-
cli.deploy
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context "when on feature branch" do
|
|
90
|
-
before do
|
|
91
|
-
allow(cli).to receive(:options).and_return({ target: "production" })
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
context "with fast-forward merge possible" do
|
|
95
|
-
it "fetches master, pushes branch, runs CI, merges to master, and deploys" do
|
|
96
|
-
expect(cli).to receive(:run!).with("git fetch origin")
|
|
97
|
-
expect(cli).to receive(:run!).with("git fetch origin master:master").twice
|
|
98
|
-
expect(cli).to receive(:run!).with("git push -f origin feature-branch:feature-branch")
|
|
99
|
-
expect(cli).to receive(:invoke).with(:ci, ["feature-branch"], {})
|
|
100
|
-
expect(cli).to receive(:run!).with("git push origin feature-branch:master")
|
|
101
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
102
|
-
|
|
103
|
-
cli.deploy
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "deletes the feature branch after successful deploy" do
|
|
107
|
-
expect(cli).to receive(:puts).with("Deleting branch: feature-branch")
|
|
108
|
-
expect(cli).to receive(:run!).with("git push --delete origin feature-branch")
|
|
109
|
-
expect(cli).to receive(:run!).with("git checkout master")
|
|
110
|
-
expect(cli).to receive(:run!).with("git branch -D feature-branch")
|
|
111
|
-
|
|
112
|
-
cli.deploy
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
context "when run from a linked worktree" do
|
|
117
|
-
before do
|
|
118
|
-
allow(Bard::Git).to receive(:in_linked_worktree?).and_return(true)
|
|
119
|
-
allow(cli).to receive(:`).with("git rev-parse --git-common-dir").and_return("/main/checkout/.git\n")
|
|
120
|
-
allow(Dir).to receive(:pwd).and_return("/main/checkout/tmp/worktrees/feature-branch")
|
|
121
|
-
allow(Dir).to receive(:chdir).with("/main/checkout")
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it "skips writes to local master, removes the worktree, and reports where to cd back" do
|
|
125
|
-
expect(cli).not_to receive(:run!).with("git fetch origin master:master")
|
|
126
|
-
expect(cli).not_to receive(:run!).with("git checkout master")
|
|
127
|
-
expect(cli).to receive(:run!).with("git fetch origin master")
|
|
128
|
-
expect(Dir).to receive(:chdir).with("/main/checkout")
|
|
129
|
-
expect(cli).to receive(:run!).with("git worktree remove /main/checkout/tmp/worktrees/feature-branch")
|
|
130
|
-
expect(cli).to receive(:run!).with("git branch -D feature-branch")
|
|
131
|
-
expect(cli).to receive(:puts).with("Worktree removed. Run: cd /main/checkout")
|
|
132
|
-
|
|
133
|
-
cli.deploy
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context "when rebase is needed" do
|
|
138
|
-
it "attempts rebase before proceeding" do
|
|
139
|
-
allow(Bard::Git).to receive(:fast_forward_merge?).and_return(false)
|
|
140
|
-
|
|
141
|
-
expect(cli).to receive(:puts).with("The master branch has advanced. Attempting rebase...")
|
|
142
|
-
expect(cli).to receive(:run!).with("git rebase origin/master")
|
|
143
|
-
expect(cli).to receive(:run!).with("git push -f origin feature-branch:feature-branch")
|
|
144
|
-
|
|
145
|
-
cli.deploy
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
context "when on feature branch with ci disabled in config" do
|
|
151
|
-
before do
|
|
152
|
-
allow(cli).to receive(:options).and_return({ target: "production" })
|
|
153
|
-
allow(config).to receive(:ci).and_return(false)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "skips CI step" do
|
|
157
|
-
expect(cli).not_to receive(:invoke).with(:ci, anything, anything)
|
|
158
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
159
|
-
|
|
160
|
-
cli.deploy
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
context "with github remote" do
|
|
165
|
-
it "pushes to github remote" do
|
|
166
|
-
allow(cli).to receive(:`).with("git remote").and_return("origin\ngithub\n")
|
|
167
|
-
|
|
168
|
-
expect(cli).to receive(:run!).with("git push github")
|
|
169
|
-
|
|
170
|
-
cli.deploy
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
context "with clone option" do
|
|
175
|
-
it "deploys with clone option to strategy" do
|
|
176
|
-
allow(cli).to receive(:options).and_return({ clone: true, target: "production" })
|
|
177
|
-
|
|
178
|
-
expect(deploy_strategy).to receive(:deploy).with(clone: "test_project")
|
|
179
|
-
|
|
180
|
-
cli.deploy
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
context "with github pages" do
|
|
185
|
-
let(:deploy_strategy) { double("github_pages_strategy") }
|
|
186
|
-
let(:production_server) { double("production", run!: true, path: "/var/www/test_project", deploy_strategy: :github_pages, deploy_strategy_instance: deploy_strategy) }
|
|
187
|
-
|
|
188
|
-
it "deploys using deploy strategy" do
|
|
189
|
-
expect(deploy_strategy).to receive(:deploy)
|
|
190
|
-
|
|
191
|
-
cli.deploy
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
context "with custom deployment target" do
|
|
196
|
-
let(:staging_strategy) { double("staging_strategy", deploy: true) }
|
|
197
|
-
let(:staging_server) { double("staging", run!: true, deploy_strategy: :ssh, deploy_strategy_instance: staging_strategy) }
|
|
198
|
-
|
|
199
|
-
before do
|
|
200
|
-
allow(config).to receive(:[]).with(:staging).and_return(staging_server)
|
|
201
|
-
allow(cli).to receive(:options).and_return({ target: "staging" })
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "deploys to specified target" do
|
|
205
|
-
expect(staging_strategy).to receive(:deploy)
|
|
206
|
-
expect(cli).to receive(:ping).with(:staging)
|
|
207
|
-
|
|
208
|
-
cli.deploy
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
context "when command fails" do
|
|
213
|
-
it "handles errors gracefully" do
|
|
214
|
-
allow(cli).to receive(:run!).and_raise(Bard::Command::Error.new("Git push failed"))
|
|
215
|
-
|
|
216
|
-
expect(cli).to receive(:puts).with(/Running command failed/)
|
|
217
|
-
expect(cli).to receive(:exit).with(1)
|
|
218
|
-
|
|
219
|
-
cli.deploy
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
context "with local-ci option" do
|
|
224
|
-
it "passes local-ci option to CI invocation" do
|
|
225
|
-
allow(cli).to receive(:options).and_return({ "local-ci" => true, target: "production" })
|
|
226
|
-
|
|
227
|
-
expect(cli).to receive(:invoke).with(:ci, ["feature-branch"], { "local-ci" => true })
|
|
228
|
-
|
|
229
|
-
cli.deploy
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
context "with ci option" do
|
|
234
|
-
it "passes ci option to CI invocation" do
|
|
235
|
-
allow(cli).to receive(:options).and_return({ "ci" => "jenkins", target: "production" })
|
|
236
|
-
|
|
237
|
-
expect(cli).to receive(:invoke).with(:ci, ["feature-branch"], { "ci" => "jenkins" })
|
|
238
|
-
|
|
239
|
-
cli.deploy
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
end
|
data/spec/bard/cli/hurt_spec.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard hurt" do
|
|
5
|
-
let(:cli) { Bard::CLI.new }
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
allow(cli).to receive(:puts)
|
|
9
|
-
allow(cli).to receive(:system)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "#hurt" do
|
|
13
|
-
it "should have a hurt command" do
|
|
14
|
-
expect(cli).to respond_to(:hurt)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard install" do
|
|
5
|
-
let(:cli) { Bard::CLI.new }
|
|
6
|
-
|
|
7
|
-
describe "#install" do
|
|
8
|
-
it "should have an install command" do
|
|
9
|
-
expect(cli).to respond_to(:install)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it "should copy install files to bin directory" do
|
|
13
|
-
expect(cli).to receive(:system).with(/cp -R .*plugins\/install\/\* bin\//)
|
|
14
|
-
expect(cli).to receive(:system).with(/cp -R .*plugins\/install\/\.github \.\//)
|
|
15
|
-
|
|
16
|
-
cli.install
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard master_key" do
|
|
5
|
-
let(:from_server) { double("production") }
|
|
6
|
-
let(:to_server) { double("local") }
|
|
7
|
-
let(:config) { { production: from_server, local: to_server } }
|
|
8
|
-
let(:cli) { Bard::CLI.new }
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
allow(cli).to receive(:config).and_return(config)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#master_key" do
|
|
15
|
-
it "should have a master_key command" do
|
|
16
|
-
expect(cli).to respond_to(:master_key)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "should copy master key from production to local by default" do
|
|
20
|
-
allow(config).to receive(:[]).with("production").and_return(from_server)
|
|
21
|
-
allow(config).to receive(:[]).with("local").and_return(to_server)
|
|
22
|
-
allow(cli).to receive(:options).and_return({ from: "production", to: "local" })
|
|
23
|
-
expect(Bard::Copy).to receive(:file).with("config/master.key", from: from_server, to: to_server)
|
|
24
|
-
|
|
25
|
-
cli.master_key
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "should copy master key with custom servers" do
|
|
29
|
-
staging_server = double("staging")
|
|
30
|
-
allow(config).to receive(:[]).with("production").and_return(staging_server)
|
|
31
|
-
allow(config).to receive(:[]).with("local").and_return(to_server)
|
|
32
|
-
allow(cli).to receive(:options).and_return({ from: "production", to: "local" })
|
|
33
|
-
expect(Bard::Copy).to receive(:file).with("config/master.key", from: staging_server, to: to_server)
|
|
34
|
-
|
|
35
|
-
cli.master_key
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
data/spec/bard/cli/open_spec.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard open" do
|
|
5
|
-
let(:target) { double("target", url: "https://example.com", require_capability!: nil) }
|
|
6
|
-
let(:config) { { production: target } }
|
|
7
|
-
let(:cli) { Bard::CLI.new }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
allow(cli).to receive(:config).and_return(config)
|
|
11
|
-
allow(cli).to receive(:project_name).and_return("test_project")
|
|
12
|
-
allow(cli).to receive(:exec)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe "#open" do
|
|
16
|
-
it "should have an open command" do
|
|
17
|
-
expect(cli).to respond_to(:open)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should open production target URL by default" do
|
|
21
|
-
expect(cli).to receive(:exec).with("xdg-open https://example.com")
|
|
22
|
-
|
|
23
|
-
cli.open
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should open specified target URL" do
|
|
27
|
-
staging_server = double("staging", url: "https://staging.example.com", require_capability!: nil)
|
|
28
|
-
allow(config).to receive(:[]).with(:staging).and_return(staging_server)
|
|
29
|
-
|
|
30
|
-
expect(cli).to receive(:exec).with("xdg-open https://staging.example.com")
|
|
31
|
-
|
|
32
|
-
cli.open(:staging)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "should open CI URL when target is ci" do
|
|
36
|
-
expect(cli).to receive(:exec).with("xdg-open https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
|
|
37
|
-
|
|
38
|
-
cli.open(:ci)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe "#open_url" do
|
|
43
|
-
it "returns CI URL for ci target" do
|
|
44
|
-
expect(cli.open_url(:ci)).to eq("https://github.com/botandrosedesign/test_project/actions/workflows/ci.yml")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "returns target url for other targets" do
|
|
48
|
-
expect(cli.open_url(:production)).to eq("https://example.com")
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
data/spec/bard/cli/ping_spec.rb
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
require "thor"
|
|
4
|
-
|
|
5
|
-
describe "bard ping" do
|
|
6
|
-
let(:target) { double("target", ping: ["https://example.com"]) }
|
|
7
|
-
let(:config) { double("config", targets: { production: target }) }
|
|
8
|
-
let(:cli) { Bard::CLI.new }
|
|
9
|
-
|
|
10
|
-
before do
|
|
11
|
-
allow(cli).to receive(:config).and_return(config)
|
|
12
|
-
allow(config).to receive(:[]).with(:production).and_return(target)
|
|
13
|
-
allow(cli).to receive(:puts)
|
|
14
|
-
allow(cli).to receive(:exit)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#ping" do
|
|
18
|
-
it "should call Bard::Ping with the target" do
|
|
19
|
-
expect(Bard::Ping).to receive(:call).with(target).and_return([])
|
|
20
|
-
|
|
21
|
-
cli.ping
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should print down URLs when they exist" do
|
|
25
|
-
down_urls = ["https://down.example.com"]
|
|
26
|
-
allow(Bard::Ping).to receive(:call).and_return(down_urls)
|
|
27
|
-
expect(cli).to receive(:puts).with("https://down.example.com is down!")
|
|
28
|
-
|
|
29
|
-
cli.ping
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
data/spec/bard/cli/run_spec.rb
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard run" do
|
|
5
|
-
let(:target) { double("target") }
|
|
6
|
-
let(:config) { { production: target } }
|
|
7
|
-
let(:cli) { Bard::CLI.new }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
allow(cli).to receive(:config).and_return(config)
|
|
11
|
-
allow(cli).to receive(:puts)
|
|
12
|
-
allow(cli).to receive(:exit)
|
|
13
|
-
allow(cli).to receive(:red).and_return("")
|
|
14
|
-
allow(cli).to receive(:yellow).and_return("")
|
|
15
|
-
allow(cli).to receive(:options).and_return({ target: "production" })
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "#run" do
|
|
19
|
-
it "should have a run command" do
|
|
20
|
-
expect(cli).to respond_to(:run)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should run command on production target" do
|
|
24
|
-
expect(target).to receive(:run!).with("ls -la", verbose: true, home: nil)
|
|
25
|
-
|
|
26
|
-
cli.run("ls", "-la")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should run command on specified target" do
|
|
30
|
-
staging_server = double("staging_target")
|
|
31
|
-
allow(cli).to receive(:config).and_return(config.merge(staging: staging_server))
|
|
32
|
-
allow(cli).to receive(:options).and_return({ target: "staging" })
|
|
33
|
-
|
|
34
|
-
expect(staging_server).to receive(:run!).with("ls -la", verbose: true, home: nil)
|
|
35
|
-
|
|
36
|
-
cli.run("ls", "-la")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "should pass home option to target" do
|
|
40
|
-
allow(cli).to receive(:options).and_return({ target: "production", home: true })
|
|
41
|
-
|
|
42
|
-
expect(target).to receive(:run!).with("ls -la", verbose: true, home: true)
|
|
43
|
-
|
|
44
|
-
cli.run("ls", "-la")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "should handle command errors" do
|
|
48
|
-
error = Bard::Command::Error.new("Command failed")
|
|
49
|
-
allow(target).to receive(:run!).and_raise(error)
|
|
50
|
-
|
|
51
|
-
expect(cli).to receive(:puts).with(/Running command failed/)
|
|
52
|
-
expect(cli).to receive(:exit).with(1)
|
|
53
|
-
|
|
54
|
-
cli.run("failing-command")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
data/spec/bard/cli/setup_spec.rb
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard setup" do
|
|
5
|
-
let(:cli) { Bard::CLI.new }
|
|
6
|
-
|
|
7
|
-
before do
|
|
8
|
-
allow(cli).to receive(:project_name).and_return("test_project")
|
|
9
|
-
allow(Dir).to receive(:pwd).and_return("/home/user/project")
|
|
10
|
-
allow(File).to receive(:exist?).and_return(false)
|
|
11
|
-
allow(cli).to receive(:system)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#setup" do
|
|
15
|
-
before { allow(cli).to receive(:nginx_server_name).and_return("test_project.localhost") }
|
|
16
|
-
|
|
17
|
-
it "should have a setup command" do
|
|
18
|
-
expect(cli).to respond_to(:setup)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
context "in production" do
|
|
22
|
-
before do
|
|
23
|
-
allow(ENV).to receive(:[]).and_call_original
|
|
24
|
-
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production")
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "creates an nginx reverse proxy config" do
|
|
28
|
-
expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*proxy_pass http:\/\/puma/m)
|
|
29
|
-
expect(cli).to receive(:system).with(/sudo ln -sf/)
|
|
30
|
-
expect(cli).to receive(:system).with("sudo service nginx restart")
|
|
31
|
-
|
|
32
|
-
cli.setup
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "in staging" do
|
|
37
|
-
before do
|
|
38
|
-
allow(ENV).to receive(:[]).and_call_original
|
|
39
|
-
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("staging")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "creates a Passenger nginx config, not a puma reverse proxy" do
|
|
43
|
-
expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*include \/etc\/nginx\/snippets\/common\.conf/m)
|
|
44
|
-
expect(cli).not_to receive(:system).with(/proxy_pass http:\/\/puma/m)
|
|
45
|
-
expect(cli).to receive(:system).with(/sudo ln -sf/)
|
|
46
|
-
expect(cli).to receive(:system).with("sudo service nginx restart")
|
|
47
|
-
|
|
48
|
-
cli.setup
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context "in development" do
|
|
53
|
-
before do
|
|
54
|
-
allow(ENV).to receive(:[]).and_call_original
|
|
55
|
-
allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("development")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "creates an nginx config that includes the shared dev snippet" do
|
|
59
|
-
expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*include \/etc\/nginx\/snippets\/common\.conf/m)
|
|
60
|
-
expect(cli).to receive(:system).with(/sudo ln -sf/)
|
|
61
|
-
expect(cli).to receive(:system).with("sudo service nginx restart")
|
|
62
|
-
|
|
63
|
-
cli.setup
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe "#nginx_server_name" do
|
|
69
|
-
let(:production_server) { double("production", url: "https://example.com") }
|
|
70
|
-
|
|
71
|
-
before do
|
|
72
|
-
allow(cli).to receive(:config).and_return({ production: production_server })
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context "when RAILS_ENV is production" do
|
|
76
|
-
before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production") }
|
|
77
|
-
|
|
78
|
-
it "returns production server names with wildcard" do
|
|
79
|
-
expect(cli.nginx_server_name).to eq("*.example.com _")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "when RAILS_ENV is staging" do
|
|
84
|
-
before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("staging") }
|
|
85
|
-
|
|
86
|
-
it "returns staging server name" do
|
|
87
|
-
expect(cli.nginx_server_name).to eq("test_project.botandrose.com")
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
context "when RAILS_ENV is development" do
|
|
92
|
-
before { allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("development") }
|
|
93
|
-
|
|
94
|
-
it "returns localhost server name" do
|
|
95
|
-
expect(cli.nginx_server_name).to eq("test_project.localhost")
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
data/spec/bard/cli/ssh_spec.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/cli"
|
|
3
|
-
|
|
4
|
-
describe "bard ssh" do
|
|
5
|
-
let(:target) { double("target") }
|
|
6
|
-
let(:config) { { production: target } }
|
|
7
|
-
let(:cli) { Bard::CLI.new }
|
|
8
|
-
|
|
9
|
-
before do
|
|
10
|
-
allow(cli).to receive(:config).and_return(config)
|
|
11
|
-
allow(cli).to receive(:options).and_return({ home: false })
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "#ssh" do
|
|
15
|
-
it "should have an ssh command" do
|
|
16
|
-
expect(cli).to respond_to(:ssh)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "should execute shell on production target by default" do
|
|
20
|
-
expect(target).to receive(:exec!).with("exec $SHELL -l", home: false)
|
|
21
|
-
|
|
22
|
-
cli.ssh
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should execute shell with home option when specified" do
|
|
26
|
-
allow(cli).to receive(:options).and_return({ home: true })
|
|
27
|
-
expect(target).to receive(:exec!).with("exec $SHELL -l", home: true)
|
|
28
|
-
|
|
29
|
-
cli.ssh
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should connect to specified target" do
|
|
33
|
-
staging_server = double("staging")
|
|
34
|
-
allow(config).to receive(:[]).with(:staging).and_return(staging_server)
|
|
35
|
-
expect(staging_server).to receive(:exec!).with("exec $SHELL -l", home: false)
|
|
36
|
-
|
|
37
|
-
cli.ssh(:staging)
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|