forked from 18F/18f.gsa.gov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo
executable file
·168 lines (149 loc) · 3.97 KB
/
go
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#! /usr/bin/env ruby
#
# Go script for building the 18F site
#
# Written in 2015 by Mike Bland ([email protected]) and Greg Boone
# ([email protected]) on behalf of the 18F team, part of the US General
# Services Administration: https://18f.gsa.gov/
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
# <https://creativecommons.org/publicdomain/zero/1.0/>.
#
# @author Mike Bland ([email protected])
# @author Greg Boone ([email protected])
#
# ----
#
# ./go script: unified development environment interface
#
# Inspired by:
# http://www.thoughtworks.com/insights/blog/praise-go-script-part-i
# http://www.thoughtworks.com/insights/blog/praise-go-script-part-ii
#
# Author: Mike Bland ([email protected])
# Date: 2015-01-10
def exec_cmd(cmd)
exit $?.exitstatus unless system(cmd, :err => :out)
end
def init
begin
require 'bundler'
rescue LoadError
puts "Installing Bundler gem..."
exec_cmd 'gem install bundler'
puts "Bundler installed; installing gems"
end
exec_cmd 'bundle install'
end
def update_gems(development=true)
# Installs and updates gems to the correct version, in case it's been a while
if development
exec_cmd 'bundle install'
else
exec_cmd 'bundle install --without development'
end
end
def update_data
ruby = exec_cmd 'which ruby'
exec_cmd "ruby _data/import-public.rb"
end
def serve
exec 'bundle exec jekyll serve --trace --incremental'
end
def build(watch = false, config=false)
puts 'Building the site...'
cmd = 'bundle exec jekyll b --trace --incremental'
if watch == false
cmd = "#{cmd} --no-watch"
end
if config
cmd = "#{cmd} --config _config.yml,#{config}"
end
puts(cmd)
exec_cmd(cmd)
puts 'Site built successfully.'
end
def ci_build
reset
build
test
puts 'Done!'
end
def server_build
puts 'Fetching from git'
exec_cmd 'git fetch origin staging'
exec_cmd 'git reset --hard origin/staging'
update_gems(development=false)
reset
puts 'building site'
build
require 'time'
puts Time.now()
end
def production_build
puts 'Fetching from git'
exec_cmd 'git fetch origin staging'
exec_cmd 'git reset --hard origin/staging'
update_gems
reset
puts 'building site'
build(watch=false, config="_config-deploy.yml")
require 'time'
puts Time.now()
end
def cf_deploy
build
test
exec_cmd('sh deploy/cf-deploy.sh')
end
def test
exec_cmd('bundle exec deploy/tests/test.rb')
exec_cmd('bundle exec jekyll test')
end
def pre_deploy
ci_build
end
def reset
exec_cmd('bundle exec jekyll clean')
end
COMMANDS = {
:init => 'Set up the 18f.gsa.gov dev environment',
:update_gems => 'Update your rubygems, do this if you have problems building',
:update_data => 'Updates data files from the public Hub',
:serve => 'Serves the site at localhost:4000',
:build => 'Builds the site',
:ci_build => 'Builds the site for a CI system',
:server_build => 'Pulls from git and builds the site with `jekyll-get` enabled',
:cf_deploy => 'Deploys to cloudfoundry',
:production_build => 'Deploys to production using a second config file',
:test => 'Tests the fontmatter and site build.',
:pre_deploy => 'Builds the site and runs associated tests',
:reset => 'Clears the build cache'
}
def usage(exitstatus: 0)
puts <<EOF
Usage: #{$0} [options] [command]
options:
-h,--help Show this help
commands:
EOF
padding = COMMANDS.keys.max_by {|i| i.size}.size + 2
COMMANDS.each do |name, desc|
puts " %-#{padding}s#{desc}" % name
end
exit exitstatus
end
usage(exitstatus: 1) unless ARGV.size == 1
command = ARGV.shift
usage if ['-h', '--help'].include? command
command = command.to_sym
unless COMMANDS.member? command
puts "Unknown option or command: #{command}"
usage(exitstatus: 1)
end
send command