Class: Usmu::Github::Pages::Commands::Deploy
- Inherits:
-
Object
- Object
- Usmu::Github::Pages::Commands::Deploy
- Defined in:
- lib/usmu/github/pages/commands/deploy.rb
Instance Method Summary collapse
- #clean_destination(destination, remote, branch) ⇒ void protected
- #create_commit!(destination, message) ⇒ void protected
-
#initialize ⇒ Deploy
constructor
A new instance of Deploy.
- #run(ui, config) ⇒ void
- #working_dir_clean? ⇒ Boolean protected
Constructor Details
#initialize ⇒ Deploy
Returns a new instance of Deploy.
3 4 5 |
# File 'lib/usmu/github/pages/commands/deploy.rb', line 3 def initialize(*) @log = Logging.logger[self] end |
Instance Method Details
#clean_destination(destination, remote, branch) ⇒ void (protected)
47 48 49 50 51 52 53 |
# File 'lib/usmu/github/pages/commands/deploy.rb', line 47 def clean_destination(destination, remote, branch) Dir.chdir destination do remote = Shellwords.escape remote branch = Shellwords.escape branch `(git fetch #{remote} && git reset --hard #{remote}/#{branch}) 2>&1` end end |
#create_commit!(destination, message) ⇒ void (protected)
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/usmu/github/pages/commands/deploy.rb', line 55 def create_commit!(destination, ) Dir.chdir destination do if working_dir_clean? @log.info "Detected no changes - deploy aborted." exit 0 end `(git add . && git commit -a -m #{Shellwords.escape message}) 2>&1` if $?.exitstatus != 0 @log.fatal "Unable to create a new commit. Please check the destination folder for more information." exit 1 end end end |
#run(ui, config) ⇒ void
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/usmu/github/pages/commands/deploy.rb', line 7 def run(ui, config) remote = config['remote', default: 'origin'] branch = config['branch', default: config.default_branch(remote)] destination = ui.configuration.destination_path # Ensure we're deploying a complete commit. sha = `git rev-parse HEAD`.chomp[0, 7] unless working_dir_clean? @log.fatal("Found unsaved changes in your git repository. Please commit these changes and try again.") exit 1 end # Ensure clean worktree. @log.info("Cleaning output directory.") clean_destination(destination, remote, branch) # Regenerate site. Usmu.plugins[Usmu::Plugin::Core].command_generate({}, ) # Commit results. create_commit!(destination, "Update created by usmu-github-pages from revision #{sha}.") # Push branch to remote. @log.info("Deploying to Github...") `git push #{Shellwords.escape remote} #{Shellwords.escape branch} 2>&1` cname_file = File.('./CNAME', destination) if File.exist? cname_file @log.success("Your site should be available shortly at http://#{File.read(cname_file).chomp}/") else @log.success("Deploy completed successfully.") end end |
#working_dir_clean? ⇒ Boolean (protected)
43 44 45 |
# File 'lib/usmu/github/pages/commands/deploy.rb', line 43 def working_dir_clean? `git diff HEAD --name-only`.lines.count == 0 end |