patches 3.3.0 → 3.6.0

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: 31f20fe803ffb8762b4ebdbdacb5b33564d67eaa24505ffb8fdd25fc88a6198c
4
- data.tar.gz: c7fbbb497911d30dd73555a77f8ea946788de6b43110df7afcf6e680f9a349a3
3
+ metadata.gz: c1f8701526a4dd4b0b2f9468a341fda316bde2dd0ba8b9bf0cea5e4236aa9ee5
4
+ data.tar.gz: 6b340c8ab529811f011ba4b984f208f2abb080dfe4b97bcbbd2e7fcccf78e92a
5
5
  SHA512:
6
- metadata.gz: 2b2674ce8e4f2deb2f856e67c32d381bf4007729fad286179b89c0c982c8991b58072c59de133485ea7d9a40071df36778198037569a496a60fa25f4371ce6e1
7
- data.tar.gz: 5fee7f04b02862424097a26e51fe6ad376e885637e67aa90f3986942457494900646426a393f3b1a8946fc3fbb748a8bed89619a9cd7e28a2278151a0eefbc34
6
+ metadata.gz: fa96ce95251d9295cd6544c54d8b2670c1d9f8aab860a50874539662a58e571ae902e400169cf58cfbb0649a980cb29badbb9b0dd65c09c2ecea35bfdd26a823
7
+ data.tar.gz: 5e08319d65bbd8d940ef2fd79091c0d6780e35878c4881fdc491a119eeb6a4fbb640a675e3d38d386d3a69eddb192f916d617aeb2285ca565ce187f2b1a32709
@@ -0,0 +1,26 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: read
13
+ packages: write
14
+
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: '2.7'
20
+
21
+ - name: Publish to RubyGems
22
+ run: |
23
+ gem build *.gemspec
24
+ gem push *.gem
25
+ env:
26
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/CHANGELOG.md CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.6.0] - 2022-05-27
10
+ ### Added
11
+ - Added `notification_prefix` and `notification_suffix` to configuration options
12
+ - Linked to docs/usage.md in README
13
+
14
+ ### Changed
15
+ - Refactored `Patches::Notifier`
16
+ - `Patches::Notifier.append_tenant_message` effectively replaced by `tenant_suffix`
17
+
18
+ ## [3.5.0] - 2020-07-22
19
+ ### Added
20
+ - Enable application version constraint support on `Patches::TenantWorker`
21
+
22
+ ## [3.4.0] - 2020-07-22
23
+ ### Added
24
+ - `Patches::TenantWorker` application version constraint forward compatibility
25
+
9
26
  ## [3.3.0] - 2020-07-20
10
27
  ### Added
11
28
  - Application version constraints
data/README.md CHANGED
@@ -11,7 +11,7 @@ A simple gem for one off tasks
11
11
 
12
12
  ## Version 2.0
13
13
 
14
- Please note the breaking change release around deployment. See docs/usage.md for the full change.
14
+ Please note the breaking change release around deployment. See [docs/usage.md](docs/usage.md) for the full change.
15
15
 
16
16
  TL;DR You need to manually declare the patches task to run in your deploy.rb
17
17
 
@@ -32,7 +32,7 @@ Or install it yourself as:
32
32
 
33
33
  ## Usage
34
34
 
35
- see `docs/usage.md`
35
+ see [docs/usage.md](docs/usage.md)
36
36
 
37
37
  ## Development
38
38
 
data/docs/usage.md CHANGED
@@ -39,6 +39,15 @@ Patches::Config.configure do |config|
39
39
  end
40
40
  ```
41
41
 
42
+ Additionally, you can override the default prefix and suffix of the
43
+ notification message in the patches config:
44
+
45
+ ```ruby
46
+ # for example
47
+ config.notification_prefix = "#{Tenant.current.name}-#{Rails.env}" # => [READYTECH-STAGING]
48
+ config.notification_suffix = Tenant.current.name # => ... patches succeeded for Readytech
49
+ ```
50
+
42
51
  ### Running patches in parallel for tenants
43
52
 
44
53
  If you are using the Apartment gem, you can run the patches for each tenant in parallel.
@@ -0,0 +1,9 @@
1
+ module Patches
2
+ module ApplicationVersionValidation
3
+ def valid_application_version?(application_version)
4
+ return true unless application_version
5
+ return true unless Patches::Config.configuration.application_version
6
+ Patches::Config.configuration.application_version == application_version
7
+ end
8
+ end
9
+ end
@@ -16,6 +16,8 @@ module Patches
16
16
  class Configuration
17
17
  attr_accessor \
18
18
  :application_version,
19
+ :notification_prefix,
20
+ :notification_suffix,
19
21
  :retry_after_version_mismatch_in,
20
22
  :sidekiq_options,
21
23
  :sidekiq_parallel,
@@ -11,23 +11,32 @@ class Patches::Notifier
11
11
  end
12
12
 
13
13
  def success_message(patches)
14
- message = "#{environment_prefix}#{patches.count} patches succeeded"
15
- append_tenant_message(message)
14
+ message(patches.count, "patches succeeded")
16
15
  end
17
16
 
18
17
  def failure_message(patch_path, error)
19
- details = "#{Pathname.new(patch_path).basename} failed with error: #{error}"
20
- message = "#{environment_prefix}Error applying patch: #{details}"
21
- append_tenant_message(message)
18
+ message("Error applying patch:", Pathname.new(patch_path).basename, "failed with error:", error)
19
+ end
20
+
21
+ def message(*args)
22
+ [notification_prefix, *args, notification_suffix].compact.join(" ")
23
+ end
24
+
25
+ def notification_prefix
26
+ prefix = config.notification_prefix.presence || environment_prefix
27
+ "[#{prefix}]" if prefix.present?
22
28
  end
23
29
 
24
30
  def environment_prefix
25
- "[#{Rails.env.upcase}] " if defined?(Rails)
31
+ Rails.env.upcase if defined?(Rails)
32
+ end
33
+
34
+ def notification_suffix
35
+ config.notification_suffix.presence || tenant_suffix
26
36
  end
27
37
 
28
- def append_tenant_message(message)
29
- message = message + " for tenant: #{Apartment::Tenant.current}" if defined?(Apartment)
30
- message
38
+ def tenant_suffix
39
+ "for tenant: #{Apartment::Tenant.current}" if defined?(Apartment)
31
40
  end
32
41
 
33
42
  def send_slack_message(message, color)
@@ -11,7 +11,11 @@ class Patches::TenantRunner
11
11
  Patches.logger.info("Patches tenant runner for: #{tenants.join(',')}")
12
12
  tenants.each do |tenant|
13
13
  if parallel?
14
- Patches::TenantWorker.perform_async(tenant, path)
14
+ Patches::TenantWorker.perform_async(
15
+ tenant,
16
+ path,
17
+ application_version: Patches::Config.configuration.application_version
18
+ )
15
19
  else
16
20
  run(tenant, path)
17
21
  end
@@ -3,10 +3,15 @@ require 'sidekiq'
3
3
  class Patches::TenantWorker
4
4
  include Sidekiq::Worker
5
5
  include Patches::TenantRunConcern
6
+ include Patches::ApplicationVersionValidation
6
7
 
7
8
  sidekiq_options Patches::Config.configuration.sidekiq_options
8
9
 
9
- def perform(tenant_name, path)
10
- run(tenant_name, path)
10
+ def perform(tenant_name, path, params = {})
11
+ if valid_application_version?(params['application_version'])
12
+ run(tenant_name, path)
13
+ else
14
+ self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, tenant_name, path, params)
15
+ end
11
16
  end
12
17
  end
@@ -1,6 +1,6 @@
1
1
  module Patches
2
2
  MAJOR = 3
3
- MINOR = 3
3
+ MINOR = 6
4
4
  PATCH = 0
5
5
  VERSION = [MAJOR, MINOR, PATCH].compact.join(".").freeze
6
6
  end
@@ -2,22 +2,15 @@ require 'sidekiq'
2
2
 
3
3
  class Patches::Worker
4
4
  include Sidekiq::Worker
5
+ include Patches::ApplicationVersionValidation
5
6
 
6
7
  sidekiq_options Patches::Config.configuration.sidekiq_options
7
8
 
8
9
  def perform(runner, params = {})
9
- if valid_application_version?(params)
10
+ if valid_application_version?(params['application_version'])
10
11
  runner.constantize.new.perform
11
12
  else
12
13
  self.class.perform_in(Patches::Config.configuration.retry_after_version_mismatch_in, runner, params)
13
14
  end
14
15
  end
15
-
16
- private
17
-
18
- def valid_application_version?(params)
19
- return true unless params['application_version']
20
- return true unless Patches::Config.configuration.application_version
21
- Patches::Config.configuration.application_version == params['application_version']
22
- end
23
16
  end
data/lib/patches.rb CHANGED
@@ -22,6 +22,7 @@ end
22
22
  require "patches/base"
23
23
  require "patches/config"
24
24
  require "patches/tenant_run_concern"
25
+ require "patches/application_version_validation"
25
26
  require "patches/tenant_worker" if defined?(Sidekiq)
26
27
  require "patches/engine" if defined?(Rails)
27
28
  require "patches/patch"
@@ -22,7 +22,7 @@ namespace :patches do
22
22
  end
23
23
 
24
24
  task :pending => [:environment] do
25
- Patches::Pending.each do |patch|
25
+ Patches::Pending.new.each do |patch|
26
26
  puts patch
27
27
  end
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patches
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JobReady
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -242,6 +242,7 @@ extensions: []
242
242
  extra_rdoc_files: []
243
243
  files:
244
244
  - ".buildkite/pipeline.yml"
245
+ - ".github/workflows/publish.yml"
245
246
  - ".gitignore"
246
247
  - ".rspec"
247
248
  - CHANGELOG.md
@@ -261,6 +262,7 @@ files:
261
262
  - lib/generators/patches/templates/patch.rb.erb
262
263
  - lib/generators/patches/templates/patch_spec.rb.erb
263
264
  - lib/patches.rb
265
+ - lib/patches/application_version_validation.rb
264
266
  - lib/patches/base.rb
265
267
  - lib/patches/capistrano.rb
266
268
  - lib/patches/capistrano/tasks.rake
@@ -296,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
298
  - !ruby/object:Gem::Version
297
299
  version: '0'
298
300
  requirements: []
299
- rubygems_version: 3.0.3
301
+ rubygems_version: 3.1.6
300
302
  signing_key:
301
303
  specification_version: 4
302
304
  summary: A simple gem for one off tasks