Class: Neptuno::Services::Update

Inherits:
CLI::Base
  • Object
show all
Defined in:
lib/neptuno/services/update.rb

Overview

Update project to to latest GH master/main

Constant Summary

Constants inherited from CLI::Base

CLI::Base::ABORT_MESSAGE

Constants included from TTY::Command

TTY::Command::TTY, TTY::Command::TTYP

Constants included from TTY::Config

TTY::Config::ABORT_MESSAGE, TTY::Config::TTY

Constants included from TTY::File

TTY::File::ABORT_MESSAGE, TTY::File::TTY

Constants included from TTY::Prompt

TTY::Prompt::TTY

Instance Method Summary collapse

Methods inherited from CLI::Base

#command_service_to, #command_services_to, #initialize

Methods included from TTY::Command

#command, #command_p, #neptuno_command

Methods included from TTY::Config

#auto_restart_procs, #config, #configured_services, #docker_compose_hash, #docker_compose_services, #get_dependants, #healthy_services, #json_services_status, #running_services, #services, #services_with_procs, #starting_services

Methods included from TTY::File

#file, #in_service?, #make_service_files, #neptuno_path, #project, #service

Methods included from TTY::Prompt

#prompt

Constructor Details

This class inherits a constructor from Neptuno::CLI::Base

Instance Method Details

#call(services: [], **options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/neptuno/services/update.rb', line 14

def call(services: [], **options)
  command_services_to("update", all: options.fetch(:all), services_as_args: services) do |services|
    services.each do |service|
      puts "---Updating #{service}---"
      current_branch = `git branch --show-current`
      puts current_branch
      system("cd #{neptuno_path}/services/#{service}  2>/dev/null && git add . && git stash save -u -q neptuno_stash")
      `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout main 2>/dev/null`
      `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout master 2>/dev/null`
      system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git pull")
      unless options.fetch(:main)
        stash_id = `git stash list`.lines.find { |str| str =~ /neptuno_stash/ }&.split(":")&.first
        `cd #{neptuno_path}/services/#{service} 2>/dev/null && git checkout #{current_branch} 2>/dev/null`
        if stash_id
          puts "Applying stashed changes"
          system("cd #{neptuno_path}/services/#{service} 2>/dev/null && git stash pop -q #{stash_id}")
        end
      end
      puts ""
    end
  end
end