Sha256: 13bb6a9f21f2850e448db8956586fc601ea5aa502c633e4b9766556df85f22e2

Contents?: true

Size: 1.48 KB

Versions: 14

Compression:

Stored size: 1.48 KB

Contents

require 'awestruct/deployers'

module Awestruct
  module Deploy

    class GitHubPagesDeploy
      def initialize( site_config, deploy_config )
        @site_path = site_config.output_dir
        @branch    = deploy_config[ 'branch' ] || 'gh-pages'
      end

      def run
        git.status.changed.empty? ? publish_site : message_for(:existing_changes)
      end

      private
      def git
        @git ||= Git.open('.')
      end

      def publish_site
        current_branch = git.branch
        checkout_pages_branch
        add_and_commit_site @site_path
        push_and_restore current_branch
      end

      def checkout_pages_branch
        git.branch( @branch ).checkout
      end

      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
            $stderr.puts "Can't commit. #{e}."
          end
        end
      end

      def push_and_restore( original_branch )
        git.reset_hard
        git.push( 'origin', @branch )
        git.checkout( original_branch )
      end

      def message_for( key )
        $stderr.puts case key
        when :existing_changes 
          "You have uncommitted changes in the working branch. Please commit or stash them."
        else 
          "An error occured."
        end
      end
    end
  end
end

Awestruct::Deployers.instance[ :github_pages ] = Awestruct::Deploy::GitHubPagesDeploy

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
awestruct-0.4.4 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.3 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x10 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x9 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x8 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x7 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x6 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x5 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x4 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x3 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x2 lib/awestruct/deploy/github_pages_deploy.rb
awestruct-0.4.2.x1 lib/awestruct/deploy/github_pages_deploy.rb
awestructx-0.4.1.x1 lib/awestruct/deploy/github_pages_deploy.rb