Module: JekyllGitDeploy
- Includes:
- CommonTasks
- Defined in:
- lib/jekyll_git_deploy.rb
Constant Summary
Constants included from CommonTasks
CommonTasks::CONFIG_DEFAULTS, CommonTasks::CONFIG_FILE, CommonTasks::REQUIRED_CONFIGS
Instance Method Summary collapse
-
#deploy ⇒ Object
Build and push(deploy) the newest generated site.
-
#init ⇒ Object
Initialize the deploy environment.
Methods included from CommonTasks
#commit_newest_site, #current_branch, included, #read_configs
Instance Method Details
#deploy ⇒ Object
Build and push(deploy) the newest generated site
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jekyll_git_deploy.rb', line 46 def deploy puts "\nGenerating the newest site".yellow `jekyll build` # This step is only for sites requiring some special file to detect running environment unless destination.empty? puts "\nTouching Staticfile".yellow `touch #{destination}/Staticfile` end puts "\nruning `cd #{destination}`".yellow Dir.chdir destination do if `git branch`.empty? # Fully new git repo commit_newest_site puts "\nThis is a new git repo, creating new branch #{deploy_branch} now".yellow `git checkout -b #{deploy_branch} &> /dev/null && git merge #{current_branch}` else unless current_branch == deploy_branch puts "\nStart to checkout to deploy branch: #{deploy_branch}".yellow if `git show-branch #{deploy_branch} 2> /dev/null`.empty? # the deploy branch didn't exist `git checkout -b #{deploy_branch}` else `git checkout #{deploy_branch}` end end commit_newest_site end puts "\nPushing newest generated site:".yellow `git push -u #{deploy_remote_name} #{deploy_branch}` puts "\nThe deploy is finished!".green baseurl = read_configs['baseurl'] || "" `open "#{baseurl}"` if baseurl =~ /https?:\/\/\S+/ end end |
#init ⇒ Object
Initialize the deploy environment
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 40 41 42 |
# File 'lib/jekyll_git_deploy.rb', line 10 def init configs = read_configs puts "Start to initialize the git repo at #{destination}".yellow unless deploy_repo && !deploy_repo.strip.empty? raise "You haven't specify any deploy repo in _config.yml file, the action can not continue!".red end file = File.open('.gitignore', 'r+') existed_line = file.readlines.select{|line| line.strip == destination} unless existed_line puts "\nadd #{destination} directory to .gitignore".yellow file.puts destination end file.close `mkdir -p #{Dir.pwd}/#{destination}` puts "\nruning `cd #{destination}`".yellow Dir.chdir destination do # Determine if there has been any git repo existed unless File.directory? ".git" `git init` end puts "\nStart to add remote url".yellow `git remote add #{deploy_remote_name} #{deploy_repo} 2> /dev/null` puts "\nCurrent git remotes:\n==========================".yellow puts `git remote -v` puts "\nFinished deploy initialization for the current site".green end end |