releasetool 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +22 -10
- data/release_notes/v0.5.0.md +5 -0
- data/release_notes/v0.5.1.md +8 -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 +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be31ca29505431ae2078f139521c8a0de7ebe18146acee1feaa862e169475645
|
4
|
+
data.tar.gz: cf6a69fe17b82ea44099124cfc61b53b5541b9767d813cc4260d9908e9260446
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0c60d8f3d241c2bbc4035cbd71e5b8a744a99618c9f4aa72718918c6c66b926647d0bf4bd327cf5a1b87066631a94b73160be3972e0b5b62e9449a84d496485
|
7
|
+
data.tar.gz: 1a38cc0c5f621f84030f95baa81fe13229ac51621cee1462cdb88e9d907039595b76825eb3e47c4007f17391a7472ed8c1cd0485da0bce9fc835e578e0c322fd
|
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]'
|
@@ -62,13 +73,16 @@ class Release < Thor
|
|
62
73
|
If no version given, it will use the version stored by release start
|
63
74
|
END
|
64
75
|
|
65
|
-
|
66
|
-
method_option :
|
76
|
+
method_option :edit, type: :boolean, desc: "release commit --edit allows you to edit, or --no-edit (default) which allows you to just skip", aliases: 'e', default: false
|
77
|
+
method_option :after, type: :boolean, desc: " --after (only do after -- needed for when after fails first time); --no-after (only do the standard); default is do both", default: "default", check_default_type: false
|
67
78
|
def commit(version = nil)
|
68
|
-
version
|
69
|
-
|
70
|
-
|
71
|
-
|
79
|
+
version ||= stored_version
|
80
|
+
if options[:after] == "default" || !options[:after]
|
81
|
+
guarded_system("git add #{DIR}")
|
82
|
+
guarded_system("git add #{Releasetool::Util.version_file}") if File.exist?(Releasetool::Util.version_file)
|
83
|
+
guarded_system("git commit #{DIR} #{File.exist?(Releasetool::Util.version_file) ? Releasetool::Util.version_file : ''} #{options[:edit] ? '-e' : nil} -m\"#{DEFAULT_COMMIT_MESSAGE}\"")
|
84
|
+
end
|
85
|
+
config.after_commit_hook(version) unless options[:after]
|
72
86
|
end
|
73
87
|
|
74
88
|
desc "tag (NEW_VERSION)", <<-END
|
@@ -111,9 +125,7 @@ class Release < Thor
|
|
111
125
|
|
112
126
|
protected
|
113
127
|
|
114
|
-
def next_version
|
115
|
-
return Releasetool::Version.new(specified) if specified
|
116
|
-
|
128
|
+
def next_version
|
117
129
|
if options[:major]
|
118
130
|
previous_version.next_major
|
119
131
|
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.1
|
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-19 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,12 @@ 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
|
117
|
+
- release_notes/v0.5.1.md
|
114
118
|
- releasetool.gemspec
|
119
|
+
- spec/fixtures/empty_file.rb
|
115
120
|
- spec/fixtures/example_with_releases.tar
|
121
|
+
- spec/fixtures/hooks_example.rb
|
116
122
|
- spec/releasetool_spec.rb
|
117
123
|
- spec/spec_helper.rb
|
118
124
|
- spec/version_spec.rb
|
@@ -136,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
142
|
- !ruby/object:Gem::Version
|
137
143
|
version: '0'
|
138
144
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
145
|
+
rubygems_version: 3.2.33
|
140
146
|
signing_key:
|
141
147
|
specification_version: 4
|
142
148
|
summary: Release management tools
|