discharger 0.1.4 → 0.2.1

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: d85acb3df98a5ced5599847e46e71ae447a884099366570e194aed83207b1667
4
- data.tar.gz: 4d65fedb9d04a8dae89e2e13cbbc779720098052a0f6c7f5a59583992f498b88
3
+ metadata.gz: 124d11a54d0e01902289ad669c58ffff0a0f2d3440cd92ac2775ee7958b04b92
4
+ data.tar.gz: 43016830306332f19aada077073497b8dd8227e9ebcc5de69d3bf53cd86dae8c
5
5
  SHA512:
6
- metadata.gz: 946a7e62f479869ca557183920392bc843fca20236a2e43ed85c1f37541dc0fb2fb5d2bd3cf19c246f3259503a87e0982d8cbe6bd6ffe4d091efb74139c861e3
7
- data.tar.gz: fb8c3ffa1d3d69da351e5564fe0e14f32290aa2676238b062cab6dc689786fccbcbb9fefddb5384a9931f532dadd853967ae3378680b14d53bd1eb32851f850b
6
+ metadata.gz: d64755635d36299678b677de387c2a367a31776cd6d81fd9002e8fc3eb84826ace926d60b9d59ef2516034478737cd0105aa3d177f1083bc875031ea610b82b5
7
+ data.tar.gz: c4011249e3c1ae3763479b0a8bc267ef1a7ec709315f2c0866a1c4511cc9d5697d5b59cbad7ce74adae5e5b6974b6646898f36d677347d2b91adbcec27bb5ed6
data/README.md CHANGED
@@ -43,6 +43,11 @@ And then execute:
43
43
  $ bundle
44
44
  ```
45
45
 
46
+ Then run the install generator:
47
+ ```bash
48
+ $ rails generate discharger:install
49
+ ```
50
+
46
51
  Or install it yourself as:
47
52
  ```bash
48
53
  $ gem install discharger
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
1
  require "bundler/setup"
2
2
 
3
3
  require "bundler/gem_tasks"
4
-
5
- task default: :test
4
+ require "rake/testtask"
6
5
 
7
6
  require "reissue/gem"
8
7
 
@@ -10,3 +9,11 @@ Reissue::Task.create :reissue do |task|
10
9
  task.version_file = "lib/discharger/version.rb"
11
10
  task.commit = true
12
11
  end
12
+
13
+ Rake::TestTask.new(:test) do |t|
14
+ t.libs << "test"
15
+ t.pattern = "test/**/*_test.rb"
16
+ t.verbose = false
17
+ end
18
+
19
+ task default: :test
@@ -1,8 +1,8 @@
1
1
  module Discharger
2
2
  class Railtie < ::Rails::Railtie
3
- config.before_configuration do
4
- if ENV["SLACK_API_TOKEN_RELEASES"].nil?
5
- raise "SLACK_API_TOKEN_RELEASES must be set in the environment"
3
+ config.after_initialize do |app|
4
+ if Rails.env.development? && Discharger.slack_token.nil?
5
+ warn "Your application Discharger.slack_token must be set."
6
6
  end
7
7
  end
8
8
  end
@@ -5,8 +5,8 @@ using Rainbow
5
5
 
6
6
  module Discharger
7
7
  class Task < Rake::TaskLib
8
- def self.create(name = :release, &block)
9
- task = new(name)
8
+ def self.create(name = :release, tasker: Rake::Task, &block)
9
+ task = new(name, tasker:)
10
10
  task.instance_eval(&block) if block
11
11
  Reissue::Task.create do |reissue|
12
12
  reissue.version_file = task.version_file
@@ -46,13 +46,15 @@ module Discharger
46
46
  attr_accessor :commit
47
47
  attr_accessor :commit_finalize
48
48
 
49
- def initialize(name = :release)
49
+ def initialize(name = :release, tasker: Rake::Task)
50
50
  @name = name
51
+ @tasker = tasker
51
52
  @working_branch = "develop"
52
53
  @staging_branch = "stage"
53
54
  @production_branch = "main"
54
55
  @description = "Release the current version to #{staging_branch}"
55
56
  end
57
+ private attr_reader :tasker
56
58
 
57
59
  # Run a multiple system commands and return true if all commands succeed
58
60
  # If any command fails, the method will return false and stop executing
@@ -71,18 +73,19 @@ module Discharger
71
73
  # ["echo", "Hello, World!"],
72
74
  # ["ls", "-l"]
73
75
  # )
74
- def syscall(*steps)
76
+ def syscall(*steps, output: $stdout, error: $stderr)
75
77
  success = false
76
78
  stdout, stderr, status = nil
77
- steps.each do |*cmd|
79
+ steps.each do |cmd|
78
80
  puts cmd.join(" ").bg(:green).black
79
81
  stdout, stderr, status = Open3.capture3(*cmd)
80
82
  if status.success?
81
- puts stdout
83
+ output.puts stdout
84
+ success = true
82
85
  else
83
- puts stderr
86
+ error.puts stderr
84
87
  success = false
85
- abort(stderr)
88
+ exit(status.exitstatus)
86
89
  end
87
90
  end
88
91
  if block_given?
@@ -100,8 +103,8 @@ module Discharger
100
103
  #
101
104
  # @param message [String] the message to echo
102
105
  # return [TrueClass]
103
- def sysecho(message)
104
- system "echo", message
106
+ def sysecho(message, output: $stdout)
107
+ output.puts message
105
108
  true
106
109
  end
107
110
 
@@ -134,17 +137,18 @@ module Discharger
134
137
  exit if input.chomp.match?(/^x/i)
135
138
 
136
139
  continue = syscall(
137
- "git checkout #{working_branch}",
138
- "git branch -D #{staging_branch} 2> /dev/null || true",
139
- "git branch -D #{production_branch} 2> /dev/null || true",
140
- "git fetch origin #{staging_branch}:#{staging_branch} #{production_branch}:#{production_branch}",
141
- "git checkout #{production_branch}",
142
- "git rebase #{staging_branch}",
143
- "git tag -a v#{current_version} -m 'Release #{current_version}'",
144
- "git push origin #{production_branch}; git push origin v#{current_version}"
140
+ ["git", "checkout", working_branch],
141
+ ["git", "branch", "-D #{staging_branch}", "2>/dev/null || true"],
142
+ ["git", "branch", "-D #{production_branch}", "2>/dev/null || true"],
143
+ ["git", "fetch", "origin", "#{staging_branch}:#{staging_branch}", "#{production_branch}:#{production_branch}"],
144
+ ["git", "checkout", production_branch],
145
+ ["git", "rebase", staging_branch],
146
+ ["git", "tag", "-a v#{current_version}", "-m 'Release #{current_version}'"],
147
+ ["git", "push", "origin", "#{production_branch}:#{production_branch}", "v#{current_version}:v#{current_version}"],
148
+ ["git", "push", "origin", "v#{current_version}"]
145
149
  ) do
146
- Rake::Task["#{name}:slack"].invoke("Released #{Qualify.name} #{current_version} to production.", release_message_channel, ":chipmunk:")
147
- syscall "git checkout #{working_branch}"
150
+ tasker["#{name}:slack"].invoke("Released #{Qualify.name} #{current_version} to production.", release_message_channel, ":chipmunk:")
151
+ syscall ["git", "checkout", working_branch]
148
152
  end
149
153
 
150
154
  abort "Release failed." unless continue
@@ -156,17 +160,16 @@ module Discharger
156
160
 
157
161
  MSG
158
162
 
159
- new_version_branch = "bump/begin-#{current_version.tr(".", "-")}"
160
-
161
- continue = syscall("git checkout -b #{new_version_branch}") do
162
- Rake::Task["reissue"].invoke
163
- end
163
+ tasker["reissue"].invoke
164
+ new_version = Object.const_get(version_constant)
165
+ new_version_branch = "bump/begin-#{new_version.tr(".", "-")}"
166
+ continue = syscall(["git", "checkout", "-b #{new_version_branch}"])
164
167
 
165
168
  abort "Bump failed." unless continue
166
169
 
167
170
  pr_url = "#{pull_request_url}/compare/#{working_branch}...#{new_version_branch}?expand=1&title=Begin%20#{current_version}"
168
171
 
169
- syscall("git push origin #{new_version_branch} --force") do
172
+ syscall(["git", "push", "origin", new_version_branch, "--force"]) do
170
173
  sysecho <<~MSG
171
174
  Branch #{new_version_branch} created.
172
175
 
@@ -176,7 +179,7 @@ module Discharger
176
179
  Opening PR: #{pr_url}
177
180
  MSG
178
181
  end.then do |success|
179
- syscall "open #{pr_url}" if success
182
+ syscall ["open", pr_url] if success
180
183
  end
181
184
  end
182
185
 
@@ -184,14 +187,14 @@ module Discharger
184
187
  desc description
185
188
  task build: :environment do
186
189
  syscall(
187
- "git fetch origin #{working_branch}",
188
- "git checkout #{working_branch}",
189
- "git branch -D #{staging_branch} 2> /dev/null || true",
190
- "git checkout -b #{staging_branch}",
191
- "git push origin #{staging_branch} --force"
190
+ ["git", "fetch", "origin", working_branch],
191
+ ["git", "checkout", working_branch],
192
+ ["git", "branch", "-D #{staging_branch}", "2> /dev/null || true"],
193
+ ["git", "checkout", "-b #{staging_branch}"],
194
+ ["git", "push", "origin", staging_branch, "--force"]
192
195
  ) do
193
- Rake::Task["#{name}:slack"].invoke("Building #{app_name} #{commit_identifier.call} on #{staging_branch}.", release_message_channel)
194
- syscall "git checkout #{working_branch}"
196
+ tasker["#{name}:slack"].invoke("Building #{app_name} #{commit_identifier.call} on #{staging_branch}.", release_message_channel)
197
+ syscall ["git", "checkout", working_branch]
195
198
  end
196
199
  end
197
200
 
@@ -225,9 +228,9 @@ module Discharger
225
228
  current_version = Object.const_get(version_constant)
226
229
  finish_branch = "bump/finish-#{current_version.tr(".", "-")}"
227
230
 
228
- syscall "git fetch origin #{working_branch}",
229
- "git checkout #{working_branch}",
230
- "git checkout -b #{finish_branch}"
231
+ syscall ["git", "fetch origin #{working_branch}"],
232
+ ["git", "checkout", working_branch],
233
+ ["git", "checkout", "-b #{finish_branch}"]
231
234
 
232
235
  sysecho <<~MSG
233
236
  Branch #{finish_branch} created.
@@ -241,7 +244,7 @@ module Discharger
241
244
  input = $stdin.gets
242
245
  exit if input.chomp.match?(/^x/i)
243
246
 
244
- Rake::Task["reissue:finalize"].invoke
247
+ tasker["reissue:finalize"].invoke
245
248
 
246
249
  params = {
247
250
  expand: 1,
@@ -253,7 +256,7 @@ module Discharger
253
256
 
254
257
  pr_url = "#{pull_request_url}/compare/#{finish_branch}?#{params.to_query}"
255
258
 
256
- continue = syscall "git push origin #{finish_branch} --force" do
259
+ continue = syscall ["git", "push", "origin", finish_branch, "--force"] do
257
260
  sysecho <<~MSG
258
261
  Branch #{finish_branch} created.
259
262
  Open a PR to #{working_branch} to finalize the release.
@@ -266,8 +269,8 @@ module Discharger
266
269
  MSG
267
270
  end
268
271
  if continue
269
- syscall "git checkout #{working_branch}",
270
- "open #{pr_url}"
272
+ syscall ["git", "checkout", working_branch],
273
+ ["open", pr_url]
271
274
  end
272
275
  end
273
276
 
@@ -282,7 +285,7 @@ module Discharger
282
285
  bin/rails #{name}:build
283
286
  DESC
284
287
  task stage: [:environment] do
285
- Rake::Task["build"].invoke
288
+ tasker["build"].invoke
286
289
  current_version = Object.const_get(version_constant)
287
290
 
288
291
  params = {
@@ -303,7 +306,7 @@ module Discharger
303
306
 
304
307
  Once the PR is **approved**, run 'rake release' to release the version.
305
308
  MSG
306
- syscall "open #{pr_url}"
309
+ syscall ["open", pr_url]
307
310
  end
308
311
  end
309
312
  end
@@ -1,3 +1,3 @@
1
1
  module Discharger
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/discharger.rb CHANGED
@@ -2,4 +2,11 @@ require "discharger/version"
2
2
  require "discharger/railtie"
3
3
 
4
4
  module Discharger
5
+ class << self
6
+ attr_accessor :slack_token
7
+
8
+ def configure
9
+ yield self
10
+ end
11
+ end
5
12
  end
@@ -0,0 +1,11 @@
1
+ module Discharger
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def copy_initializer
7
+ template "discharger_initializer.rb", "config/initializers/discharger.rb"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ if defined?(Discharger)
2
+ Discharger.configure do |config|
3
+ # Configure your Discharger settings here
4
+ # config.slack_token = 'your_slack_token'
5
+ end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discharger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-05 00:00:00.000000000 Z
11
+ date: 2024-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open3
@@ -94,6 +94,8 @@ files:
94
94
  - lib/discharger/railtie.rb
95
95
  - lib/discharger/task.rb
96
96
  - lib/discharger/version.rb
97
+ - lib/generators/discharger/install/install_generator.rb
98
+ - lib/generators/discharger/install/templates/discharger_initializer.rb
97
99
  homepage: https://github.com/SOFware/discharger
98
100
  licenses: []
99
101
  metadata: