Skip to content
Open
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 .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.1.0
- name: Install dependencies
run: bundle install
- name: Run tests
Expand Down
21 changes: 19 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 3.1
DisplayCopNames: true
DisplayStyleGuide: true
SuggestExtensions: false
NewCops: disable

Exclude:
- 'bin/*'

Metrics/LineLength:
Layout/LineLength:
Max: 100

Style/GlobalStdStream:
Enabled: false

Style/OptionalBooleanParameter:
Enabled: false

Style/SoleNestedConditional:
Enabled: false

Style/RedundantReturn:
Enabled: false

Security/Open:
Enabled: false

Metrics/MethodLength:
Max: 20

Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.5
3.1.0
2 changes: 1 addition & 1 deletion lib/wordmove.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'English'

require 'logger'
require 'active_support'
require 'active_support/core_ext'
require 'colorize'
require 'dotenv'
require 'erb'
require 'kwalify'
require 'logger'
require 'open-uri'
require 'ostruct'
require 'thor'
Expand Down
6 changes: 6 additions & 0 deletions lib/wordmove/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def init
desc "doctor", "Do some local configuration and environment checks"
def doctor
Wordmove::Doctor.start
rescue Wordmove::MovefileNotFound => e
logger.error(e.message)
exit 1
rescue Psych::SyntaxError => e
logger.error("Your movefile is not parsable due to a syntax error: #{e.message}")
exit 1
end

shared_options = {
Expand Down
4 changes: 1 addition & 3 deletions lib/wordmove/deployer/base.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module Wordmove
module Deployer
class Base
attr_reader :options
attr_reader :logger
attr_reader :environment
attr_reader :options, :logger, :environment

class << self
def deployer_for(cli_options)
Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/deployer/ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def escape_php(string)

# replaces \ with \\
# replaces ' with \'
string.gsub('\\', '\\\\\\').gsub(/[']/, '\\\\\'')
string.gsub('\\', '\\\\\\').gsub(/'/, '\\\\\'')
end

def generate_dump_script(db, password)
Expand Down
4 changes: 2 additions & 2 deletions lib/wordmove/deployer/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize(environment, options)

@local_dump_path = local_wp_content_dir.path("dump.sql")
@local_backup_path = local_wp_content_dir.path("local-backup-#{Time.now.to_i}.sql")
@local_gzipped_dump_path = local_dump_path + '.gz'
@local_gzipped_dump_path = "#{local_dump_path}.gz"
@local_gzipped_backup_path = local_wp_content_dir
.path("#{environment}-backup-#{Time.now.to_i}.sql.gz")
end
Expand Down Expand Up @@ -86,7 +86,7 @@ def download_remote_db(local_gizipped_dump_path)

def import_remote_dump(local_gizipped_dump_path)
remote_dump_path = remote_wp_content_dir.path("dump.sql")
remote_gizipped_dump_path = remote_dump_path + '.gz'
remote_gizipped_dump_path = "#{remote_dump_path}.gz"

remote_put(local_gizipped_dump_path, remote_gizipped_dump_path)
remote_run uncompress_command(remote_gizipped_dump_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def adapt_local_db!
run wpcli_search_replace(local_options, remote_options, :wordpress_path)

local_search_replace_dump_path = local_wp_content_dir.path("search_replace_dump.sql")
local_gzipped_search_replace_dump_path = local_search_replace_dump_path + '.gz'
local_gzipped_search_replace_dump_path = "#{local_search_replace_dump_path}.gz"

save_local_db(local_search_replace_dump_path)
run compress_command(local_search_replace_dump_path)
Expand Down
12 changes: 9 additions & 3 deletions lib/wordmove/doctor/rsync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ def initialize
def check!
logger.task "Checking rsync"

if (version = /\d\.\d.\d/.match(`rsync --version | head -n1`)[0])
logger.success "rsync is installed at version #{version}"
version_output = `rsync --version | head -n1 2>&1`

if version_output.downcase.include?('openrsync')
protocol_version = version_output[/protocol version (\d+)/i, 1]
logger.success "openrsync detected (protocol version #{protocol_version || 'unknown'})"
elsif (match = /\d+\.\d+\.\d+/.match(version_output))
logger.success "rsync is installed at version #{match[0]}"
else
logger.error "rsync not found. And belive me: it's really strange it's not there."
logger.error "rsync not found or the version could not be detected. "\
"Output was: #{version_output.strip}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/movefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fetch(verbose = true)

found = entries.first
logger.task("Using Movefile: #{found}") if verbose == true
YAML.safe_load(ERB.new(File.read(found)).result, [], [], true).deep_symbolize_keys!
YAML.safe_load(ERB.new(File.read(found)).result).deep_symbolize_keys!
end

def load_dotenv(cli_options = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/sql_adapter/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def replace_field!(source_field, dest_field)
def serialized_replace!(source_field, dest_field)
length_delta = source_field.length - dest_field.length

sql_content.gsub!(/s:(\d+):([\\]*['"])(.*?)\2;/) do |_|
sql_content.gsub!(/s:(\d+):(\\*['"])(.*?)\2;/) do |_|
length = Regexp.last_match(1).to_i
delimiter = Regexp.last_match(2)
string = Regexp.last_match(3)
Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wordmove
VERSION = "5.2.2".freeze
VERSION = "5.3.0".freeze
end
32 changes: 32 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,38 @@
expect(Wordmove::Doctor).to receive(:start)
cli.invoke(:doctor, [], options)
end

context "without a movefile" do
before do
allow(Wordmove::Doctor).to receive(:start)
.and_raise(Wordmove::MovefileNotFound, "Could not find a valid Movefile.")
end

it "rescues from a MovefileNotFound exception" do
expect do
expect { cli.invoke(:doctor, [], options) }.to raise_error SystemExit
end.to output(
/Could not find a valid Movefile\./
).to_stdout_from_any_process
end
end

context "with an invalid movefile" do
before do
allow(Wordmove::Doctor).to receive(:start)
.and_raise(
Psych::SyntaxError.new(nil, 1, 1, 0, "found character that cannot start any token", nil)
)
end

it "rescues from a syntax error" do
expect do
expect { cli.invoke(:doctor, [], options) }.to raise_error SystemExit
end.to output(
/Your movefile is not parsable due to a syntax error/
).to_stdout_from_any_process
end
end
end

context "#pull" do
Expand Down
57 changes: 52 additions & 5 deletions spec/doctor/rsync_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,58 @@
describe Wordmove::Doctor::Rsync do
let(:doctor) { described_class.new }
subject(:doctor) { described_class.new }

context ".new" do
it "implements #check! method" do
expect_any_instance_of(described_class).to receive(:check!)
let(:logger) { double('logger', task: nil, success: nil, error: nil) }

silence_stream(STDOUT) { doctor.check! }
before do
allow(logger).to receive(:level=)
allow(Logger).to receive(:new).and_return(logger)
end

it "responds to #check!" do
expect(doctor).to respond_to(:check!)
end

context "when GNU rsync is installed" do
before do
allow(doctor).to receive(:`).with("rsync --version | head -n1 2>&1")
.and_return("rsync 3.2.7 protocol version 31\n")
end

it "logs the detected version" do
doctor.check!

expect(logger).to have_received(:success)
.with("rsync is installed at version 3.2.7")
end
end

context "when openrsync is installed" do
before do
allow(doctor).to receive(:`).with("rsync --version | head -n1 2>&1")
.and_return("openrsync: protocol version 29\n")
end

it "logs the detected protocol version" do
doctor.check!

expect(logger).to have_received(:success)
.with("openrsync detected (protocol version 29)")
end
end

context "when rsync is missing" do
before do
allow(doctor).to receive(:`).with("rsync --version | head -n1 2>&1")
.and_return("command not found: rsync\n")
end

it "logs an error" do
doctor.check!

expect(logger).to have_received(:error)
.with(
a_string_including("rsync not found or the version could not be detected.")
)
end
end
end
5 changes: 1 addition & 4 deletions spec/movefile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TMPDIR = "/tmp/wordmove".freeze
describe Wordmove::Movefile do
let(:movefile) { described_class.new }

Expand All @@ -8,8 +9,6 @@
end

context ".load_env" do
TMPDIR = "/tmp/wordmove".freeze

let(:path) { File.join(TMPDIR, 'movefile.yml') }
let(:dotenv_path) { File.join(TMPDIR, '.env') }
let(:yaml) { "name: Waldo\njob: Hider" }
Expand Down Expand Up @@ -41,8 +40,6 @@
end

context ".fetch" do
TMPDIR = "/tmp/wordmove".freeze

let(:path) { File.join(TMPDIR, 'movefile.yml') }
let(:yaml) { "name: Waldo\njob: Hider" }
let(:movefile) { described_class.new(nil, path) }
Expand Down
6 changes: 3 additions & 3 deletions wordmove.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "dotenv", "~> 2.7.5"
spec.add_runtime_dependency "kwalify", "~> 0"
spec.add_runtime_dependency "photocopier", "~> 1.4", ">= 1.4.0"
spec.add_runtime_dependency "thor", "~> 0.20.3"
spec.add_runtime_dependency "thor", "~> 1.3"

spec.required_ruby_version = ">= 2.6.0"
spec.required_ruby_version = ">= 3.1.0"

spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "priscilla", "~> 1.0"
spec.add_development_dependency "pry-byebug", "~> 3.1"
spec.add_development_dependency "rake", "~> 13.0.1"
spec.add_development_dependency "rspec", "~> 3.9"
spec.add_development_dependency "rubocop", "~> 0.76.0"
spec.add_development_dependency "rubocop", "~> 1.81.7"
spec.add_development_dependency "simplecov", "~> 0.17.1"

spec.post_install_message = <<-RAINBOW
Expand Down