Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Push your local development database backup up to staging:

staging restore development

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

production deploy
Expand Down
17 changes: 15 additions & 2 deletions lib/parity/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,27 @@ def backup

def deploy
if production?
Kernel.system("git push production master")
Kernel.system("git push production #{branch_ref}")
else
Kernel.system(
"git push #{environment} HEAD:master --force",
"git push #{environment} HEAD:#{branch_ref} --force",
)
end
end

def branch_ref
main_ref_exists = system("git show-ref --verify --quiet refs/heads/main")
master_ref_exists = system(
"git show-ref --verify --quiet refs/heads/master",
)

if main_ref_exists && !master_ref_exists
"main"
else
"master"
end
end

def restore
if production? && !forced?
$stdout.puts "Parity does not support restoring backups into your "\
Expand Down
36 changes: 33 additions & 3 deletions spec/parity/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
backup = stub_parity_backup
allow(Parity::Backup).to receive(:new).and_return(backup)

Parity::Environment.new("development",
["restore", "staging", "--parallelize"]).run
Parity::Environment.new(
"development",
["restore", "staging", "--parallelize"],
).run

expect(Parity::Backup).to have_received(:new).
with(
Expand Down Expand Up @@ -238,7 +240,7 @@
once
end

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

expect(result).to eq(true)
Expand All @@ -258,6 +260,26 @@
expect(Kernel).to have_received(:system).with(git_push_feature_branch)
end

it "deploys feature branches to staging's main for evaluation" do
env = Parity::Environment.new("staging", ["deploy"])

allow(env).to receive(:branch_ref).and_return("main")

env.run

expect(Kernel).to have_received(:system).with(git_push_feature_branch_main)
end

it "deploys main production's main for evaluation" do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think this is "deploys the main branch to production".

env = Parity::Environment.new("production", ["deploy"])

allow(env).to receive(:branch_ref).and_return("main")

env.run

expect(Kernel).to have_received(:system).with(git_push_main)
end

def heroku_backup
"heroku pg:backups:capture --remote production"
end
Expand All @@ -274,10 +296,18 @@ def git_push
"git push production master"
end

def git_push_main
"git push production main"
end

def git_push_feature_branch
"git push staging HEAD:master --force"
end

def git_push_feature_branch_main
"git push staging HEAD:main --force"
end

def migrate
%{
heroku run rake db:migrate --remote production &&
Expand Down