@@ -79,3 +79,90 @@ RDoc::Task.new do |rdoc|
79
79
rdoc . rdoc_files . include ( file ) if File . exist? ( file )
80
80
}
81
81
end
82
+
83
+ def change_version ( &block )
84
+ version_file = 'lib/net/scp/version.rb'
85
+ require_relative version_file
86
+ pre = Net ::SCP ::Version ::PRE
87
+ tiny = Net ::SCP ::Version ::TINY
88
+ result = block [ pre : pre , tiny : Net ::SCP ::Version ::TINY ]
89
+ raise ArgumentError , "Version change logic should always return a pre" unless result . key? ( :pre )
90
+
91
+ new_pre = result [ :pre ]
92
+ new_tiny = result [ :tiny ] || tiny
93
+ found = { pre : false , tiny : false }
94
+ File . open ( "#{ version_file } .new" , "w" ) do |f |
95
+ File . readlines ( version_file ) . each do |line |
96
+ match =
97
+ if pre . nil?
98
+ /^(\s +PRE\s +=\s +)nil(\s *)$/ . match ( line )
99
+ else
100
+ /^(\s +PRE\s +=\s +")#{ pre } ("\s *)$/ . match ( line )
101
+ end
102
+ if match
103
+ prefix = match [ 1 ]
104
+ postfix = match [ 2 ]
105
+ prefix . delete_suffix! ( '"' )
106
+ postfix . delete_prefix! ( '"' )
107
+ new_line = "#{ prefix } #{ new_pre . inspect } #{ postfix } "
108
+ puts "Changing:\n - #{ line } + #{ new_line } "
109
+ line = new_line
110
+ found [ :pre ] = true
111
+ end
112
+
113
+ if new_tiny != tiny
114
+ match = /^(\s +TINY\s +=\s +)#{ tiny } (\s *)$/ . match ( line )
115
+ if match
116
+ prefix = match [ 1 ]
117
+ postfix = match [ 2 ]
118
+ new_line = "#{ prefix } #{ new_tiny } #{ postfix } "
119
+ puts "Changing:\n - #{ line } + #{ new_line } "
120
+ line = new_line
121
+ found [ :tiny ] = true
122
+ end
123
+ end
124
+
125
+ f . write ( line )
126
+ end
127
+ raise ArgumentError , "Cound not find line: PRE = \" #{ pre } \" in #{ version_file } " unless found [ :pre ]
128
+ raise ArgumentError , "Cound not find line: TINY = \" #{ tiny } \" in #{ version_file } " unless found [ :tiny ] || new_tiny == tiny
129
+ end
130
+
131
+ FileUtils . mv version_file , "#{ version_file } .old"
132
+ FileUtils . mv "#{ version_file } .new" , version_file
133
+ end
134
+
135
+ namespace :vbump do
136
+ desc "Final release"
137
+ task :final do
138
+ change_version do |pre :, tiny :|
139
+ _ = tiny
140
+ if pre . nil?
141
+ { tiny : tiny + 1 , pre : nil }
142
+ else
143
+ raise ArgumentError , "Unexpected pre: #{ pre } " if pre . nil?
144
+
145
+ { pre : nil }
146
+ end
147
+ end
148
+ end
149
+
150
+ desc "Increment prerelease"
151
+ task :pre , [ :type ] do |_t , args |
152
+ change_version do |pre :, tiny :|
153
+ puts " PRE => #{ pre . inspect } "
154
+ match = /^([a-z]+)(\d +)/ . match ( pre )
155
+ raise ArgumentError , "Unexpected pre: #{ pre } " if match . nil? && args [ :type ] . nil?
156
+
157
+ if match . nil? || ( !args [ :type ] . nil? && args [ :type ] != match [ 1 ] )
158
+ if pre . nil?
159
+ { pre : "#{ args [ :type ] } 1" , tiny : tiny + 1 }
160
+ else
161
+ { pre : "#{ args [ :type ] } 1" }
162
+ end
163
+ else
164
+ { pre : "#{ match [ 1 ] } #{ match [ 2 ] . to_i + 1 } " }
165
+ end
166
+ end
167
+ end
168
+ end
0 commit comments