@@ -37,6 +37,7 @@ task(:default).clear.enhance %w[
37
37
html_from_markdown
38
38
eslint
39
39
report_code_statistics
40
+ percent_gems_up_to_date
40
41
test:all
41
42
]
42
43
# Temporarily removed fasterer
@@ -124,17 +125,17 @@ task :report_code_statistics do
124
125
end
125
126
end
126
127
128
+ # Helper function to check network availability
129
+ def network_available?
130
+ require 'socket'
131
+ Socket . tcp ( 'github.com' , 443 , connect_timeout : 5 ) { true }
132
+ rescue StandardError
133
+ false
134
+ end
135
+
127
136
# rubocop:disable Metrics/BlockLength
128
137
desc 'Run bundle-audit - check for known vulnerabilities in dependencies'
129
138
task :bundle_audit do
130
- require 'socket'
131
-
132
- def network_available?
133
- Socket . tcp ( 'github.com' , 443 , connect_timeout : 5 ) { true }
134
- rescue StandardError
135
- false
136
- end
137
-
138
139
# rubocop:disable Metrics/MethodLength
139
140
def bundle_audit_update_successful?
140
141
max_retries = 4
@@ -186,6 +187,51 @@ task :bundle_audit do
186
187
end
187
188
# rubocop:enable Metrics/BlockLength
188
189
190
+ # We don't normally print a list of out-of-date gems, that would create
191
+ # a lot of output that is normally useless. The developer can always run
192
+ # "bundle outdated" if that's important.
193
+ desc 'Report percentage of gems that are up-to-date if network available'
194
+ task :percent_gems_up_to_date do
195
+ if network_available?
196
+ begin
197
+ bundle_list_output = `bundle list 2>/dev/null`
198
+ if $CHILD_STATUS. success?
199
+ total_gems =
200
+ bundle_list_output . lines . count do |line |
201
+ line . match? ( /^\s +\* \s / )
202
+ end
203
+ outdated_output = `bundle outdated 2>/dev/null`
204
+ outdated_count =
205
+ $CHILD_STATUS. success? ? 0 : count_outdated_gems ( outdated_output )
206
+ up_to_date = total_gems - outdated_count
207
+ percent =
208
+ if total_gems . zero?
209
+ 100.0
210
+ else
211
+ ( up_to_date . to_f / total_gems * 100 ) . round ( 1 )
212
+ end
213
+
214
+ puts "Gem stats: out-of-date=#{ outdated_count } , " \
215
+ "up-to-date=#{ up_to_date } , total=#{ total_gems } , " \
216
+ "%up-to-date=#{ percent } %"
217
+ else
218
+ puts 'Unable to determine total gem count'
219
+ end
220
+ rescue StandardError => e
221
+ puts "Error checking gem status: #{ e . message } "
222
+ end
223
+ else
224
+ puts 'Network not available, skipping gem status check'
225
+ end
226
+ end
227
+
228
+ # Helper function to count outdated gems from bundle outdated output
229
+ def count_outdated_gems ( outdated_output )
230
+ lines = outdated_output . lines
231
+ gem_header_index = lines . find_index { |line | line . start_with? ( 'Gem' ) }
232
+ gem_header_index ? lines . length - gem_header_index - 1 : 0
233
+ end
234
+
189
235
# Use markdownlint to examine the usual markdown files.
190
236
# NOTE: If you don't want mdl to be run on a markdown file, rename it to
191
237
# end in ".markdown" instead. (E.g., for markdown fragments.)
0 commit comments