app-release 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66d901ceef4c1692f197234e9da00fc7f539f16f99464030ad12b93a9661e7ac
4
- data.tar.gz: b13743f3fffc8a1eff94ae5d538f9741ad240ac676f311eba547a1445455406e
3
+ metadata.gz: c9f2da32871893861168cbd63742f4120e0c221db42fb98ad7fb9ee2fe3a4b66
4
+ data.tar.gz: b839751a394471cd3db1b735657ecbb011eeceedcda444ea71304966a6d6689f
5
5
  SHA512:
6
- metadata.gz: 9047b8f943ad3b084d7b7f6d803ae177a08665298046e410d8700110bb74f1e4023197d7d5f9a15c3dd16ee39934c7a0d6eb5dcd243ee03e99c0a96a76f7741f
7
- data.tar.gz: 24996ee9a97a2f855e8b8cc6955e4c6e9bb59a70fcef7e94f5054e25165174c342917589fd6dd95fa60e5f71e4494e2edaa4cc47bf8d71a1a4fd539059906cb5
6
+ metadata.gz: 7a754723f4e6116c925bc265215cae7a5bd007e7e11b1fe7976c258f764e684ccf15f75414c5ed966755c1dd5e49ad49f75f442a12fe0bd1bd00f3b7688ce4d7
7
+ data.tar.gz: c694303f987a339d28afae84b3dbf03c63873ccd0c79ad0fa82818bac73504dfa047e030d5181b354aa1983dea5927b6c3b3c5649272048f8f2390bc2d73058c
@@ -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,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 CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Sokolov
@@ -48,7 +48,14 @@ extra_rdoc_files: []
48
48
  files:
49
49
  - LICENSE.md
50
50
  - README.md
51
+ - app_release.gemspec
51
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
52
59
  homepage: https://github.com/afuno/app-release
53
60
  licenses:
54
61
  - MIT