Skip to content

Commit b4afa60

Browse files
mrjonesbotgeoffharcourt
authored andcommitted
Feature: #deploy to main or master refs
Checks for the presence of refs/heads/main and absence of refs/heads/master; if this condition is true, set ref to "main". If a master ref is present, set ref to "master".
1 parent a0a3250 commit b4afa60

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Push your local development database backup up to staging:
6161

6262
staging restore development
6363

64-
Deploy master to production (note that prior versions of Parity would run
64+
Deploy main to production (note that prior versions of Parity would run
6565
database migrations, that's now better handled using [Heroku release phase]):
6666

6767
production deploy

lib/parity/environment.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,27 @@ def backup
4141

4242
def deploy
4343
if production?
44-
Kernel.system("git push production master")
44+
Kernel.system("git push production #{branch_ref}")
4545
else
4646
Kernel.system(
47-
"git push #{environment} HEAD:master --force",
47+
"git push #{environment} HEAD:#{branch_ref} --force",
4848
)
4949
end
5050
end
5151

52+
def branch_ref
53+
main_ref_exists = system("git show-ref --verify --quiet refs/heads/main")
54+
master_ref_exists = system(
55+
"git show-ref --verify --quiet refs/heads/master",
56+
)
57+
58+
if main_ref_exists && !master_ref_exists
59+
"main"
60+
else
61+
"master"
62+
end
63+
end
64+
5265
def restore
5366
if production? && !forced?
5467
$stdout.puts "Parity does not support restoring backups into your "\

spec/parity/environment_spec.rb

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
backup = stub_parity_backup
1111
allow(Parity::Backup).to receive(:new).and_return(backup)
1212

13-
Parity::Environment.new("development",
14-
["restore", "staging", "--parallelize"]).run
13+
Parity::Environment.new(
14+
"development",
15+
["restore", "staging", "--parallelize"],
16+
).run
1517

1618
expect(Parity::Backup).to have_received(:new).
1719
with(
@@ -238,7 +240,7 @@
238240
once
239241
end
240242

241-
it "returns true if the deploy was succesful but no migrations needed to be run" do
243+
it "returns true if deploy was successful without migrations" do
242244
result = Parity::Environment.new("production", ["deploy"]).run
243245

244246
expect(result).to eq(true)
@@ -258,6 +260,26 @@
258260
expect(Kernel).to have_received(:system).with(git_push_feature_branch)
259261
end
260262

263+
it "deploys feature branches to staging's main for evaluation" do
264+
env = Parity::Environment.new("staging", ["deploy"])
265+
266+
allow(env).to receive(:branch_ref).and_return("main")
267+
268+
env.run
269+
270+
expect(Kernel).to have_received(:system).with(git_push_feature_branch_main)
271+
end
272+
273+
it "deploys main production's main for evaluation" do
274+
env = Parity::Environment.new("production", ["deploy"])
275+
276+
allow(env).to receive(:branch_ref).and_return("main")
277+
278+
env.run
279+
280+
expect(Kernel).to have_received(:system).with(git_push_main)
281+
end
282+
261283
def heroku_backup
262284
"heroku pg:backups:capture --remote production"
263285
end
@@ -274,10 +296,18 @@ def git_push
274296
"git push production master"
275297
end
276298

299+
def git_push_main
300+
"git push production main"
301+
end
302+
277303
def git_push_feature_branch
278304
"git push staging HEAD:master --force"
279305
end
280306

307+
def git_push_feature_branch_main
308+
"git push staging HEAD:main --force"
309+
end
310+
281311
def migrate
282312
%{
283313
heroku run rake db:migrate --remote production &&

0 commit comments

Comments
 (0)