ndr_dev_support 6.0.2 → 6.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a024102f34097eebbb099cd46d7a962238390cc3be9bea382308f0ae2615ec6
4
- data.tar.gz: '0938834d58be0cd0e9b0442fc280d8b2cdca3874d3d76767d35c42c617bc34f8'
3
+ metadata.gz: 0ddf993378e5cd98d65313341b0af15677fb8934c42eebb91875d49b66b1ff27
4
+ data.tar.gz: fceda29b2a92b42b2d480926e9079c6f0f7cf2cfb42c6d7c1263fc58308a7bc1
5
5
  SHA512:
6
- metadata.gz: 7769eed298f1f78be229193b218d83377e81f9410535c28ff44ec241aea43ec55cf7796e762aa2c57dc18decd9daa56c1b1b00e98d258d9b6491ea7b27973e17
7
- data.tar.gz: 911e45911f29f14589f7ac63250b1bb1aa14541e76ed4022bb747d113e37aa62e470a326ae90628e3e5367d423f10e40b92bfc89d2177081c2ee34cc4846065e
6
+ metadata.gz: 22b80f92debe98a7092b9b7a1322792142e459e33b8d2cdc7dbaecbcbd3f4e8fa1757eeb033c0d1c98b36c5f2411130b6f7aa7a6c4a4ec13f06bf20436746290
7
+ data.tar.gz: be6721ab8d9ea0e37035cd593748f6d15ce7f958cf5fe5e934c13db2c9a8b61c7dbc751c1b217b47f18c9b3950272496af013190fd7e81f752367839d1b9af55
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## [Unreleased]
2
2
  * no unreleased changes
3
3
 
4
+ ## 6.0.3 / 2022-03-14
5
+ ### Added
6
+ * Add `bundle:update` rake task to update bundled gem files
7
+
4
8
  ## 6.0.2 / 2022-01-14
5
9
  ### Fixed
6
10
  * Support Rails 7, Ruby 3.1
data/code_safety.yml CHANGED
@@ -27,7 +27,7 @@ file safety:
27
27
  CHANGELOG.md:
28
28
  comments:
29
29
  reviewed_by: brian.shand
30
- safe_revision: 773282057d09738cde2b4986c2e4a8a79ed40529
30
+ safe_revision: 5943e1a2ef7095e44858806ad16713cffc67c31b
31
31
  CODE_OF_CONDUCT.md:
32
32
  comments:
33
33
  reviewed_by: timgentry
@@ -226,12 +226,16 @@ file safety:
226
226
  safe_revision: ad38e92c6e56b9d81fdab10681d8f2924eeadf5a
227
227
  lib/ndr_dev_support/tasks.rb:
228
228
  comments:
229
- reviewed_by: josh.pencheon
230
- safe_revision: 2154aa7f32e731933ff6091b8f42b2b014028a6a
229
+ reviewed_by: brian.shand
230
+ safe_revision: 93f9ed210c6a19eee4884ea8a906067c65ee67f6
231
231
  lib/ndr_dev_support/version.rb:
232
232
  comments:
233
233
  reviewed_by: brian.shand
234
- safe_revision: 773282057d09738cde2b4986c2e4a8a79ed40529
234
+ safe_revision: 5943e1a2ef7095e44858806ad16713cffc67c31b
235
+ lib/tasks/audit_bundle.rake:
236
+ comments:
237
+ reviewed_by: brian.shand
238
+ safe_revision: 93f9ed210c6a19eee4884ea8a906067c65ee67f6
235
239
  lib/tasks/audit_code.rake:
236
240
  comments: Identical to the version reviewed by josh.pencheon when contained within
237
241
  ndr_support
@@ -1,4 +1,5 @@
1
1
  load 'tasks/audit_code.rake'
2
+ load 'tasks/audit_bundle.rake'
2
3
  load 'tasks/ci/brakeman.rake'
3
4
  load 'tasks/ci/bundle_audit.rake'
4
5
  load 'tasks/ci/commit_cop.rake'
@@ -2,5 +2,5 @@
2
2
  # This defines the NdrDevSupport version. If you change it, rebuild and commit the gem.
3
3
  # Use "rake build" to build the gem, see rake -T for all bundler rake tasks (and our own).
4
4
  module NdrDevSupport
5
- VERSION = '6.0.2'
5
+ VERSION = '6.0.3'
6
6
  end
@@ -0,0 +1,170 @@
1
+ # A rake task to update the bundled version of a gem
2
+
3
+ # Assumes constant SAFETY_FILE and function repository_type are defined in another rake task.
4
+
5
+ namespace :bundle do
6
+ desc <<~USAGE
7
+ Update to a later version of a gem interactively.
8
+
9
+ Usage: bundle:update gem=rails [version=6.0.4.7]
10
+
11
+ Updates the bundled gem (e.g. rails) version to e.g. 6.0.4.7
12
+ and provides instructions for committing changes.
13
+ It will attempt to modify a hardcoded version in the Gemfile if necessary.
14
+ USAGE
15
+ task(:update) do
16
+ unless %w[git git-svn].include?(repository_type)
17
+ warn 'Error: Requires a git working copy. Aborting.'
18
+ exit 1
19
+ end
20
+
21
+ gem = ENV['gem']
22
+ if gem.blank? || gem !~ /\A[a-zA-Z0-9_.-]+\z/
23
+ warn "Error: missing or invalid required 'gem' parameter. Aborting.\n\n"
24
+ system('rake -D bundle:update')
25
+ exit 1
26
+ end
27
+
28
+ gem_list = Bundler.with_unbundled_env { `bundle exec gem list ^#{gem}$` }
29
+ # Needs to match e.g. "nokogiri (1.12.5 x86_64-darwin)"
30
+ old_gem_version = gem_list.match(/ \(([0-9.]+)( [a-z0-9_-]*)?\)$/).to_a&.second
31
+ unless old_gem_version
32
+ warn <<~MSG.chomp
33
+ Cannot determine gem version for gem=#{gem}. Aborting. Output from bundle exec gem list:
34
+ #{gem_list}
35
+ MSG
36
+ exit 1
37
+ end
38
+ puts "Old #{gem} version from bundle: #{old_gem_version}"
39
+
40
+ new_gem_version = ENV['version'].presence
41
+ if new_gem_version && new_gem_version !~ /\A[0-9.a-zA-Z-]+\z/
42
+ warn "Error: invalid 'version' parameter. Aborting.\n\n"
43
+ system('rake -D bundle:update')
44
+ exit 1
45
+ end
46
+
47
+ unless Bundler.with_unbundled_env { system('bundle check 2> /dev/null') }
48
+ warn('Error: bundle check fails before doing anything.')
49
+ warn('Please clean up the Gemfile before running this. Aborting.')
50
+ exit 1
51
+ end
52
+
53
+ if gem == 'rails'
54
+ # If updating Rails and using activemodel-caution, prompt to put
55
+ # activemodel-caution gem in place, unless it's already installed for this rails version.
56
+ activemodel_caution = Bundler.
57
+ with_unbundled_env { `bundle exec gem list activemodel-caution` }.
58
+ match?(/^activemodel-caution \([0-9.]+\)$/)
59
+ if activemodel_caution && new_gem_version
60
+ file_pattern = "activemodel-caution-#{new_gem_version}*.gem"
61
+ unless Dir.glob("vendor/cache/#{file_pattern}").any? ||
62
+ Bundler.with_unbundled_env do
63
+ `gem list ^activemodel-caution$ -i -v #{new_gem_version}`
64
+ end.match?(/^true$/)
65
+ warn("Error: missing #{file_pattern} file in vendor/cache")
66
+ warn('Copy this file to vendor/cache, then run this command again.')
67
+ exit 1
68
+ end
69
+ end
70
+ end
71
+
72
+ related_gems = if gem == 'rails'
73
+ gem_list2 = Bundler.with_unbundled_env do
74
+ `bundle exec gem list`
75
+ end
76
+ gem_list2.split("\n").
77
+ grep(/[ (]#{old_gem_version}(.0)*[,)]/).
78
+ collect { |row| row.split.first }
79
+ else
80
+ [gem]
81
+ end
82
+ puts "Gems to update: #{related_gems.join(' ')}"
83
+
84
+ if new_gem_version
85
+ puts 'Tweaking Gemfile for new gem version'
86
+ cmd = ['sed', '-i', '.bak', '-E']
87
+ related_gems.each do |rgem|
88
+ cmd += ['-e', "s/(gem '(#{rgem})', '(~> )?)#{old_gem_version}(')/\\1#{new_gem_version}\\4/"]
89
+ end
90
+ cmd += %w[Gemfile]
91
+ system(*cmd)
92
+ File.delete('Gemfile.bak')
93
+
94
+ system('git diff Gemfile')
95
+ end
96
+
97
+ cmd = "bundle update --conservative --minor #{related_gems.join(' ')}"
98
+ puts "Running: #{cmd}"
99
+ Bundler.with_unbundled_env do
100
+ system(cmd)
101
+ end
102
+
103
+ unless Bundler.with_unbundled_env { system('bundle check 2> /dev/null') }
104
+ warn <<~MSG
105
+ Error: bundle check fails after trying to update Rails version. Aborting.
106
+ You will need to check your working copy, especially Gemfile, Gemfile.lock, vendor/cache
107
+ MSG
108
+ exit 1
109
+ end
110
+
111
+ if File.exist?(SAFETY_FILE)
112
+ # Remove references to unused files in code_safety.yml
113
+ system('rake audit:tidy_code_safety_file')
114
+ end
115
+
116
+ gem_list = Bundler.with_unbundled_env { `bundle exec gem list ^#{gem}$` }
117
+ new_gem_version2 = gem_list.match(/ \(([0-9.]+)( [a-z0-9_-]*)?\)$/).to_a&.second
118
+
119
+ if new_gem_version && new_gem_version != new_gem_version2
120
+ puts <<~MSG
121
+ Error: Tried to update gem #{gem} to version #{new_gem_version} but ended up at version #{new_gem_version2}. Aborting.
122
+ You will need to check your working copy, especially Gemfile, Gemfile.lock, vendor/cache
123
+ Try running:
124
+ bundle exec rake bundle:update gem=#{gem} version=#{new_gem_version2}
125
+ MSG
126
+ exit 1
127
+ end
128
+
129
+ # At this point, we have successfully updated all the local files.
130
+ # All that remains is to set up a branch, if necessary, and inform the user what to commit.
131
+
132
+ puts "Looking for changed files using git status\n\n"
133
+ files_to_git_rm = `git status vendor/cache/|grep 'deleted: ' | \
134
+ grep -o ': .*' | sed -e 's/^: *//'`.split("\n")
135
+ files_to_git_add = `git status Gemfile Gemfile.lock code_safety.yml|grep 'modified: ' | \
136
+ grep -o ': .*' | sed -e 's/^: *//'`.split("\n")
137
+ files_to_git_add += `git status vendor/cache|expand|grep '^\s*vendor/cache' | \
138
+ sed -e 's/^ *//'`.split("\n")
139
+
140
+ if files_to_git_rm.empty? && files_to_git_add.empty?
141
+ puts <<~MSG
142
+ No changes were made. Please manually update the Gemfile, run
143
+ bundle update --conservative --minor #{related_gems.join(' ')}
144
+ MSG
145
+ puts ' rake audit:tidy_code_safety_file' if File.exist?(SAFETY_FILE)
146
+ puts <<~MSG
147
+ then run tests and git rm / git add any changes
148
+ including vendor/cache Gemfile Gemfile.lock code_safety.yml
149
+ then git commit
150
+ MSG
151
+ exit
152
+ end
153
+
154
+ if repository_type == 'git'
155
+ # Check out a fresh branch, if a git working copy (but not git-svn)
156
+ branch_name = "#{gem}_#{new_gem_version2.gsub('.', '_')}"
157
+ system('git', 'checkout', '-b', branch_name) # Create a new git branch
158
+ end
159
+
160
+ puts <<~MSG
161
+ Gemfile updated. Please use "git status" and "git diff" to check the local changes,
162
+ manually add any additional platform-specific gems required (e.g. for nokogiri),
163
+ re-run tests locally, then run the following to commit the changes:
164
+
165
+ $ git rm #{files_to_git_rm.join(' ')}
166
+ $ git add #{files_to_git_add.join(' ')}
167
+ $ git commit -m '# Bump #{gem} to #{new_gem_version2}'
168
+ MSG
169
+ end
170
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndr_dev_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.2
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NCRS Development Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -450,6 +450,7 @@ files:
450
450
  - lib/ndr_dev_support/slack_message_publisher.rb
451
451
  - lib/ndr_dev_support/tasks.rb
452
452
  - lib/ndr_dev_support/version.rb
453
+ - lib/tasks/audit_bundle.rake
453
454
  - lib/tasks/audit_code.rake
454
455
  - lib/tasks/ci/brakeman.rake
455
456
  - lib/tasks/ci/bundle_audit.rake