ndr_dev_support 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87c153a7110ac07b2d6a99db00e1767cb99c6cbe0ff24e0a9a3ae02a6a0e8a49
4
- data.tar.gz: 81338a061ce5554213835bde60ce17a7a76603c356efcac1d2d5dce92a34f6d1
3
+ metadata.gz: 07b63ea8d81ee459134b9050fe9de402b50f79b0ad32139d73d90e6e26b7053c
4
+ data.tar.gz: 3479a5ccbd481bae7528036b8ba0cf20aba3676c99ca0f4c4b68f20920df35d0
5
5
  SHA512:
6
- metadata.gz: 7fc483a76029f95b49ba8718be0346616296b9b636e4ff693fda738e54803fce8d67d28d7d4b324b04340581c8e8c134566227e9a7983d8412b43a3aab604456
7
- data.tar.gz: b44a5b0eaa442d0ff383e90c8418b17a9014c113040e7c93d8e02e4e0b768b473fcedd2dabd5d35bc5029b7bfcc7ff67c5c058591e6fe5f2b6f4d5c4a388beac
6
+ metadata.gz: feee00d50b38a0e07f7f2817b580d9236b177a85ff949f18662e5dcd90488b8a85b8d3851655a922356f35f8e78f0fcab0aeea0a9d9a8c99c9cc89c7d2b71e51
7
+ data.tar.gz: 1f12d9c909139011e27e6c185289d97189d63c7bf8949e09b49767aeee3edef302f33385528a8a301775361799308fcc73d7d7b0193015d493b5b2eae2dde40c
@@ -1,6 +1,10 @@
1
1
  ## [Unreleased]
2
2
  *no unreleased changes*
3
3
 
4
+ ## 4.2.1 / 2018-12-18
5
+ ### Fixed
6
+ * ci_server: improve logging and error handling (#44)
7
+
4
8
  ## 4.2.0 / 2018-11-28
5
9
  ### Added
6
10
  * Improve `Stoppable` integration within a Rails project, adding configurable logger.
data/README.md CHANGED
@@ -7,6 +7,7 @@ providing:
7
7
  2. rake tasks to limit Rubocop's output to changed (and related) code
8
8
  3. integration testing support, which can be required from a project's `test_helper.rb`
9
9
  4. Deployment support, through Capistrano.
10
+ 5. a rake task based Continuous Integration (CI) server.
10
11
 
11
12
  ## Installation
12
13
 
@@ -140,6 +141,71 @@ require 'ndr_dev_support/capistrano/ndr_model'
140
141
 
141
142
  This will pull in the majority of behaviour needed to deploy in our preferred style.
142
143
 
144
+ ## Rake CI server
145
+
146
+ ndr_dev_support provides a rake based continuous integration server that runs on a `git` or `git svn` working copy of your application.
147
+ It polls for changes to the respository and, unlike some CI servers, it checks out and tests every commit; enabling full and comparative analysis of code quality and other statistical trends.
148
+
149
+ Out of the box it does nothing, but does provide a number of rake tasks that you can opt to use.
150
+ Those rake tasks utilise the concepts of metrics and attachments (messages) and tasks tend to either generate them or publish them.
151
+
152
+ NOTE: As the way tests are run across applications differs, the `:default` rake task must be able to run your full suite of tests.
153
+
154
+ CI rake tasks have been written for:
155
+
156
+ * `ci:brakeman` - [brakeman](https://brakemanscanner.org/) vulnerability scanner metrics are generated for warning counts and "danger" messages for new warnings and "good" messages for fixed warnings.
157
+ * `ci:bundle_audit` - generates "danger" messages for high criticality [bundle audit](https://github.com/rubysec/bundler-audit) advisories and "warning" messages for all others.
158
+ * `ci:commit_cop` - Runs a number of commit "Cops" which create messages when common commit mistakes occur. Current cops look for a Rails migration added without a structure dump file, modified Rails migrations and renamed Rails migrations.
159
+ * `ci:dependencies:process` - generates a line of pipe delimited markup showing system dependencies (that could be used in a wiki page on Redmine)
160
+ * `ci:housekeep` - runs `rake log:clear` and `rake tmp:clear` if defined
161
+ * `ci:linguist` - generates project programming language metrics for languages over 1% of codebase.
162
+ * `ci:minitest` - sets up Minitest and SimpleCov to capture metrics and messages and runs the `default` rake task and `ci:simplecov:process` before running `ci:redmine:update_tickets` if all tests pass.
163
+ * `ci:notes` - runs the Rails `rake notes` task (if using Rails) and converts annotation counts into metrics.
164
+ * `ci:prometheus:publish` - sends all metrics to specified [Prometheus](https://prometheus.io/) push gateway.
165
+ * `ci:redmine:update_tickets` - if all tests pass, this will parse the commit message and resolve associated [Redmine](https://www.redmine.org/) tickets.
166
+ * `ci:rugged:commit_details` - if there are messages, then it prepends message list with commit details.
167
+ * `ci:simplecov:process` - generates metrics for [SimpleCov](https://github.com/colszowka/simplecov) measured test covered lines, test coverage percentage and total lines of code.
168
+ * `ci:slack:publish` - sends all messages to specified [Slack](https://slack.com/) channel.
169
+ * `ci:stats` - runs the Rails `rake stats` task (if using Rails) and converts counts into metrics
170
+
171
+ To start the server, `cd` to the working copy and execute:
172
+
173
+ $ rake ci:server
174
+
175
+ Configuration is managed within your application by implementing the `ci:all` rake task. When a new commit is detected, it checks it out and runs `rake ci:all`.
176
+
177
+ An example Rails application rake task might look like:
178
+
179
+ ```ruby
180
+ namespace :ci do
181
+ desc 'Setup CI stack, integrations, etc up front'
182
+ task setup: [
183
+ 'ci:rugged:setup',
184
+ 'ci:slack:setup',
185
+ 'ci:prometheus:setup'
186
+ ]
187
+
188
+ desc 'all'
189
+ task all: [
190
+ # Setup
191
+ 'ci:setup',
192
+ 'ci:housekeep',
193
+ 'db:migrate',
194
+ # Test and Analyse
195
+ 'ci:minitest',
196
+ 'ci:brakeman',
197
+ 'ci:bundle_audit',
198
+ 'ci:linguist',
199
+ 'ci:notes',
200
+ 'ci:stats',
201
+ # Report
202
+ 'ci:publish'
203
+ ]
204
+ end
205
+ ```
206
+
207
+ NOTE: Defining the `ci:setup` rake tasks up front is not necessary, but will prompt for missing server credentials at the start of the first CI run.
208
+
143
209
  ## Development
144
210
 
145
211
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -19,7 +19,7 @@ file safety:
19
19
  CHANGELOG.md:
20
20
  comments:
21
21
  reviewed_by: josh.pencheon
22
- safe_revision: 261906b5303610ac97278d8e653d5394428625d1
22
+ safe_revision: a73717bdeb9f48c257aec4fa41a19735e99555c8
23
23
  CODE_OF_CONDUCT.md:
24
24
  comments:
25
25
  reviewed_by: timgentry
@@ -35,7 +35,7 @@ file safety:
35
35
  README.md:
36
36
  comments:
37
37
  reviewed_by: josh.pencheon
38
- safe_revision: a2b7c20eb58572c213f77677b36aa2f7e6db747e
38
+ safe_revision: dd220d1cd30d878bf8a35495efe474f08c5c0971
39
39
  Rakefile:
40
40
  comments:
41
41
  reviewed_by: josh.pencheon
@@ -95,7 +95,7 @@ file safety:
95
95
  lib/ndr_dev_support/daemon/ci_server.rb:
96
96
  comments:
97
97
  reviewed_by: josh.pencheon
98
- safe_revision: 66ce36e2646d392e3a67e19fcb9322ed8c5a6c16
98
+ safe_revision: 0677afc93b0a64d56383e80fa1247e5be64bfb24
99
99
  lib/ndr_dev_support/daemon/stoppable.rb:
100
100
  comments:
101
101
  reviewed_by: josh.pencheon
@@ -191,7 +191,7 @@ file safety:
191
191
  lib/ndr_dev_support/version.rb:
192
192
  comments:
193
193
  reviewed_by: josh.pencheon
194
- safe_revision: 261906b5303610ac97278d8e653d5394428625d1
194
+ safe_revision: a73717bdeb9f48c257aec4fa41a19735e99555c8
195
195
  lib/tasks/audit_code.rake:
196
196
  comments: Identical to the version reviewed by josh.pencheon when contained within
197
197
  ndr_support
@@ -224,7 +224,7 @@ file safety:
224
224
  lib/tasks/ci/minitest.rake:
225
225
  comments:
226
226
  reviewed_by: josh.pencheon
227
- safe_revision: 3cadf2dc33034cfe7258f6cf4b199d3101b2a7ba
227
+ safe_revision: 0677afc93b0a64d56383e80fa1247e5be64bfb24
228
228
  lib/tasks/ci/notes.rake:
229
229
  comments:
230
230
  reviewed_by: timgentry
@@ -236,7 +236,7 @@ file safety:
236
236
  lib/tasks/ci/redmine.rake:
237
237
  comments:
238
238
  reviewed_by: josh.pencheon
239
- safe_revision: 2154aa7f32e731933ff6091b8f42b2b014028a6a
239
+ safe_revision: ba171e9460b57d2d9932f6c0c0bdc3a5b282af80
240
240
  lib/tasks/ci/rugged.rake:
241
241
  comments:
242
242
  reviewed_by: timgentry
@@ -44,39 +44,49 @@ module NdrDevSupport
44
44
  private
45
45
 
46
46
  def run_once
47
+ log('running once...')
48
+
47
49
  git_fetch
48
50
  git_checkout(MASTER_BRANCH_NAME)
49
51
 
50
52
  objectids_between_master_and_remote.each do |oid|
53
+ log("testing #{oid}...")
51
54
  git_rebase(oid)
52
55
 
53
56
  WithCleanRbenv.with_clean_rbenv do
54
57
  # TODO: rbenv_install
55
58
  bundle_install
56
- `rbenv exec bundle exec rake ci:all`
59
+ system('rbenv exec bundle exec rake ci:all')
57
60
  git_discard_changes
58
61
  end
59
62
  end
63
+
64
+ log('completed single run.')
65
+ rescue => exception
66
+ log(<<~MSG)
67
+ Unhandled exception! #{exception.class}: #{exception.message}
68
+ #{(exception.backtrace || []).join("\n")}
69
+ MSG
70
+
71
+ raise exception
60
72
  end
61
73
 
62
74
  def git_fetch
63
- svn_remote? ? `git svn fetch` : `git fetch`
75
+ system(svn_remote? ? 'git svn fetch' : 'git fetch')
64
76
  end
65
77
 
66
78
  def git_checkout(oid)
67
79
  Open3.popen3('git', 'checkout', oid) do |_stdin, _stdout, stderr, wait_thr|
68
80
  msg = stderr.read.strip
69
- # TODO: Once https://github.com/PublicHealthEngland/ndr_dev_support/issues/27
70
- # has been resolved, use logging instead of puts
71
- puts msg unless msg == "Already on '#{oid}'"
81
+ log(msg) unless msg == "Already on '#{oid}'"
72
82
 
73
83
  process_status = wait_thr.value
74
- raise stderr.read unless process_status.exited?
84
+ raise msg unless process_status.exited?
75
85
  end
76
86
  end
77
87
 
78
88
  def git_rebase(oid)
79
- `git rebase #{Shellwords.escape(oid)}`
89
+ system("git rebase #{Shellwords.escape(oid)}") || raise('Unable to rebase!')
80
90
  end
81
91
 
82
92
  def git_discard_changes
@@ -122,7 +132,7 @@ module NdrDevSupport
122
132
  return unless File.file?('Gemfile')
123
133
  return if system('bundle check')
124
134
 
125
- `rbenv exec bundle install --local --jobs=3`
135
+ system('rbenv exec bundle install --local --jobs=3')
126
136
  return if $CHILD_STATUS.exitstatus.zero? || ENV['SLACK_WEBHOOK_URL'].nil?
127
137
 
128
138
  slack_publisher = NdrDevSupport::SlackMessagePublisher.new(ENV['SLACK_WEBHOOK_URL'],
@@ -138,6 +148,8 @@ module NdrDevSupport
138
148
  }
139
149
 
140
150
  slack_publisher.post(attachments: [attachment])
151
+
152
+ raise 'Failure running `bundle install --local`'
141
153
  end
142
154
  end
143
155
  end
@@ -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 = '4.2.0'.freeze
5
+ VERSION = '4.2.1'.freeze
6
6
  end
@@ -5,7 +5,6 @@ namespace :ci do
5
5
 
6
6
  # Run the tests
7
7
  test_cmd = 'bundle exec rake ci:minitest:setup ci:simplecov:setup default'
8
- test_cmd += ' 2>&1 >/dev/null' if ENV['RAKECI_HEADLESS']
9
8
  system test_cmd
10
9
 
11
10
  Rake::Task['ci:minitest:process'].invoke
@@ -2,6 +2,8 @@ namespace :ci do
2
2
  namespace :redmine do
3
3
  desc 'Set up Redmine'
4
4
  task :setup do
5
+ require 'highline/import'
6
+
5
7
  ENV['REDMINE_HOSTNAME'] ||= ask('Redmine URL: ')
6
8
  ENV['REDMINE_HOSTNAME'] = nil if ENV['REDMINE_HOSTNAME'] == ''
7
9
 
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: 4.2.0
4
+ version: 4.2.1
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: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2018-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry