releasetool 0.4.0 → 0.5.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 +4 -4
- data/README.md +10 -0
- data/lib/releasetool/base_hooks.rb +20 -0
- data/lib/releasetool/configuration.rb +76 -0
- data/lib/releasetool/util.rb +6 -0
- data/lib/releasetool.rb +1 -1
- data/lib/tasks/release_thor.rb +15 -5
- data/release_notes/v0.5.0.md +5 -0
- data/spec/fixtures/empty_file.rb +3 -0
- data/spec/fixtures/hooks_example.rb +18 -0
- data/spec/releasetool_spec.rb +62 -2
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b46e141b87c5f056ab3af71cdf6a5157e6b559e51743a07383bc225676c9866
|
4
|
+
data.tar.gz: e9d0a785e91132404eee8aef1a96705834569d5933210dbae5e3a6cbe89f2360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0e80727a056d71917c33fb270685e16f7ec50e50a9aad75d0ae15c09380b993aec681fa340e45ecc126bda12a4a0778e807443dabba0e9f269b586f22cdc046
|
7
|
+
data.tar.gz: ad2a984cb079825de22f0efa986f6f4695e3df5f711c4eb8da5075ad726a2356eea050dff44d24efb48a78bf2d6069077a1126c4854a353b2ce2efa6d8cb4326
|
data/README.md
CHANGED
@@ -69,6 +69,7 @@ It will ask for a one-line summary of the release (full details are in the relea
|
|
69
69
|
|
70
70
|
The tests work on a known-good repo stored in `spec/fixtures/example_with_releases.tar`. To recreate this:
|
71
71
|
```
|
72
|
+
mkdir -p spec/fixtures/example_with_releases
|
72
73
|
cd spec/fixtures/example_with_releases && tar -xvf ../example_with_releases.tar && cd -
|
73
74
|
```
|
74
75
|
|
@@ -77,11 +78,20 @@ then you can tweak it and save it back with:
|
|
77
78
|
cd spec/fixtures/example_with_releases && tar -cvf ../example_with_releases.tar . && cd -
|
78
79
|
```
|
79
80
|
|
81
|
+
ditto for other one with config
|
82
|
+
|
83
|
+
cd spec/fixtures/example_with_releases && tar -cvf ../example_with_releases.tar . && cd -
|
84
|
+
|
80
85
|
## Configuration
|
81
86
|
|
82
87
|
If you want it to automatically update the version number in a string then set the environment variable
|
83
88
|
`RELEASETOOL_VERSION_FILE`, eg. `export RELEASETOOL_VERSION_FILE=./lib/releasetool.rb`. By default this is configured to config/initializers/00-version.rb (useful for rails projects).
|
84
89
|
|
90
|
+
If you want to run something after `release start` or after `release commit` then generate a hooks file:
|
91
|
+
|
92
|
+
release init
|
93
|
+
|
94
|
+
which will generate a file at `config/releasetool/hooks.rb` which you can adjust.
|
85
95
|
|
86
96
|
## Contributing
|
87
97
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "releasetool/util"
|
4
|
+
|
5
|
+
module Releasetool
|
6
|
+
class BaseHooks
|
7
|
+
# @param config [Releasetool::Configuration]
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def after_prepare(version)
|
13
|
+
# noop
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_commit(version)
|
17
|
+
# noop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "releasetool/util"
|
4
|
+
require "pathname"
|
5
|
+
|
6
|
+
module Releasetool
|
7
|
+
class Configuration
|
8
|
+
def after_start_hook(version)
|
9
|
+
return nil unless hooks.respond_to?(:after_start)
|
10
|
+
|
11
|
+
hooks.after_start(version)
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_commit_hook(version)
|
15
|
+
return nil unless hooks.respond_to?(:after_commit)
|
16
|
+
|
17
|
+
hooks.after_commit(version)
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate
|
21
|
+
FileUtils.mkdir_p(config_dir)
|
22
|
+
if File.exist?(hooks_file)
|
23
|
+
say "File #{hooks_file.inspect} already exists"
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
File.write(hooks_file, default_hooks)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def config_dir
|
33
|
+
Pathname.new("./config/releasetool")
|
34
|
+
end
|
35
|
+
|
36
|
+
def hooks
|
37
|
+
@hooks ||= new_hooks
|
38
|
+
end
|
39
|
+
|
40
|
+
def new_hooks
|
41
|
+
return nil unless File.exist?(hooks_file)
|
42
|
+
|
43
|
+
load hooks_file # we use load so we can test it 🙁
|
44
|
+
return nil unless defined?(Releasetool::Hooks)
|
45
|
+
|
46
|
+
Releasetool::Hooks.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def hooks_file
|
50
|
+
config_dir / "hooks.rb"
|
51
|
+
end
|
52
|
+
|
53
|
+
def default_hooks
|
54
|
+
<<~HOOKS
|
55
|
+
# frozen_string_literal: true
|
56
|
+
|
57
|
+
require "releasetool/util"
|
58
|
+
require "releasetool/base_hooks"
|
59
|
+
|
60
|
+
module Releasetool
|
61
|
+
class Hooks < Releasetool::BaseHooks
|
62
|
+
include Releasetool::Util
|
63
|
+
|
64
|
+
# def after_start(version)
|
65
|
+
# puts "after_start has been called"
|
66
|
+
# end
|
67
|
+
|
68
|
+
# def after_commit(version)
|
69
|
+
# puts "after_commit has been called"
|
70
|
+
# end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
HOOKS
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/releasetool/util.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'English'
|
4
|
+
require "releasetool/configuration"
|
4
5
|
|
5
6
|
module Releasetool
|
6
7
|
module Util
|
@@ -35,5 +36,10 @@ module Releasetool
|
|
35
36
|
|
36
37
|
output
|
37
38
|
end
|
39
|
+
|
40
|
+
# @return [Releasetool::Configuration]
|
41
|
+
def config
|
42
|
+
@config ||= Releasetool::Configuration.new
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
data/lib/releasetool.rb
CHANGED
data/lib/tasks/release_thor.rb
CHANGED
@@ -8,6 +8,16 @@ require "releasetool/version"
|
|
8
8
|
|
9
9
|
class Release < Thor
|
10
10
|
include Releasetool::Util
|
11
|
+
desc "init", <<-END
|
12
|
+
generate optional config directory and optional hooks file
|
13
|
+
END
|
14
|
+
|
15
|
+
def init
|
16
|
+
config.generate
|
17
|
+
end
|
18
|
+
|
19
|
+
# ========================
|
20
|
+
|
11
21
|
desc "list", <<-END
|
12
22
|
show a list of tags ordered by date (just a git listing).
|
13
23
|
END
|
@@ -51,9 +61,10 @@ class Release < Thor
|
|
51
61
|
def start(specified_version = nil)
|
52
62
|
raise Thor::Error.new("Can't start when already started on a version. release abort or release finish") if File.exist?(RELEASE_MARKER_FILE)
|
53
63
|
|
54
|
-
version =
|
64
|
+
version = specified_version ? Releasetool::Version.new(specified_version) : next_version
|
55
65
|
File.write(RELEASE_MARKER_FILE, version)
|
56
66
|
Releasetool::Release.new(version, previous: previous_version).prepare(edit: options[:edit])
|
67
|
+
config.after_start_hook(version)
|
57
68
|
end
|
58
69
|
|
59
70
|
DEFAULT_COMMIT_MESSAGE = 'preparing for release [CI SKIP]'
|
@@ -65,10 +76,11 @@ class Release < Thor
|
|
65
76
|
# should take release commit --edit which allows you to edit, or --no-edit (default) which allows you to just skip
|
66
77
|
method_option :edit, type: :boolean, desc: "edit", aliases: 'e', default: false
|
67
78
|
def commit(version = nil)
|
68
|
-
version
|
79
|
+
version ||= stored_version
|
69
80
|
guarded_system("git add #{DIR}")
|
70
81
|
guarded_system("git add #{Releasetool::Util.version_file}") if File.exist?(Releasetool::Util.version_file)
|
71
82
|
guarded_system("git commit #{DIR} #{File.exist?(Releasetool::Util.version_file) ? Releasetool::Util.version_file : ''} #{options[:edit] ? '-e' : nil} -m\"#{DEFAULT_COMMIT_MESSAGE}\"")
|
83
|
+
config.after_commit_hook(version)
|
72
84
|
end
|
73
85
|
|
74
86
|
desc "tag (NEW_VERSION)", <<-END
|
@@ -111,9 +123,7 @@ class Release < Thor
|
|
111
123
|
|
112
124
|
protected
|
113
125
|
|
114
|
-
def next_version
|
115
|
-
return Releasetool::Version.new(specified) if specified
|
116
|
-
|
126
|
+
def next_version
|
117
127
|
if options[:major]
|
118
128
|
previous_version.next_major
|
119
129
|
elsif options[:minor]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "releasetool/util"
|
4
|
+
require "releasetool/base_hooks"
|
5
|
+
|
6
|
+
module Releasetool
|
7
|
+
class Hooks < Releasetool::BaseHooks
|
8
|
+
include Releasetool::Util
|
9
|
+
|
10
|
+
def after_start(version)
|
11
|
+
puts "after_start(#{version}) has been called"
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_commit(version)
|
15
|
+
puts "after_commit(#{version}) has been called"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/releasetool_spec.rb
CHANGED
@@ -10,11 +10,15 @@ RSpec.describe Releasetool do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
RSpec.describe Release, quietly:
|
13
|
+
RSpec.describe Release, quietly: false do
|
14
14
|
subject { Release.new }
|
15
|
+
|
15
16
|
let(:tmpdir) { File.expand_path('../tmp/testing', __dir__) }
|
16
17
|
let(:root_dir) { File.expand_path('..', __dir__) }
|
18
|
+
let(:hooks_example_rb) { File.expand_path('./fixtures/hooks_example.rb', __dir__) }
|
19
|
+
let(:empty_file) { File.expand_path('./fixtures/empty_file.rb', __dir__) }
|
17
20
|
before {
|
21
|
+
Releasetool.send(:remove_const, :Hooks) if defined?(Releasetool::Hooks)
|
18
22
|
FileUtils.rmtree(tmpdir)
|
19
23
|
FileUtils.mkdir_p(tmpdir)
|
20
24
|
FileUtils.chdir(tmpdir)
|
@@ -53,7 +57,7 @@ RSpec.describe Release, quietly: true do
|
|
53
57
|
|
54
58
|
it "with existing release-version file, it should freak out" do
|
55
59
|
FileUtils.touch(File.join(tmpdir, '.RELEASE_NEW_VERSION'))
|
56
|
-
expect { subject.start('v0.0.3') }.to raise_error
|
60
|
+
expect { subject.start('v0.0.3') }.to raise_error(/Can't start when already started on a version/)
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -92,6 +96,31 @@ RSpec.describe Release, quietly: true do
|
|
92
96
|
subject.start
|
93
97
|
end
|
94
98
|
end
|
99
|
+
|
100
|
+
context "with config and..." do
|
101
|
+
context "with empty hooks" do
|
102
|
+
before do
|
103
|
+
FileUtils.mkdir_p("#{tmpdir}/config/releasetool")
|
104
|
+
FileUtils.cp(empty_file, "#{tmpdir}/config/releasetool/hooks.rb")
|
105
|
+
end
|
106
|
+
it "should still work" do
|
107
|
+
expect(Releasetool::Release).to receive(:new).with(v_0_0_2, previous: v_0_0_1).and_return(mock_target)
|
108
|
+
expect(mock_target).to receive(:prepare)
|
109
|
+
expected = "after_start(v0.0.2) has been called"
|
110
|
+
expect { subject.start }.not_to output(/#{Regexp.escape(expected)}/).to_stdout
|
111
|
+
end
|
112
|
+
end
|
113
|
+
context "with hook" do
|
114
|
+
before do
|
115
|
+
FileUtils.mkdir_p("#{tmpdir}/config/releasetool")
|
116
|
+
FileUtils.cp(hooks_example_rb, "#{tmpdir}/config/releasetool/hooks.rb")
|
117
|
+
end
|
118
|
+
it "should output hook" do
|
119
|
+
expected = "after_start(v0.0.2) has been called"
|
120
|
+
expect { subject.start }.to output(/#{Regexp.escape(expected)}/).to_stdout
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
95
124
|
end
|
96
125
|
|
97
126
|
describe "commit" do
|
@@ -114,6 +143,37 @@ RSpec.describe Release, quietly: true do
|
|
114
143
|
subject.commit('v0.0.3')
|
115
144
|
end
|
116
145
|
end
|
146
|
+
|
147
|
+
context "with generated config and hook" do
|
148
|
+
it "should generate and still work" do
|
149
|
+
subject.init
|
150
|
+
expected = "after_commit(v0.0.3) has been called"
|
151
|
+
expect(subject).to receive(:guarded_system).with("git commit release_notes config/initializers/00-version.rb -m\"#{Release::DEFAULT_COMMIT_MESSAGE}\"")
|
152
|
+
expect { subject.commit('v0.0.3') }.not_to output(/#{Regexp.escape(expected)}/).to_stdout
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context "with config and hook" do
|
157
|
+
before do
|
158
|
+
FileUtils.mkdir_p("#{tmpdir}/config/releasetool")
|
159
|
+
FileUtils.cp(hooks_example_rb, "#{tmpdir}/config/releasetool/hooks.rb")
|
160
|
+
end
|
161
|
+
it "should output hook" do
|
162
|
+
expect(subject).to receive(:guarded_system).with("git commit release_notes config/initializers/00-version.rb -m\"#{Release::DEFAULT_COMMIT_MESSAGE}\"")
|
163
|
+
expected = "after_commit(v0.0.3) has been called"
|
164
|
+
expect { subject.commit('v0.0.3') }.to output(/#{Regexp.escape(expected)}/).to_stdout
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "init" do
|
170
|
+
it "should generate " do
|
171
|
+
expect(Dir.exist?("#{tmpdir}/config/releasetool")).to be_falsey
|
172
|
+
expect(File.exist?("#{tmpdir}/config/releasetool/hooks.rb")).to be_falsey
|
173
|
+
subject.init
|
174
|
+
expect(Dir.exist?("#{tmpdir}/config/releasetool")).to be_truthy
|
175
|
+
expect(File.exist?("#{tmpdir}/config/releasetool/hooks.rb")).to be_truthy
|
176
|
+
end
|
117
177
|
end
|
118
178
|
|
119
179
|
describe "latest" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: releasetool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Diggins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -98,6 +98,8 @@ files:
|
|
98
98
|
- Rakefile
|
99
99
|
- bin/release
|
100
100
|
- lib/releasetool.rb
|
101
|
+
- lib/releasetool/base_hooks.rb
|
102
|
+
- lib/releasetool/configuration.rb
|
101
103
|
- lib/releasetool/release.rb
|
102
104
|
- lib/releasetool/util.rb
|
103
105
|
- lib/releasetool/version.rb
|
@@ -111,8 +113,11 @@ files:
|
|
111
113
|
- release_notes/v0.2.0.md
|
112
114
|
- release_notes/v0.3.0.md
|
113
115
|
- release_notes/v0.4.0.md
|
116
|
+
- release_notes/v0.5.0.md
|
114
117
|
- releasetool.gemspec
|
118
|
+
- spec/fixtures/empty_file.rb
|
115
119
|
- spec/fixtures/example_with_releases.tar
|
120
|
+
- spec/fixtures/hooks_example.rb
|
116
121
|
- spec/releasetool_spec.rb
|
117
122
|
- spec/spec_helper.rb
|
118
123
|
- spec/version_spec.rb
|
@@ -136,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
141
|
- !ruby/object:Gem::Version
|
137
142
|
version: '0'
|
138
143
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
144
|
+
rubygems_version: 3.2.33
|
140
145
|
signing_key:
|
141
146
|
specification_version: 4
|
142
147
|
summary: Release management tools
|