forked from fastlane-old/countdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
178 lines (152 loc) · 4.78 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
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
169
170
171
172
173
174
175
176
177
178
GEMS = %w(fastlane fastlane_core deliver snapshot frameit pem sigh produce cert gym pilot credentials_manager spaceship scan supply watchbuild danger)
RAILS = %w(boarding refresher enhancer)
#####################################################
# @!group Everything to be executed in the root folder containing all fastlane repos
#####################################################
desc 'Setup the fastlane development environment'
task :bootstrap do
system('gem install bundler') unless system('which bundle')
Rake::Task[:clone].invoke
Rake::Task[:install].invoke
box 'You are up and running'
end
desc 'Clones all the repositories. Use `bootstrap` if you want to clone + install all gems'
task :clone do
(GEMS + RAILS).each do |repo|
if File.directory? repo
sh "cd #{repo} && git pull"
else
sh "git clone https://github.com/fastlane/#{repo}"
end
end
end
desc 'Run `bundle update` for all the gems.'
task :bundle do
GEMS.each do |repo|
sh "cd #{repo} && bundle update"
end
end
desc 'Run `bundle update` and `rake install` for all the gems.'
task install: :bundle do
GEMS.each do |repo|
sh "cd #{repo} && rake install"
end
end
desc 'Show the un-commited changes from all repos'
task :diff do
(GEMS + RAILS).each do |repo|
output = `cd #{repo} && git diff --stat` # not using `sh` as it gets you into its own view
if (output || '').length > 0
box repo
puts output
end
end
end
desc 'Pulls the latest changes from all the gems repos'
task :pull do
sh 'git pull' # the countdown repo itself
(GEMS + RAILS).each do |repo|
sh "cd #{repo} && git pull"
end
end
desc 'Fetches the latest rubocop config from the fastlane main repo'
task :fetch_rubocop do
fl_path = './fastlane/.rubocop_general.yml'
fail 'Could not find rubocop configuration in fastlane repository' unless File.exist?(fl_path)
rubocop_file = File.read(fl_path)
GEMS.each do |repo|
next if repo == 'fastlane' # we don't want to overwrite the main repo's config
path = File.join(repo, '.rubocop_general.yml')
if File.exist?(path)
# we only want to store the file for repos we use rubocop in
if File.read(path) != rubocop_file
File.write(path, rubocop_file)
puts "+ Updated rubocop file #{path}"
else
puts "- File #{path} unchanged"
end
end
File.write(File.join(repo, '.hound.yml'), File.read('./fastlane/.hound.yml'))
unless %w(gym fastlane_core).include?(repo) # some repos need Mac OS
File.write(File.join(repo, '.travis.yml'), File.read('./fastlane/.travis.yml'))
end
end
end
task :test_all do
GEMS.reverse_each do |repo|
box "Testing #{repo}"
sh "cd #{repo} && rspec && rubocop"
end
end
desc 'Fetch the latest rubocop config and apply&test it for all gems'
task rubocop: :fetch_rubocop do
GEMS.each do |repo|
path = File.join(repo, '.rubocop_general.yml')
if File.exist?(path)
begin
sh "cd #{repo} && rubocop"
rescue
box "Validation for #{repo} failed"
end
else
box "No rubocop for #{repo}..."
end
end
end
desc 'Print out the # of unreleased commits'
task :unreleased do
GEMS.each do |repo|
Dir.chdir(repo) do
`git pull --tags`
last_tag = `git describe --abbrev=0 --tags`.strip
output = `git log #{last_tag}..HEAD --oneline`.strip
if output.length > 0
box "#{repo}: #{output.split("\n").count} Commits"
output.split("\n").each do |line|
puts "\t" + line.split(' ', 1).last # we don't care about the commit ID
end
puts "\nhttps://github.com/fastlane/#{repo}/compare/#{last_tag}...master"
end
end
end
end
desc 'git push all the things'
task :push do
(GEMS + RAILS).each do |repo|
box "Pushing #{repo}"
sh "cd #{repo} && git push origin master"
end
end
desc 'enable lol commits for all repos'
task :lolcommits do
(['.'] + GEMS + RAILS).each do |repo|
box "Enabling lol commits for #{repo}"
sh "cd #{repo} && lolcommits --enable"
# We need to patch it to work with El Capitan
path = File.join(repo, '.git', 'hooks', 'post-commit')
content = File.read(path)
content.gsub!('lolcommits --capture', 'lolcommits --capture --delay 4')
File.write(path, content)
end
end
desc 'enable auto push for all repos'
task :autopush do
(['.'] + GEMS + RAILS).each do |repo|
box "Enabling auto push for #{repo}"
path = File.join(repo, '.git', 'hooks', 'post-commit')
content = File.read(path)
next if content.include?('git push')
content += "\ngit push"
File.write(path, content)
end
end
#####################################################
# @!group Helper Methods
#####################################################
def box(str)
l = str.length + 4
puts ''
puts '=' * l
puts '| ' + str + ' |'
puts '=' * l
end