-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rakefile
80 lines (70 loc) · 1.82 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
require 'nanoc3/tasks'
BASE_URL = 'http://gurusc.heroku.com'
##
# Heroku-based Deployment
#
# Requires a Heroku Application (a heroku remote) that runs on Celadon Cedar
#
desc 'Deploy the website to Heroku using Git.'
task :deploy do
prepare!
compile!
deploy!
revert!
end
##
# Use this method to change the base url in the configuration file
# so you can automate that instead of manually changing it everytime
# when you want to deploy the website
#
def change_base_url_to(url)
puts "Changing Base URL to #{url}.."
config = YAML.load_file('./config.yaml')
config['base_url'] = url
File.open('./config.yaml', 'w') do |file|
file.write(config.to_yaml)
end
end
##
# Re-compile by removing the output directory and re-compiling
#
def compile!
puts "Compiling website.."
puts %x[rm -rf output]
puts %x[nanoc compile]
end
##
# Prepares the deployment environment
#
def prepare!
%x[git checkout master]
unless %x[git status] =~ /nothing to commit \(working directory clean\)/
puts "Please commit your changes on the master branch before deploying!"
exit 1
end
puts "Creating and moving in to \"deployment\" branch.."
puts %x[git checkout -b deployment]
puts "Removing \"output\" directory from .gitignore.."
gitignore = File.read(".gitignore")
File.open(".gitignore", "w") do |file|
file.write(gitignore.gsub("output", ""))
end
change_base_url_to(BASE_URL)
end
##
# Moves back to the "master" branch and removes the "deployment" branch
#
def revert!
%x[git checkout master]
%x[git branch -D deployment]
end
##
# Deploys the application via git to Heroku
#
def deploy!
puts "Adding and committing compiled output for deployment.."
puts %x[git add .]
puts %x[git commit -a -m "temporary commit for deployment"]
puts 'Deploying to Heroku..'
puts %x[git push heroku HEAD:master --force]
end