forked from artsy/artsy.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
executable file
·96 lines (77 loc) · 2.79 KB
/
Rakefile
1
2
3
4
5
6
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
40
41
42
43
44
45
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
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env rake
desc 'Initial setup'
task :bootstrap do
puts 'Installing Bundle...'
puts `bundle install --without distribution`
end
desc 'Builds the site locally'
task :build do
puts 'Building site.'
sh 'PRODUCTION="YES" jekyll build -d _gh-pages'
end
# Deprecated, but leaving shortcut in because I'm sure Orta, at least, has this
# in his muscle-memory.
task :init => :bootstrap
namespace :serve do
desc 'Runs a local server *with* draft posts and watches for changes'
task :drafts do
puts 'Starting the server locally on http://localhost:4000'
sh 'PRODUCTION="NO" jekyll serve --watch --drafts --port 4000'
end
desc 'Runs a local server *without* draft posts and watches for changes'
task :published do
puts 'Starting the server locally on http://localhost:4000'
sh 'PRODUCTION="NO" jekyll serve --watch --port 4000'
end
end
desc 'Runs a local server with draft posts and watches for changes'
task :serve => 'serve:drafts'
desc 'Deploy the site to the gh_pages branch and push'
task :deploy do
FileUtils.rm_rf '_gh-pages'
puts 'Cloning master branch...'
puts `git clone https://github.com/artsy/artsy.github.io.git _gh-pages`
Dir.chdir('_gh-pages') do
puts `git checkout master`
end
Dir.chdir('_gh-pages') do
puts 'Pulling changes from server.'
puts `git reset --hard`
puts `git clean -xdf`
puts `git checkout master`
puts `git pull origin master`
end
Rake::Task['build'].invoke
Dir.chdir('_gh-pages') do
puts 'Pulling changes from server.'
puts `git checkout master`
puts `git pull origin master`
puts 'Creating a commit for the deploy.'
puts `git ls-files --deleted -z | xargs -0 git rm;`
puts `git add .`
puts `git commit -m "Deploy"`
puts 'Pushing to github.'
puts `git push --quiet > /dev/null 2>&1`
end
end
namespace :deploy do
namespace :travis do
task :checks do
branch = ENV['TRAVIS_BRANCH'] # Ensure this command is only run on Travis.
abort 'Must be run on Travis.' unless branch
abort "Skipping deploy for non-source branch #{branch}." if branch != 'source'
pull_request = ENV['TRAVIS_PULL_REQUEST'] #Ensure this command is only not run on pull requests
abort 'Skipping deploy from pull request.' if pull_request != 'false'
end
task :github_setup do
puts `git config --global user.email #{ENV['GIT_EMAIL']}`
puts `git config --global user.name #{ENV['GIT_NAME']}`
File.open("#{ENV['HOME']}/.netrc", 'w') { |f| f.write("machine github.com login #{ENV['GH_TOKEN']}") }
puts `chmod 600 ~/.netrc`
end
end
desc 'Run on Travis only; deploys the site when built on the source branch'
task :travis => ['deploy:travis:checks', 'deploy:travis:github_setup', :deploy]
end
desc 'Defaults to serve:drafts'
task :default => 'serve:drafts'