@@ -10,6 +10,7 @@ Projects = ['rspec', 'rspec-core', 'rspec-expectations', 'rspec-mocks', 'rspec-r
10
10
UnDocumentedProjects = %w[ rspec rspec-support ]
11
11
BaseRspecPath = Pathname . new ( Dir . pwd )
12
12
ReposPath = BaseRspecPath . join ( 'repos' )
13
+ MAX_PROJECT_NAME_LENGTH = Projects . map ( &:length ) . max
13
14
14
15
def run_command ( command , opts = { } )
15
16
projects = if opts [ :except ]
@@ -35,17 +36,25 @@ def run_command(command, opts={})
35
36
end
36
37
end
37
38
39
+ def announce ( project )
40
+ puts "=" *50
41
+ puts "# #{ project } "
42
+ puts "-" *40
43
+ end
44
+
38
45
def each_project ( options = { } )
39
- projects = Projects
46
+ projects = options . fetch ( :only , Projects )
40
47
projects -= Array ( options [ :except ] )
41
48
42
49
projects . each do |project |
43
50
Dir . chdir ( "repos/#{ project } " ) do
44
- puts "=" *50
45
- puts "# #{ project } "
46
- puts "-" *40
47
- yield project
48
- puts
51
+ if options [ :silent ]
52
+ yield project
53
+ else
54
+ announce ( project )
55
+ yield project
56
+ puts
57
+ end
49
58
end
50
59
end
51
60
end
@@ -63,14 +72,30 @@ desc "Updates the rspec.github.io docs"
63
72
task :update_docs , [ :version , :branch , :website_path ] do |t , args |
64
73
abort "You must have ag installed to generate docs" if `which ag` == ""
65
74
args . with_defaults ( :website_path => "../rspec.github.io" )
66
- each_project :except => ( UnDocumentedProjects ) do |project |
67
- latest_release = `git fetch --tags && git tag | grep '^v\\ \d .\\ \d .\\ \d $' | grep v#{ args [ :version ] } | tail -1`
75
+
76
+ projects = { }
77
+ skipped = [ ]
78
+
79
+ $stdout. write "Checking versions..."
80
+
81
+ each_project :silent => true , :except => ( UnDocumentedProjects ) do |project |
82
+ $stdout. write "\r Checking versions... #{ project } "
83
+ latest_release = `git fetch --tags && git tag -l "v#{ args [ :version ] } *" | grep v#{ args [ :version ] } | tail -1`
68
84
69
85
if latest_release . empty?
70
- next "No release found for #{ args [ :version ] } in #{ `pwd` } "
86
+ skipped << project
87
+ else
88
+ projects [ project ] = latest_release
71
89
end
90
+ $stdout. write "\r Checking versions... " + ( " " * MAX_PROJECT_NAME_LENGTH )
91
+ end
72
92
73
- `git checkout #{ latest_release } `
93
+ $stdout. write "\r \n "
94
+
95
+ abort "No projects matched #{ args [ :version ] } " if projects . empty?
96
+
97
+ each_project ( :only => projects . keys ) do |project |
98
+ `git checkout #{ projects [ project ] } `
74
99
doc_destination_path = "#{ args [ :website_path ] } /source/documentation/#{ args [ :version ] } /#{ project } /"
75
100
cmd = "bundle update && \
76
101
RUBYOPT='-I#{ args [ :website_path ] } /lib' bundle exec yard \
@@ -89,6 +114,8 @@ task :update_docs, [:version, :branch, :website_path] do |t, args|
89
114
Bundler . unbundled_system %Q{ag -l href=\\ "\\ \( ?:..\/ \\ \) *css #{ doc_destination_path } | xargs -I{} sed #{ in_place } 's/href="\\ \( ..\\ \/ \\ \) *css/href="\\ \/ documentation\\ \/ #{ args [ :version ] } \\ \/ #{ project } \\ \/ css/' {}}
90
115
Bundler . unbundled_system %Q{ag --html -l . #{ doc_destination_path } | xargs -I{} sed #{ in_place } /^[[:space:]]*$/d {}}
91
116
end
117
+
118
+ puts "Skipped projects: (#{ skipped . join ( ", " ) } ) due to no matching version." unless skipped . empty?
92
119
end
93
120
94
121
namespace :gem do
@@ -176,16 +203,26 @@ namespace :git do
176
203
sh "git add ."
177
204
sh "git ci -m 'Update version to #{ version } '"
178
205
end
179
- force_update ( branch , nil )
206
+ force_update ( branch , nil , false )
180
207
end
181
208
182
- { :status => nil , :push => nil , :reset => '--hard' , :diff => nil } . each do |command , options |
209
+ { :show => nil , :status => nil , :reset => '--hard' , :diff => nil } . each do |command , options |
183
210
desc "git #{ command } on all the repos"
184
211
task command => :clone do
185
212
run_command "git #{ command } #{ options } " . strip
186
213
end
187
214
end
188
215
216
+ desc 'git push on all the repos'
217
+ task :push , :force do |t , args |
218
+ branch = `git rev-parse --abbrev-ref HEAD`
219
+ if args [ :force ]
220
+ run_command "git push origin #{ branch } --force-with-lease"
221
+ else
222
+ run_command "git push origin #{ branch } "
223
+ end
224
+ end
225
+
189
226
desc 'git pull on all the repos'
190
227
task :pull => [ :clone ] do
191
228
run_command "git pull --rebase"
@@ -350,9 +387,9 @@ namespace :ci do
350
387
end
351
388
352
389
desc "Updates the CI files and creates a PR"
353
- task :create_pr_with_updates , :custom_pr_comment do |t , args |
390
+ task :create_pr_with_updates , :custom_pr_comment , :force do |t , args |
354
391
opts = { except : %w[ rspec-rails ] }
355
- force_update ( update_ci_files_in_repos ( opts ) , args [ :custom_pr_comment ] , opts )
392
+ force_update ( update_ci_files_in_repos ( opts ) , args [ :custom_pr_comment ] , args [ :force ] == "force" , opts )
356
393
end
357
394
end
358
395
@@ -429,8 +466,8 @@ namespace :common_plaintext_files do
429
466
end
430
467
431
468
desc "Updates the common plaintext files files and creates a PR"
432
- task :create_pr_with_updates , :custom_pr_comment do |_t , args |
433
- force_update ( update_common_plaintext_files_in_repos , args [ :custom_pr_comment ] )
469
+ task :create_pr_with_updates , :custom_pr_comment , :force do |_t , args |
470
+ force_update ( update_common_plaintext_files_in_repos , args [ :custom_pr_comment ] , args [ :force ] == "force" )
434
471
end
435
472
end
436
473
@@ -521,12 +558,16 @@ def each_project_with_common_build(opts={}, &b)
521
558
each_project ( :except => except , &b )
522
559
end
523
560
524
- def force_update ( branch , custom_pr_comment , opts = { } )
561
+ def force_update ( branch , custom_pr_comment , skip_confirmation = false , opts = { } )
525
562
each_project_with_common_build ( opts ) do |name |
526
563
unless system ( "git push origin #{ branch } " )
527
- puts "Push failed, force? (y/n)"
528
- if STDIN . gets . downcase =~ /^y/
529
- sh "git push origin +#{ branch } "
564
+ if skip_confirmation
565
+ sh "git push origin #{ branch } --force-with-lease"
566
+ else
567
+ puts "Push failed, force? (y/n)"
568
+ if STDIN . gets . downcase =~ /^y/
569
+ sh "git push origin +#{ branch } "
570
+ end
530
571
end
531
572
create_pull_request ( name , branch , custom_pr_comment ) rescue nil
532
573
else
0 commit comments