discharger 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/Rakefile +9 -2
- data/lib/discharger/railtie.rb +3 -3
- data/lib/discharger/task.rb +47 -44
- data/lib/discharger/version.rb +1 -1
- data/lib/discharger.rb +7 -0
- data/lib/generators/discharger/install/install_generator.rb +11 -0
- data/lib/generators/discharger/install/templates/discharger_initializer.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c6a8e46dbab57a51adf0c6cc3334b47fcf2671c804b335c8919ebd618f965db
|
4
|
+
data.tar.gz: 7f5c5820619821993de7d54d673d0f6c67437b81d0b46fb3d7f2b8a301faa292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bff63aaf0204b05a18a737cd30c29530dbaa083b8727c3ee60e274ad94f47b902c1810ca13bcfecf535718ca45b9281d8fd0e65a4af1de164e1b2c56b2b38666
|
7
|
+
data.tar.gz: a5cde81b45b56eb3e204d58e53f2ce3aae68a5cdca11e44ff0c93bfc9425b065afade6e9fdbe3ef9d23c9a2ae9ec19a01e722b9733114d549836120965577638
|
data/README.md
CHANGED
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
|
data/lib/discharger/railtie.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Discharger
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
|
-
config.
|
4
|
-
if
|
5
|
-
raise "
|
3
|
+
config.after_initialize do |app|
|
4
|
+
if Rails.env.development? && Discharger.slack_token.nil?
|
5
|
+
raise "Your application Discharger.slack_token must be set in the environment"
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/discharger/task.rb
CHANGED
@@ -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
|
@@ -15,7 +15,7 @@ module Discharger
|
|
15
15
|
reissue.changelog_file = task.changelog_file
|
16
16
|
reissue.updated_paths = task.updated_paths
|
17
17
|
reissue.commit = task.commit
|
18
|
-
reissue.commit_finalize = task.
|
18
|
+
reissue.commit_finalize = task.commit_finalize
|
19
19
|
end
|
20
20
|
task.define
|
21
21
|
task
|
@@ -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
|
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
|
-
|
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
|
-
|
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
|
138
|
-
"git branch -D #{staging_branch} 2
|
139
|
-
"git branch -D #{production_branch} 2
|
140
|
-
"git fetch origin #{staging_branch}:#{staging_branch} #{production_branch}:#{production_branch}",
|
141
|
-
"git checkout
|
142
|
-
"git rebase
|
143
|
-
"git tag -a v#{current_version} -m 'Release #{current_version}'",
|
144
|
-
"git push origin #{production_branch}
|
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
|
-
|
147
|
-
syscall "git checkout
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
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
|
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
|
188
|
-
"git checkout
|
189
|
-
"git branch -D #{staging_branch} 2> /dev/null || true",
|
190
|
-
"git checkout -b #{staging_branch}",
|
191
|
-
"git push origin
|
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
|
-
|
194
|
-
syscall "git checkout
|
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
|
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
|
-
|
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
|
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
|
270
|
-
"open
|
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
|
-
|
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
|
309
|
+
syscall ["open", pr_url]
|
307
310
|
end
|
308
311
|
end
|
309
312
|
end
|
data/lib/discharger/version.rb
CHANGED
data/lib/discharger.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2024-09-15 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:
|