Skip to content

Commit

Permalink
Merge pull request #102 from EugenMayer/feature/upgrade-checks
Browse files Browse the repository at this point in the history
implemented upgrade checks hooks, inform user about the unison rename…
  • Loading branch information
EugenMayer authored Aug 9, 2016
2 parents c622fd9 + 96c91aa commit 9c801b3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
59 changes: 59 additions & 0 deletions lib/docker-sync/upgrade_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'gem_update_checker'
require 'thor/actions'
require 'docker-sync/config'

class UpgradeChecker
include Thor::Shell
@config
def initialize
@config = DockerSyncConfig::global_config
end

def run
unless should_run
return
end
check_and_warn
end

def last_upgraded_version
@config['upgrade_status'] || ''
end

def should_run
# get the update_status which is the version of the update hook which has been run already
upgrade_status = last_upgraded_version
if upgrade_status == '' || Gem::Version.new(upgrade_status) < Gem::Version.new(get_current_version) # thats how we compare the version
return true
end

return false
end


def get_current_version
path = File.expand_path('../../../', __FILE__)
return File.read("#{path}/VERSION")
end

def docker_sync_update_check
gem_name = 'docker-sync'
current_version = get_current_version
checker = GemUpdateChecker::Client.new(gem_name, current_version)
return checker
end

def check_and_warn
# this is the upgrade hook for the unison-unox introduction / rename of unison
if Gem::Version.new(last_upgraded_version) < Gem::Version.new('0.1.0')
Thor::Shell::Basic.new.say_status 'warning', 'Please be aware that with the strategy "unison" is now called unison-onesided and you might need to migrate. See https://github.com/EugenMayer/docker-sync/wiki/Migration-Guide for more informations', :red
unless Thor::Shell::Basic.new.yes?('Shall we continue?')
exit 1
end
end

# update the upgrade_status
@config['upgrade_status'] = "#{get_current_version}"
DockerSyncConfig::global_config_save(@config)
end
end
4 changes: 4 additions & 0 deletions tasks/stack/stack.thor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require 'docker-sync/sync_manager'
require 'docker-sync/config'
require 'docker-sync/preconditions'
require 'docker-sync/update_check'
require 'docker-sync/upgrade_check'
require 'docker/compose'
require 'docker-sync/compose'
class Stack < Thor
Expand All @@ -15,6 +16,9 @@ class Stack < Thor
updates = UpdateChecker.new
updates.run

upgrades = UpgradeChecker.new
upgrades.run

begin
Preconditions::check_all_preconditions
rescue Exception => e
Expand Down
10 changes: 9 additions & 1 deletion tasks/sync/sync.thor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require 'docker-sync/sync_manager'
require 'docker-sync/config'
require 'docker-sync/preconditions'
require 'docker-sync/update_check'
require 'docker-sync/upgrade_check'

class Sync < Thor

Expand All @@ -13,7 +14,8 @@ class Sync < Thor
# do run update check in the start command only
updates = UpdateChecker.new
updates.run

upgrades = UpgradeChecker.new
upgrades.run
begin
Preconditions::check_all_preconditions
rescue Exception => e
Expand Down Expand Up @@ -112,5 +114,11 @@ class Sync < Thor
print_table(config) if options['verbose']
end
end
desc 'start', 'Start all sync configurations in this project'
def upgrade
# do run update check in the start command only
upgrades = UpgradeChecker.new
upgrades.run
end

end

0 comments on commit 9c801b3

Please sign in to comment.