semantic_release 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 229b0a68dcb2758c59ea49303e7f5e4dd3320da5f96662f9475ea9cefae093e4
4
+ data.tar.gz: 2e05b0c685a867b4612cf4d47a58cd861c4dc1d276e31064c297ccbea90674e9
5
+ SHA512:
6
+ metadata.gz: 6cef35b65b374159ae329ebc38c524c81158c0835a722da271343031d9abc006e4944c26e7ad0cabcd7ffc433db92cb003b766e69bcd333841546db3282d07d5
7
+ data.tar.gz: 3fbfc6a1ccad7ee107316ed6b6825403eb716a42e1e97cc49f2eeaf21ca93bcb194cdb2961af14dc3471e7e97568e59822ff161d302c9785e2c6700cfa14b5dd
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.1
7
+ NewCops: enable
8
+
9
+ Layout/LineContinuationLeadingSpace:
10
+ EnforcedStyle: leading
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Style/StringLiterals:
16
+ EnforcedStyle: double_quotes
17
+
18
+ Style/StringLiteralsInInterpolation:
19
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 David Bull
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.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # SemanticRelease
2
+
3
+ This gem helps you to manage the version number of your application or library.
4
+
5
+ Use the provided Rake tasks to:
6
+
7
+ - bump the major, minor, or patch number of your version
8
+ - automatically update our verison file (e.g. `lib/version.rb`)
9
+ - automatically update your changelog (`CHANGELOG.md` or `history.rdoc`)
10
+ - automatically create a git commit and tag for the release
11
+
12
+ This gem was inspired by:
13
+
14
+ - SemVer2 (https://github.com/haf/semver)
15
+ - Rake-n-Bake (https://github.com/RichardVickerstaff/rake-n-bake)
16
+ - Version Manager (https://github.com/tpbowden/version_manager)
17
+
18
+ ## Installation
19
+
20
+ Install the gem and add to the application's Gemfile by executing:
21
+
22
+ ```bash
23
+ bundle add semantic_release
24
+ ```
25
+
26
+ If bundler is not being used to manage dependencies, install the gem by executing:
27
+
28
+ ```bash
29
+ gem install semantic_release
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Add the Rake task by adding the following lines to a Rake configuration file (e.g. `Rakefile` or `lib/tasks/default.rake`):
35
+
36
+ ```ruby
37
+ require "semantic_release/rake_task"
38
+ SemanticRelease::RakeTask.new
39
+ ```
40
+
41
+ The following tasks are available:
42
+
43
+ ```
44
+ rake semantic_release:init
45
+ rake semantic_release:current
46
+ rake semantic_release:major
47
+ rake semantic_release:minor
48
+ rake semantic_release:patch
49
+ ```
50
+
51
+ To get the current version inside your application:
52
+
53
+ ```ruby
54
+ SemanticRelease.current_version
55
+ ```
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ukdave/semantic_release.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+ RuboCop::RakeTask.new
10
+
11
+ require_relative "lib/semantic_release/rake_task"
12
+ SemanticRelease::RakeTask.new
13
+
14
+ task default: %i[spec rubocop]
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/tasklib"
4
+ require "semantic_release"
5
+
6
+ module SemanticRelease
7
+ class RakeTask < Rake::TaskLib
8
+ # rubocop:disable Metrics/MethodLength
9
+ def initialize
10
+ super
11
+
12
+ namespace :semantic_release do
13
+ desc "Initialise version file"
14
+ task :init do
15
+ SemanticRelease.init
16
+ end
17
+
18
+ desc "Display current version"
19
+ task :current do
20
+ puts SemanticRelease.current_version
21
+ end
22
+
23
+ desc "Increment major version (e.g. 1.2.3 => 2.0.0)"
24
+ task :major do
25
+ SemanticRelease.inc_major
26
+ end
27
+
28
+ desc "Increment minor version (e.g. 1.2.3 => 1.3.0)"
29
+ task :minor do
30
+ SemanticRelease.inc_minor
31
+ end
32
+
33
+ desc "Increment patch version (e.g. 1.2.3 => 1.2.4)"
34
+ task :patch do
35
+ SemanticRelease.inc_patch
36
+ end
37
+ end
38
+ end
39
+ # rubocop:enable Metrics/MethodLength
40
+ end
41
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module SemanticRelease
6
+ class Semver
7
+ include Comparable
8
+
9
+ attr_reader :major, :minor, :patch
10
+
11
+ def initialize(major: 0, minor: 0, patch: 0, file: nil)
12
+ @major = major
13
+ @minor = minor
14
+ @patch = patch
15
+ @file = file
16
+ end
17
+
18
+ def self.load(file)
19
+ data = JSON.parse(File.read(file))
20
+ new(major: data["major"], minor: data["minor"], patch: data["patch"], file: file)
21
+ end
22
+
23
+ def save(file = nil)
24
+ f = file || @file
25
+ File.write(f, JSON.generate(to_h))
26
+ end
27
+
28
+ def increment(term)
29
+ case term.to_sym
30
+ when :major then increment_major
31
+ when :minor then increment_minor
32
+ when :patch then increment_patch
33
+ else raise ArgumentError, "Bad term"
34
+ end
35
+ self
36
+ end
37
+
38
+ def increment_major
39
+ @major += 1
40
+ @minor = 0
41
+ @patch = 0
42
+ end
43
+
44
+ def increment_minor
45
+ @minor += 1
46
+ @patch = 0
47
+ end
48
+
49
+ def increment_patch
50
+ @patch += 1
51
+ end
52
+
53
+ def to_s
54
+ [@major, @minor, @patch].join(".")
55
+ end
56
+
57
+ def to_h
58
+ { major: @major, minor: @minor, patch: @patch }
59
+ end
60
+
61
+ def <=>(other)
62
+ %i[major minor patch].each do |method|
63
+ comparison = (send(method) <=> other.send(method))
64
+ return comparison unless comparison.zero?
65
+ end
66
+ 0
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SemanticRelease
4
+ module Updaters
5
+ class BaseUpdater
6
+ def self.update
7
+ raise "Not implemented"
8
+ end
9
+
10
+ def self.current_version
11
+ Semver.load(semver_file).to_s
12
+ end
13
+
14
+ def self.semver_file
15
+ SemanticRelease::SEMVER_FILE
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SemanticRelease
4
+ module Updaters
5
+ class Changelog < BaseUpdater
6
+ FILES = %w[CHANGELOG.md history.rdoc].freeze
7
+
8
+ def self.update
9
+ FILES.each do |file|
10
+ next unless File.exist?(file)
11
+
12
+ prepend_version(file)
13
+ `git add #{file}`
14
+ end
15
+ end
16
+
17
+ def self.prepend_version(filepath)
18
+ heading_marker = filepath.end_with?(".rdoc") ? "==" : "##"
19
+ content = File.read(filepath)
20
+ File.open(filepath, "w") do |f|
21
+ f.puts("#{heading_marker} #{current_version} (#{Time.now.strftime("%d %B %Y")})\n")
22
+ f.print(content)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SemanticRelease
4
+ module Updaters
5
+ class GitTag < BaseUpdater
6
+ def self.update
7
+ tag = "v#{current_version}"
8
+ msg = "Increment version to v#{current_version}"
9
+
10
+ `git add #{semver_file} && git commit -m '#{msg}' && git tag #{tag} -a -m '#{Time.now}'`
11
+
12
+ branch = `git rev-parse --abbrev-ref HEAD`.chomp
13
+ puts "To push the new tag, use 'git push origin #{branch} --tags'"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SemanticRelease
4
+ module Updaters
5
+ class VersionRb < BaseUpdater
6
+ def self.update
7
+ version_file = find_version_rb
8
+ return unless version_file
9
+
10
+ version_string = "VERSION = \"#{current_version}\""
11
+ content = File.read(version_file).sub(/VERSION = .*$/, version_string)
12
+
13
+ File.write(version_file, content)
14
+ `git add #{version_file}`
15
+ end
16
+
17
+ def self.find_version_rb
18
+ version_files = Dir.glob("lib{,/**/*}/version.rb")
19
+ return nil unless version_files.size == 1
20
+
21
+ version_files.first
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SemanticRelease
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "semantic_release/semver"
4
+ require_relative "semantic_release/version"
5
+ Dir[File.join(__dir__, "semantic_release", "updaters", "*.rb")].each { |file| require file }
6
+
7
+ module SemanticRelease
8
+ class Error < StandardError; end
9
+
10
+ SEMVER_FILE = ".semver"
11
+
12
+ def self.init
13
+ version = Semver.new
14
+ version.save(SEMVER_FILE)
15
+ end
16
+
17
+ def self.current_version
18
+ Semver.load(SEMVER_FILE).to_s
19
+ end
20
+
21
+ def self.inc_major
22
+ increment(:major)
23
+ release
24
+ end
25
+
26
+ def self.inc_minor
27
+ increment(:minor)
28
+ release
29
+ end
30
+
31
+ def self.inc_patch
32
+ increment(:patch)
33
+ release
34
+ end
35
+
36
+ def self.increment(term)
37
+ version = Semver.load(SEMVER_FILE)
38
+ version.increment(term)
39
+ version.save
40
+ end
41
+
42
+ def self.release
43
+ Updaters::Changelog.update
44
+ Updaters::VersionRb.update
45
+ Updaters::GitTag.update
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: semantic_release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Bull
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-02-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ This gem helps you to manage the version number of your application or library. It provides Rake tasks to
14
+ automatically update your version file, changelog file, and create a git tag.
15
+ email:
16
+ - david@uk-dave.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/semantic_release.rb
28
+ - lib/semantic_release/rake_task.rb
29
+ - lib/semantic_release/semver.rb
30
+ - lib/semantic_release/updaters/base_updater.rb
31
+ - lib/semantic_release/updaters/changelog.rb
32
+ - lib/semantic_release/updaters/git_tag.rb
33
+ - lib/semantic_release/updaters/version_rb.rb
34
+ - lib/semantic_release/version.rb
35
+ homepage: https://github.com/ukdave/semantic_release
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/ukdave/semantic_release
40
+ source_code_uri: https://github.com/ukdave/semantic_release
41
+ changelog_uri: https://github.com/ukdave/semantic_release/blob/main/CHANGELOG.md
42
+ rubygems_mfa_required: 'true'
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.1.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.6.2
58
+ specification_version: 4
59
+ summary: Rake tasks to help you to manage your version number and releases
60
+ test_files: []