bake-gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b1c7d8822f1ce438e1b1c38e0fe70c84b3f4990f74ded28e55a94d48263e1cfe
4
+ data.tar.gz: d5c5244785a1e77c1b92424496b974fc1cc2f8f6620b90686177301f1c759990
5
+ SHA512:
6
+ metadata.gz: ab506f4ecdf9fca06c12206dc141416def87993bdf325a926e55c6816d5182a084b2c59b8cc9f1cd3dda6b63360612eb9a98078ef645ce885cf8f687cde078c0
7
+ data.tar.gz: cc5d3f181ececf3f864c419ffe78921731cb150cc768d4662d58e5f142ec65d5c754a04516fc101d204eab1ff825227a7c766c00b6ced47da778e7caeec0574a
data/bake/gem.rb ADDED
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative '../lib/bake/gem/helper'
24
+ require_relative '../lib/bake/gem/shell'
25
+
26
+ include Bake::Gem::Shell
27
+
28
+ def initialize(context)
29
+ super(context)
30
+
31
+ @helper = Bake::Gem::Helper.new(context.root)
32
+ end
33
+
34
+ attr :helper
35
+
36
+ # List all the files that will be included in the gem:
37
+ def files
38
+ @helper.gemspec.files.each do |path|
39
+ $stdout.puts path
40
+ end
41
+ end
42
+
43
+ # Build the gem into the pkg directory.
44
+ def build
45
+ @helper.build_gem
46
+ end
47
+
48
+ # Build and install the gem into system gems.
49
+ # @parameter local [Boolean] only use locally available caches.
50
+ def install(local: false)
51
+ path = @helper.build_gem
52
+
53
+ arguments = []
54
+ arguments << "--local" if local
55
+
56
+ @helper.install_gem(*arguments, path: path)
57
+ end
58
+
59
+ def release(tag: true)
60
+ @helper.guard_clean
61
+
62
+ version = @helper.gemspec.version
63
+
64
+ if tag
65
+ system("git", "tag", "v#{version}")
66
+ system("git", "push")
67
+ end
68
+
69
+ path = @helper.build_gem
70
+ @helper.push_gem(path: path)
71
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative '../../lib/bake/gem/shell'
24
+
25
+ include Bake::Gem::Shell
26
+
27
+ # Increment the patch number of the current version.
28
+ def patch
29
+ commit([nil, nil, 1], message: "Bump patch version.")
30
+ end
31
+
32
+ # Increment the minor number of the current version.
33
+ def minor
34
+ commit([nil, 1, 0], message: "Bump minor version.")
35
+ end
36
+
37
+ # Increment the major number of the current version.
38
+ def major
39
+ commit([1, 0, 0], message: "Bump major version.")
40
+ end
41
+
42
+ # Increments the version and commits the changes into a new branch.
43
+ #
44
+ # @parameter bump [Array(Integer | Nil)] the version bump to apply before publishing, e.g. `0,1,0` to increment minor version number.
45
+ # @parameter message [String] the git commit message to use.
46
+ def commit(bump, message: "Bump version.")
47
+ release = context.lookup('gem:release')
48
+ helper = release.instance.helper
49
+ gemspec = helper.gemspec
50
+
51
+ # helper.guard_clean
52
+
53
+ version_path = context.lookup('gem:version:increment').call(bump, message: message)
54
+
55
+ if version_path
56
+ system("git", "checkout", "-b", "release-v#{gemspec.version}")
57
+ system("git", "add", version_path, chdir: context.root)
58
+ system("git", "commit", "-m", message, chdir: context.root)
59
+ else
60
+ raise "Could not find version number!"
61
+ end
62
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative '../../lib/bake/gem/shell'
24
+
25
+ include Bake::Gem::Shell
26
+
27
+ # Increment the patch number of the current version.
28
+ def patch
29
+ commit([nil, nil, 1], message: "Bump patch version.")
30
+ end
31
+
32
+ # Increment the minor number of the current version.
33
+ def minor
34
+ commit([nil, 1, 0], message: "Bump minor version.")
35
+ end
36
+
37
+ # Increment the major number of the current version.
38
+ def major
39
+ commit([1, 0, 0], message: "Bump major version.")
40
+ end
41
+
42
+ # Scans the files listed in the gemspec for a file named `version.rb`. Extracts the VERSION constant and updates it according to the version bump.
43
+ #
44
+ # @parameter bump [Array(Integer | Nil)] the version bump to apply before publishing, e.g. `0,1,0` to increment minor version number.
45
+ # @parameter message [String] the git commit message to use.
46
+ def increment(bump, message: "Bump version.")
47
+ release = context.lookup('gem:release')
48
+ helper = release.instance.helper
49
+ gemspec = helper.gemspec
50
+
51
+ helper.update_version(bump) do |version|
52
+ version_string = version.join('.')
53
+
54
+ Console.logger.info(self) {"Updated version to #{version_string}"}
55
+
56
+ # Ensure that any subsequent tasks use the correct version!
57
+ gemspec.version = ::Gem::Version.new(version_string)
58
+ end
59
+ end
60
+
61
+ # Increments the version and commits the changes on the current branch.
62
+ #
63
+ # @parameter bump [Array(Integer | Nil)] the version bump to apply before publishing, e.g. `0,1,0` to increment minor version number.
64
+ # @parameter message [String] the git commit message to use.
65
+ def commit(bump, message: "Bump version.")
66
+ helper.guard_clean
67
+
68
+ version_path = increment(bump, message: message)
69
+
70
+ if version_path
71
+ system("git", "add", version_path, chdir: context.root)
72
+ system("git", "commit", "-m", message, chdir: context.root)
73
+ else
74
+ raise "Could not find version number!"
75
+ end
76
+ end
data/lib/bake/gem.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "bake/gem/version"
2
+
3
+ module Bake
4
+ module Gem
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'rubygems/package'
25
+
26
+ require_relative 'shell'
27
+
28
+ module Bake
29
+ module Gem
30
+ class Helper
31
+ include Shell
32
+
33
+ def initialize(root = Dir.pwd, gemspec: nil)
34
+ @root = root
35
+ @gemspec = gemspec || self.find_gemspec
36
+ end
37
+
38
+ attr :gemspec
39
+
40
+ def version_path
41
+ @gemspec&.files.grep(/lib(.*?)version.rb/).first
42
+ end
43
+
44
+ VERSION_PATTERN = /VERSION = ['"](?<value>\d+\.\d+\.\d+)(?<pre>.*?)['"]/
45
+
46
+ def update_version(bump)
47
+ return unless version_path = self.version_path
48
+
49
+ lines = File.readlines(version_path)
50
+ version = nil
51
+
52
+ lines.each do |line|
53
+ if match = line.match(VERSION_PATTERN)
54
+ version = match[:value].split(/\./).map(&:to_i)
55
+ bump.each_with_index do |increment, index|
56
+ if increment == 1
57
+ version[index] += 1
58
+ elsif increment == 0
59
+ version[index] = 0
60
+ end
61
+ end
62
+
63
+ line.sub!(match[:value], version.join('.'))
64
+ end
65
+ end
66
+
67
+ if version
68
+ yield version if block_given?
69
+
70
+ File.write(version_path, lines.join)
71
+
72
+ return version_path
73
+ end
74
+ end
75
+
76
+ def guard_clean
77
+ lines = readlines("git", "status", "--porcelain")
78
+
79
+ if lines.any?
80
+ raise "Repository has uncommited changes!\n#{lines.join('')}"
81
+ end
82
+ end
83
+
84
+ # @parameter root [String] The root path for package files.
85
+ # @returns [String] The path to the built gem package.
86
+ def build_gem(root: "pkg")
87
+ # Ensure the output directory exists:
88
+ FileUtils.mkdir_p("pkg")
89
+
90
+ output_path = File.join('pkg', @gemspec.file_name)
91
+
92
+ ::Gem::Package.build(@gemspec, false, false, output_path)
93
+ end
94
+
95
+ def install_gem(*arguments, path: @gemspec.file_name)
96
+ system("gem", "install", path, *arguments)
97
+ end
98
+
99
+ def push_gem(*arguments, path: @gemspec.file_name)
100
+ system("gem", "push", path, *arguments)
101
+ end
102
+
103
+ private
104
+
105
+ def find_gemspec(glob = "*.gemspec")
106
+ paths = Dir.glob(glob, base: @root).sort
107
+
108
+ if paths.size > 1
109
+ raise "Multiple gemspecs found: #{paths}, please specify one!"
110
+ end
111
+
112
+ if path = paths.first
113
+ return ::Gem::Specification.load(path)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Bake
24
+ module Gem
25
+ module Shell
26
+ def system(*arguments, **options)
27
+ Console.logger.info(self, Console::Event::Spawn.for(*arguments, **options))
28
+
29
+ begin
30
+ pid = Process.spawn(*arguments, **options)
31
+ yield if block_given?
32
+ ensure
33
+ pid, status = Process.wait2(pid) if pid
34
+
35
+ unless status.success?
36
+ raise "Failed to execute #{arguments}: #{status}!"
37
+ end
38
+ end
39
+ end
40
+
41
+ def execute(*arguments, **options)
42
+ Console.logger.info(self, Console::Event::Spawn.for(*arguments, **options))
43
+
44
+ IO.pipe do |input, output|
45
+ pid = Process.spawn(*arguments, out: output, **options)
46
+ output.close
47
+
48
+ begin
49
+ yield input
50
+ ensure
51
+ pid, status = Process.wait2(pid)
52
+
53
+ unless status.success?
54
+ raise "Failed to execute #{arguments}: #{status}!"
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def readlines(*arguments, **options)
61
+ execute(*arguments, **options) do |output|
62
+ return output.readlines
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Bake
24
+ module Gem
25
+ VERSION = "0.1.0"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bake-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - bake/gem.rb
20
+ - bake/gem/branch.rb
21
+ - bake/gem/version.rb
22
+ - lib/bake/gem.rb
23
+ - lib/bake/gem/helper.rb
24
+ - lib/bake/gem/shell.rb
25
+ - lib/bake/gem/version.rb
26
+ homepage: https://github.com/ioquatix/bake-gem
27
+ licenses:
28
+ - MIT
29
+ metadata:
30
+ funding_uri: https://github.com/sponsors/ioquatix/
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.3.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.1.6
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Release management for Ruby gems.
50
+ test_files: []