class Awestruct::Deploy::GitHubPagesDeploy

Public Class Methods

new(site_config, deploy_config) click to toggle source
Calls superclass method Awestruct::Deploy::Base::new
# File lib/awestruct/deploy/github_pages_deploy.rb, line 8
def initialize(site_config, deploy_config)
  super
  @branch = deploy_config['branch'] || 'gh-pages'
  @repo = deploy_config['repository'] || 'origin'
end

Public Instance Methods

publish_site() click to toggle source
# File lib/awestruct/deploy/github_pages_deploy.rb, line 14
def publish_site
  tmp_branch = '__awestruct_deploy__'
  detached_branch = nil

  original_branch = git.current_branch

  # detect a detached state
  # values include (no branch), (detached from x), etc
  if original_branch.start_with? '('
    detached_branch = git.log(1).first.sha
    git.branch(original_branch = tmp_branch).checkout
  end

  # work in a branch, then revert to current branch
  git.branch(@branch).checkout
  add_and_commit_site @site_path
  git.push(@repo, @branch)

  if detached_branch
    git.checkout detached_branch
    git.branch(original_branch).delete
  else
    git.checkout original_branch
  end
end

Private Instance Methods

add_and_commit_site(path) click to toggle source
# File lib/awestruct/deploy/github_pages_deploy.rb, line 41
def add_and_commit_site(path)
  git.with_working(path) do
    git.add(".")
    begin
      git.commit("Published #{@branch} to GitHub pages.")
    rescue ::Git::GitExecuteError => e
      ExceptionHelper.log_message "Can't commit. #{e}."
      ExceptionHelper.mark_failed
    end
  end
  git.reset_hard
end
git() click to toggle source
# File lib/awestruct/deploy/github_pages_deploy.rb, line 54
def git
  @git ||= ::Git.open('.')
end