@@ -19,76 +19,107 @@ desc("Releases both the gem and node package using the given version.
19
19
20
20
task :create_release , %i[ gem_version dry_run ] do |_t , args |
21
21
args_hash = args . to_hash
22
- is_dry_run = object_to_boolean ( args_hash [ :dry_run ] )
23
22
23
+ is_dry_run = Release . object_to_boolean ( args_hash [ :dry_run ] )
24
24
gem_version = args_hash . fetch ( :gem_version , '' ) . strip
25
- npm_version = gem_version . empty? ? '' : convert_rubygem_to_npm_version ( gem_version )
26
- gem_root = File . expand_path ( '..' , __dir__ )
25
+ npm_version = gem_version . empty? ? '' : Release . convert_rubygem_to_npm_version ( gem_version )
27
26
28
- # Prepare for release
29
- Dir . chdir ( gem_root )
30
- ensure_there_is_nothing_to_commit
27
+ Release . update_the_local_project
28
+ Release . ensure_there_is_nothing_to_commit
29
+
30
+ # Preparing for release
31
31
32
32
# Updating the pre-bundled react
33
+ puts 'Updating react'
33
34
Rake ::Task [ 'react:update' ] . invoke
34
35
35
36
# Updating ReactRailsUJS
37
+ puts 'Updating ujs:update'
36
38
Rake ::Task [ 'ujs:update' ] . invoke
37
39
38
- # release npm version
39
- # Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
40
- release_it_command = +'release-it'
41
- release_it_command << " #{ npm_version } " unless npm_version == ''
42
- release_it_command << ' --npm.publish --no-git.requireCleanWorkingDir'
43
- release_it_command << ' --dry-run --verbose' if is_dry_run
44
- puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
45
- puts 'Use the OTP for NPM!'
46
- puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
47
-
48
- system ( release_it_command )
49
-
50
- # release gem version
51
- # Update lib/react/rails/version.rb
52
- `gem bump --no-commit #{ gem_version == '' ? '' : %(--version #{ gem_version } ) } `
53
-
54
- puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
55
- puts 'Use the OTP for RubyGems!'
56
- puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
40
+ release_the_new_npm_version ( npm_version , is_dry_run )
41
+ release_the_new_gem_version ( gem_version , is_dry_run )
57
42
58
- `gem release` unless is_dry_run
43
+ Release . push
59
44
end
60
45
61
- def object_to_boolean ( value )
62
- [ true , 'true' , 'yes' , 1 , '1' , 't' ] . include? ( value . instance_of? ( String ) ? value . downcase : value )
63
- end
64
-
65
- def convert_rubygem_to_npm_version ( gem_version )
66
- regex_match = gem_version . match ( /(\d +\. \d +\. \d +)[.-]?(.+)?/ )
67
- return "#{ regex_match [ 1 ] } -#{ regex_match [ 2 ] } " if regex_match [ 2 ]
68
-
69
- regex_match [ 1 ] . to_s
70
- end
71
-
72
- def ensure_there_is_nothing_to_commit
73
- status = `git status --porcelain`
74
-
75
- return if $CHILD_STATUS. success? && status == ''
76
-
77
- error = if $CHILD_STATUS. success?
78
- 'You have uncommitted code. Please commit or stash your changes before continuing'
79
- else
80
- 'You do not have Git installed. Please install Git, and commit your changes before continuing'
81
- end
82
- raise ( error )
83
- end
84
-
85
- def update_the_local_project
86
- puts 'Pulling latest commits from remote repository'
87
-
88
- `git pull --rebase`
89
- raise 'Failed in pulling latest changes from default remore repository.' unless $CHILD_STATUS. success?
90
-
91
- `bundle install`
92
- rescue Errno ::ENOENT
93
- raise 'Ensure you have Git and Bundler installed before continuing.'
46
+ # A collection of helper functions for gem and npm release
47
+ module Release
48
+ extend FileUtils
49
+ class << self
50
+ def gem_root
51
+ File . expand_path ( '..' , __dir__ )
52
+ end
53
+
54
+ # Executes a string or an array of strings in a shell in the given directory in an unbundled environment
55
+ def sh_in_dir ( dir , *shell_commands )
56
+ shell_commands . flatten . each { |shell_command | sh %(cd #{ dir } && #{ shell_command . strip } ) }
57
+ end
58
+
59
+ def ensure_there_is_nothing_to_commit
60
+ status = `git status --porcelain`
61
+
62
+ return if $CHILD_STATUS. success? && status == ''
63
+
64
+ error = if $CHILD_STATUS. success?
65
+ 'You have uncommitted code. Please commit or stash your changes before continuing'
66
+ else
67
+ 'You do not have Git installed. Please install Git, and commit your changes before continuing'
68
+ end
69
+ raise ( error )
70
+ end
71
+
72
+ def object_to_boolean ( value )
73
+ [ true , 'true' , 'yes' , 1 , '1' , 't' ] . include? ( value . instance_of? ( String ) ? value . downcase : value )
74
+ end
75
+
76
+ def convert_rubygem_to_npm_version ( gem_version )
77
+ regex_match = gem_version . match ( /(\d +\. \d +\. \d +)[.-]?(.+)?/ )
78
+ return "#{ regex_match [ 1 ] } -#{ regex_match [ 2 ] } " if regex_match [ 2 ]
79
+
80
+ regex_match [ 1 ] . to_s
81
+ end
82
+
83
+ def update_the_local_project
84
+ puts 'Pulling latest commits from remote repository'
85
+
86
+ sh_in_dir ( gem_root , 'git pull --rebase' )
87
+ raise 'Failed in pulling latest changes from default remore repository.' unless $CHILD_STATUS. success?
88
+ rescue Errno ::ENOENT
89
+ raise 'Ensure you have Git and Bundler installed before continuing.'
90
+ end
91
+
92
+ def release_the_new_gem_version ( gem_version , is_dry_run )
93
+ puts 'Bumping gem version'
94
+ Release . sh_in_dir (
95
+ gem_root ,
96
+ "gem bump --no-commit #{ gem_version == '' ? '' : %(--version #{ gem_version } ) } " ,
97
+ 'bundle install' ,
98
+ "git commit -am 'Bump version to #{ gem_version } '"
99
+ )
100
+ puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
101
+ puts 'Use the OTP for RubyGems!'
102
+ puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
103
+
104
+ sh_in_dir ( gem_root , 'gem release --push --tag' ) unless is_dry_run
105
+ end
106
+
107
+ def release_the_new_npm_version ( npm_version , is_dry_run )
108
+ puts 'Making npm release'
109
+ # Will bump the yarn version, commit, tag the commit, push to repo, and release on yarn
110
+ release_it_command = +'release-it'
111
+ release_it_command << " #{ npm_version } " unless npm_version == ''
112
+ release_it_command << ' --npm.publish --no-git.requireCleanWorkingDir'
113
+ release_it_command << ' --dry-run --verbose' if is_dry_run
114
+ puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
115
+ puts 'Use the OTP for NPM!'
116
+ puts 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
117
+
118
+ system ( release_it_command )
119
+ end
120
+
121
+ def push
122
+ sh_in_dir ( gem_root , 'git push' )
123
+ end
124
+ end
94
125
end
0 commit comments