app-release 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c9f2da32871893861168cbd63742f4120e0c221db42fb98ad7fb9ee2fe3a4b66
4
+ data.tar.gz: b839751a394471cd3db1b735657ecbb011eeceedcda444ea71304966a6d6689f
5
+ SHA512:
6
+ metadata.gz: 7a754723f4e6116c925bc265215cae7a5bd007e7e11b1fe7976c258f764e684ccf15f75414c5ed966755c1dd5e49ad49f75f442a12fe0bd1bd00f3b7688ce4d7
7
+ data.tar.gz: c694303f987a339d28afae84b3dbf03c63873ccd0c79ad0fa82818bac73504dfa047e030d5181b354aa1983dea5927b6c3b3c5649272048f8f2390bc2d73058c
@@ -0,0 +1,21 @@
1
+ # MIT LICENSE
2
+
3
+ Copyright (c) 2020 Anton Sokolov <anton@sokolov.digital>
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.
@@ -0,0 +1,49 @@
1
+ # App Release for Rails
2
+
3
+ A simple tool for updating the version of a Rails application.
4
+
5
+ This library was implemented to simplify project versioning. With this tool can store, quickly create and push tags.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'app-release', require: false
11
+ ```
12
+
13
+ ## Using
14
+
15
+ ### Create a version file
16
+
17
+ ```shell
18
+ bundle exec app_release --init
19
+ ```
20
+
21
+ ### Version upgrade
22
+
23
+ ```shell
24
+ # Original version: 2.4.6
25
+
26
+ bundle exec app_release --patch # => 2.4.7
27
+
28
+ bundle exec app_release --minor # => 2.5.0
29
+
30
+ bundle exec app_release --major # => 3.0.0
31
+ ```
32
+
33
+ ### Version upgrade and git tag creation
34
+
35
+ ```shell
36
+ bundle exec app_release --minor --create-git-tag
37
+ ```
38
+
39
+ If need to create a tag in a specific directory, then need to use the following command:
40
+
41
+ ```shell
42
+ bundle exec app_release --minor --create-git-tag-for dev
43
+ ```
44
+
45
+ If need to push after creation, then:
46
+
47
+ ```shell
48
+ bundle exec app_release --minor --create-git-tag-for dev --git-push
49
+ ```
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'app_release/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'app-release'
8
+ spec.version = AppRelease::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ['Anton Sokolov']
11
+ spec.email = ['anton@sokolov.digital']
12
+ spec.homepage = 'https://github.com/afuno/app-release'
13
+ spec.licenses = ['MIT']
14
+ spec.summary = 'A simple tool for updating the version of a Rails application'
15
+ spec.description = 'A simple tool for updating the version of a Rails application'
16
+
17
+ spec.files = `git ls-files -z *.md *.gemspec bin lib`.split("\x0")
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.executables = ['app_release']
21
+
22
+ spec.add_dependency 'colorize', '~> 0.8.1'
23
+ spec.add_development_dependency 'rubocop', '= 0.88'
24
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless File.exist?('./Gemfile')
4
+ abort 'Please run app_release from the root of the project'
5
+ end
6
+
7
+ require 'rubygems'
8
+
9
+ begin
10
+ require 'bundler'
11
+ Bundler.setup
12
+ rescue StandardError
13
+ end
14
+
15
+ $LOAD_PATH << "#{__dir__}/../lib"
16
+
17
+ require 'app_release/parser'
18
+
19
+ AppRelease::Parser.parse(ARGV)
@@ -0,0 +1,2 @@
1
+ module AppRelease
2
+ end
@@ -0,0 +1,34 @@
1
+ require 'colorize'
2
+
3
+ module AppRelease
4
+ class Console
5
+ def self.print(text, color = nil)
6
+ new(text, color).print
7
+ end
8
+
9
+ def self.log(text)
10
+ new(text, nil).print
11
+ end
12
+
13
+ def self.success(text)
14
+ new(text, :green).print
15
+ end
16
+
17
+ def self.warning(text)
18
+ new(text, :yellow).print
19
+ end
20
+
21
+ def self.danger(text)
22
+ new(text, :red).print
23
+ end
24
+
25
+ def initialize(text, color = nil)
26
+ @text = text
27
+ @color = color
28
+ end
29
+
30
+ def print
31
+ puts @text.colorize(@color)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module AppRelease
2
+ module Constants
3
+ FILE_NAME = '.app-release.yml'.freeze
4
+
5
+ INIT_VERSION = {
6
+ major: 1,
7
+ minor: 0,
8
+ patch: 0
9
+ }.freeze
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'app_release/console'
2
+
3
+ module AppRelease
4
+ class Git
5
+ def self.create(version, prefix)
6
+ new(version, prefix).create
7
+ end
8
+
9
+ def self.push
10
+ `git push origin --tags`
11
+
12
+ AppRelease::Console.success('git push')
13
+ end
14
+
15
+ def initialize(version, prefix = nil)
16
+ @prefix = prefix
17
+ @version = "v#{version}"
18
+ end
19
+
20
+ def create
21
+ `git tag #{name_formatted}`
22
+
23
+ AppRelease::Console.success("Tag #{name_formatted} was created")
24
+
25
+ # rescue => e
26
+ # AppRelease::Console.danger(e)
27
+ end
28
+
29
+ private
30
+
31
+ def name_formatted
32
+ [
33
+ @prefix,
34
+ @version
35
+ ].join('/')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,182 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+
4
+ require 'app_release/constants'
5
+ require 'app_release/console'
6
+ require 'app_release/git'
7
+
8
+ module AppRelease
9
+ class Parser
10
+ attr_reader :args, :actions
11
+
12
+ DEFAULT_ACTIONS = {
13
+ init: false
14
+ }.freeze
15
+
16
+ def self.parse(args)
17
+ new(args).parse
18
+ end
19
+
20
+ def initialize(args)
21
+ @args = args
22
+ @actions = DEFAULT_ACTIONS.dup
23
+ end
24
+
25
+ def parse
26
+ # puts
27
+ # puts
28
+ # puts @args.inspect
29
+ # puts
30
+ # puts
31
+
32
+ parser.parse!(args)
33
+
34
+ # @actions
35
+ rescue StandardError => e
36
+ AppRelease::Console.danger("Ambiguously completable string is encountered\n#{e}")
37
+ end
38
+
39
+ private
40
+
41
+ def parser
42
+ OptionParser.new do |opts|
43
+ opts.banner = 'Usage: app_release [options]'
44
+
45
+ opts.on('-i', '--init', 'Creates a version file at the root of the project') do
46
+ init_version_file
47
+ exit
48
+ end
49
+
50
+ opts.on('-v', '--version', 'The current version of the gem') do
51
+ AppRelease::Console.log(AppRelease::VERSION)
52
+ exit
53
+ end
54
+
55
+ opts.on('-h', '--help', 'Prints this help') do
56
+ AppRelease::Console.log(opts)
57
+ exit
58
+ end
59
+
60
+ opts.on('--major', 'Upgrading the major version') do
61
+ upgrading_version(:major)
62
+ end
63
+
64
+ opts.on('--minor', 'Upgrading the minor update') do
65
+ upgrading_version(:minor)
66
+ end
67
+
68
+ opts.on('--patch', 'Upgrading the patch update') do
69
+ upgrading_version(:patch)
70
+ end
71
+
72
+ opts.on('--create-git-tag', 'Create git tag') do
73
+ create_git_tag_with
74
+ end
75
+
76
+ opts.on('--create-git-tag-for PREFIX', 'Create git tag with prefix') do |prefix|
77
+ create_git_tag_with(prefix)
78
+ end
79
+
80
+ opts.on('--git-push', 'git push') do
81
+ AppRelease::Git.push
82
+ end
83
+ end
84
+ end
85
+
86
+ def init_version_file
87
+ if file_exists?
88
+ AppRelease::Console.warning("File #{AppRelease::Constants::FILE_NAME} has already been created")
89
+ else
90
+ create_version_file
91
+
92
+ AppRelease::Console.success("File #{AppRelease::Constants::FILE_NAME} was created")
93
+ end
94
+ end
95
+
96
+ def upgrading_version(section)
97
+ unless file_exists?
98
+ AppRelease::Console.danger(
99
+ "First, you need to create a version file.\nTo do this, run command `bundle exec app_release --init`"
100
+ )
101
+ exit
102
+ end
103
+
104
+ file = current_version_file.dup
105
+
106
+ major = file[:major]
107
+ minor = file[:minor]
108
+ patch = file[:patch]
109
+
110
+ if !major.positive? && !minor.positive? && !patch.positive?
111
+ AppRelease::Console.danger('Something is wrong with the versions')
112
+ exit
113
+ end
114
+
115
+ AppRelease::Console.warning("Previous version: #{version_formatted_for(file)}")
116
+
117
+ version_from_section = file[section]
118
+
119
+ file[section] = version_from_section + 1
120
+
121
+ if section == :major
122
+ file[:minor] = 0
123
+ file[:patch] = 0
124
+ elsif section == :minor
125
+ file[:patch] = 0
126
+ end
127
+
128
+ update_version_file_with(file)
129
+
130
+ AppRelease::Console.success("New version: #{version_formatted_for(file)}")
131
+ end
132
+
133
+ def version_formatted_for(file)
134
+ major = file[:major]
135
+ minor = file[:minor]
136
+ patch = file[:patch]
137
+
138
+ [
139
+ major,
140
+ minor,
141
+ patch
142
+ ].join('.')
143
+ end
144
+
145
+ def current_version_file
146
+ @current_version_file ||= YAML.load_file(file_path)
147
+ end
148
+
149
+ def create_version_file
150
+ write_in_file_with(AppRelease::Constants::INIT_VERSION)
151
+ end
152
+
153
+ def update_version_file_with(data)
154
+ write_in_file_with(data)
155
+ end
156
+
157
+ def write_in_file_with(data)
158
+ File.open(file_path, 'w') do |file|
159
+ file.write("# Edit this file manually only if you know what you are doing\n\n")
160
+ file.write(data.to_yaml.gsub("---\n", ''))
161
+ end
162
+ end
163
+
164
+ def file_exists?
165
+ File.exist?(file_path)
166
+ end
167
+
168
+ def file_path
169
+ "#{Dir.pwd}/#{AppRelease::Constants::FILE_NAME}"
170
+ end
171
+
172
+ ############################################################################
173
+ ############################################################################
174
+ ############################################################################
175
+
176
+ def create_git_tag_with(prefix = nil)
177
+ file = current_version_file.dup
178
+ version = version_formatted_for(file)
179
+ AppRelease::Git.create(version, prefix)
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,11 @@
1
+ module AppRelease
2
+ MAJOR = 1
3
+ MINOR = 0
4
+ PATCH = 1
5
+
6
+ VERSION = [
7
+ MAJOR,
8
+ MINOR,
9
+ PATCH
10
+ ].join('.')
11
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: app-release
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anton Sokolov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.88'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '0.88'
41
+ description: A simple tool for updating the version of a Rails application
42
+ email:
43
+ - anton@sokolov.digital
44
+ executables:
45
+ - app_release
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.md
50
+ - README.md
51
+ - app_release.gemspec
52
+ - bin/app_release
53
+ - lib/app_release.rb
54
+ - lib/app_release/console.rb
55
+ - lib/app_release/constants.rb
56
+ - lib/app_release/git.rb
57
+ - lib/app_release/parser.rb
58
+ - lib/app_release/version.rb
59
+ homepage: https://github.com/afuno/app-release
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.1.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A simple tool for updating the version of a Rails application
82
+ test_files: []