sti_deploy 0.1.0rc1

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
+ SHA1:
3
+ metadata.gz: 928e039c280f04e44a90c5553aa702437d90dffd
4
+ data.tar.gz: 2852110951a268b5d48e28a42471c8a169899a92
5
+ SHA512:
6
+ metadata.gz: 29c54da5bfdc68d032e699d910a09bda9d9e7b2b45365de56673c2acc8f2e0e8c91a812e99d26d16fc5759b10af01c4457648992bd87159b472408d3fa55cd74
7
+ data.tar.gz: d4472b475724f665af41d04a25e01e35aa1852e545df4b73c1da95d406497d82fc9f20401389ad2d4106cd68aed49996a6c10bb411c6c339a5d98215168799cf
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Rodrigo Castro
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # STI Deploy
2
+ An automated script to make commits and merges faster
data/bin/sti_deploy ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/sti_deploy'
5
+
6
+ StiDeploy.begin_sti_deploy
data/lang/en.yml ADDED
@@ -0,0 +1,18 @@
1
+ en:
2
+ messages:
3
+ version:
4
+ file_not_found: The version file was not found in "%{path}"!
5
+ not_found: A valid version number was not found in the file "%{path}"!
6
+ detected: "Version number detected: %{version}"
7
+ increment: "\nThe version number will be bumped from \"%{old}\" to \"%{new}\"."
8
+ deploy_type:
9
+ prompt: "\nIs the deploy for hot(f)ix, staging(h), or (p)roject? Type in \"f\", \"h\", or \"p\": "
10
+ invalid: 'Invalid option. Type in only "f", "h", or "p", imbecile!'
11
+ release_message:
12
+ prompt: "\nInform a summary of the changes made, in order to create a Git tag:\n> "
13
+ invalid: 'Please write a proper summary (min of 10 chars)!'
14
+ git:
15
+ by: by
16
+ preparing: Setting up for deploy.
17
+ system:
18
+ interrupted: "\n\nDeploy aborted. Bye-bye."
data/lang/pt-BR.yml ADDED
@@ -0,0 +1,18 @@
1
+ pt-BR:
2
+ messages:
3
+ version:
4
+ file_not_found: O arquivo de versão não foi encontrado em "%{path}"!
5
+ not_found: "Um número de versão válido não foi encontrado em \"%{path}\"!"
6
+ detected: "Número de versão detectado: %{version}"
7
+ increment: "\nA versão será incrementada de \"%{old}\" para \"%{new}\"."
8
+ deploy_type:
9
+ prompt: "\nO deploy é para hot(f)ix, (h)omologação, or (p)rojeto? Digite \"f\", \"h\", ou \"p\": "
10
+ invalid: 'Tipo inválido. Digite apenas "f", "h", ou "p", animal!'
11
+ release_message:
12
+ prompt: "\nEscreva um resumo das alterações feitas, para criar a tag no Git:\n> "
13
+ invalid: 'Escreva uma mensagem decente (min 10 chars)!'
14
+ git:
15
+ by: por
16
+ preparing: Preparando para deploy.
17
+ system:
18
+ interrupted: "\n\nDeploy abortado. Bye-bye."
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'pry'
5
+
6
+ module StiDeploy
7
+ class Configuration
8
+ CONFIG_PATH = 'sti_deploy.yml'
9
+
10
+ class << self
11
+ attr_reader :config
12
+
13
+ def version_path
14
+ read('version_path') || 'config/initializers/version.rb'
15
+ end
16
+
17
+ def language
18
+ read('language') || 'en'
19
+ end
20
+
21
+ def git_username
22
+ read('git_username') || ''
23
+ end
24
+
25
+ def origin_branch(deploy_type)
26
+ read('branches')[deploy_type.full_name]['origin'] || 'master'
27
+ rescue StandardError
28
+ 'master'
29
+ end
30
+
31
+ def target_branch(deploy_type)
32
+ read('branches')[deploy_type.full_name]['target'] || 'master'
33
+ rescue StandardError
34
+ 'master'
35
+ end
36
+
37
+ private
38
+
39
+ def read(config_name)
40
+ unless defined? @config
41
+ @config = YAML.safe_load(File.open(CONFIG_PATH))
42
+ end
43
+ @config[config_name]
44
+ rescue StandardError
45
+ @config = nil
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StiDeploy
4
+ class Deploy
5
+ attr_reader :version, :type, :message, :git_user
6
+
7
+ def initialize
8
+ @version = Version.load_version
9
+ @git_user = Configuration.git_username
10
+ end
11
+
12
+ def update_version!
13
+ version.bump(read_type)
14
+ version.update_file!
15
+ end
16
+
17
+ def commit_merge_and_tag!
18
+ git_commit!
19
+ git_merge!
20
+ git_tag!
21
+ end
22
+
23
+ private
24
+
25
+ def read_type
26
+ Messages.print('deploy_type.prompt')
27
+ type = gets.chomp
28
+ return @type = DeployType.new(type) if %w[f F h H p P].include? type
29
+ Messages.puts('deploy_type.invalid')
30
+ read_type
31
+ end
32
+
33
+ def read_release_message
34
+ Messages.print('release_message.prompt')
35
+ msg = gets.chomp
36
+ return @message = msg if msg.size >= 10
37
+ Messages.puts('release_message.invalid')
38
+ read_release_message
39
+ end
40
+
41
+ def git_commit!
42
+ read_release_message
43
+ Git.add_version
44
+ Git.commit(message: commit_message)
45
+ Git.push(branch: Configuration.origin_branch(type))
46
+ end
47
+
48
+ def git_merge!
49
+ Git.checkout(branch: Configuration.target_branch(type))
50
+ Git.pull(branch: Configuration.target_branch(type))
51
+ Git.merge(branch: Configuration.origin_branch(type))
52
+ Git.push(branch: Configuration.target_branch(type))
53
+ Git.checkout(branch: Configuration.origin_branch(type))
54
+ end
55
+
56
+ def git_tag!
57
+ Git.tag(version: version.to_s, message: message)
58
+ Git.push_tags
59
+ end
60
+
61
+ def commit_message
62
+ by = I18n.t('messages.git.by')
63
+ preparing = I18n.t('messages.git.preparing')
64
+ return "#{preparing} #{message}" if git_user.nil? || git_user.empty?
65
+ "#{by} #{git_user}: #{preparing} #{message}"
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StiDeploy
4
+ class DeployType
5
+ attr_reader :type
6
+
7
+ def initialize(type)
8
+ @type = type.downcase
9
+ end
10
+
11
+ def full_name
12
+ { h: 'staging', f: 'hotfix', p: 'project' }[type]
13
+ end
14
+
15
+ def to_s
16
+ type
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StiDeploy
4
+ class Git
5
+ class << self
6
+ def add_version
7
+ `git add #{Configuration.version_path}`
8
+ end
9
+
10
+ def commit(message: '')
11
+ `git commit -m "#{message.tr('"', '\"')}"`
12
+ end
13
+
14
+ def checkout(branch: 'master')
15
+ `git checkout #{branch}`
16
+ end
17
+
18
+ def merge(branch: 'master')
19
+ `git merge #{branch}`
20
+ end
21
+
22
+ def tag(version: '', message: '')
23
+ `git tag -a v#{version.to_s} -m "#{message.tr('"', '\"')}"`
24
+ end
25
+
26
+ def pull(branch: 'master', remote: 'origin')
27
+ `git pull #{remote} #{branch}`
28
+ end
29
+
30
+ def push(branch: 'master', remote: 'origin')
31
+ `git push #{remote} #{branch}`
32
+ end
33
+
34
+ def push_tags
35
+ `git push --tags`
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'i18n'
4
+
5
+ begin
6
+ require 'colorize'
7
+ rescue LoadError
8
+ # No I18n support yet at this point ):
9
+ puts "Colorize gem not found. No terminal color support.\n\n"
10
+ end
11
+
12
+ module StiDeploy
13
+ class Messages
14
+ LANG_PATH = File.expand_path(File.join(__dir__, '../../', 'lang/', '*.yml'))
15
+
16
+ class << self
17
+ # Load the translation files and set the configured language
18
+ def load_messages
19
+ I18n.load_path = Dir[LANG_PATH]
20
+ I18n.backend.load_translations
21
+ I18n.default_locale = :en
22
+ I18n.locale = Configuration.language
23
+ end
24
+
25
+ def puts(i18n_key, options = {})
26
+ super colorized_message(i18n_key, options)
27
+ end
28
+
29
+ def print(i18n_key, options = {})
30
+ super colorized_message(i18n_key, options)
31
+ end
32
+
33
+ private
34
+
35
+ def colorized_message(i18n_key, options)
36
+ color = options.delete(:color)
37
+ message = I18n.t("messages.#{i18n_key}", options)
38
+ return message unless color && message.respond_to?(:colorize)
39
+ message.colorize(color)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StiDeploy
4
+ class Version
5
+ attr_accessor :major, :minor, :hotfix, :rc, :pre
6
+
7
+ FULL_VERSION_REGEX = /[\d]+.[\d]+.[\d]+(rc[\d]+)?(pre[\d]+)?/
8
+
9
+ class << self
10
+ def load_version
11
+ validate_version_file
12
+ version = read_current_version
13
+ validate_version(version)
14
+ Messages.puts('version.detected', version: version, color: :green)
15
+ version
16
+ end
17
+
18
+ private
19
+
20
+ def validate_version_file
21
+ return true if File.file?(Configuration.version_path)
22
+ Messages.puts('version.file_not_found',
23
+ path: Configuration.version_path, color: :red)
24
+ exit(-1)
25
+ end
26
+
27
+ def read_current_version
28
+ File.open(Configuration.version_path).each do |line|
29
+ version = line[FULL_VERSION_REGEX]
30
+ return Version.new(version.tr('\'"', '')) if version
31
+ end
32
+ end
33
+
34
+ def validate_version(version)
35
+ return true if version && !version.is_a?(File)
36
+ Messages.puts('version.not_found', path: Configuration.version_path,
37
+ color: :red)
38
+ exit(-2)
39
+ end
40
+ end
41
+
42
+ def initialize(version)
43
+ @major, @minor, @hotfix = version[/[\d]+.[\d]+.[\d]+/].split('.')
44
+ .map(&:to_i)
45
+ self.rc = version[/rc[\d]+/].to_s.tr('rc', '').to_i
46
+ self.pre = version[/pre[\d]+/].to_s.tr('pre', '').to_i
47
+ end
48
+
49
+ def bump(deploy_type)
50
+ old = to_s
51
+ send("bump_#{deploy_type}")
52
+ Messages.puts('version.increment', old: old, new: to_s)
53
+ to_s
54
+ end
55
+
56
+ def update_file!
57
+ version_file = File.read(Configuration.version_path)
58
+ new_version = version_file.gsub(FULL_VERSION_REGEX, to_s)
59
+ File.open(Configuration.version_path, 'w') { |f| f.puts new_version }
60
+ end
61
+
62
+ def to_s
63
+ base = "#{major}.#{minor}.#{hotfix}"
64
+ base += "rc#{rc}" if rc.positive?
65
+ base += "pre#{pre}" if pre.positive?
66
+ base
67
+ end
68
+
69
+ private
70
+
71
+ # Bump hot(f)ix
72
+ def bump_f
73
+ self.hotfix += 1
74
+ end
75
+
76
+ # Bump (h)omologação
77
+ def bump_h
78
+ self.minor += 1 if rc.zero? # Se ainda não existir RC, dá bump no minor
79
+ self.hotfix = 0
80
+ self.rc += 1
81
+ end
82
+
83
+ # Bump (p)rojeto
84
+ def bump_p
85
+ self.minor += 1 if pre.zero? # Se ainda não existir PRE, dá bump no minor
86
+ self.hotfix = 0
87
+ self.pre += 1
88
+ end
89
+ end
90
+ end
data/lib/sti_deploy.rb ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ require_relative 'sti_deploy/configuration'
6
+ require_relative 'sti_deploy/messages'
7
+ require_relative 'sti_deploy/version'
8
+ require_relative 'sti_deploy/git'
9
+ require_relative 'sti_deploy/deploy_type'
10
+ require_relative 'sti_deploy/deploy'
11
+
12
+ # Program exit codes:
13
+ #
14
+ # -3: Error: Program was interrupted (CTRL+C)
15
+ # -2: Error: Version file was not found
16
+ # -1: Error: A valid version number within the version file was not found
17
+ # 0: Program exited successfully
18
+
19
+ module StiDeploy
20
+ class << self
21
+ def begin_sti_deploy
22
+ Messages.load_messages
23
+ deploy = Deploy.new
24
+ deploy.update_version!
25
+ deploy.commit_merge_and_tag!
26
+ rescue Interrupt
27
+ Messages.puts 'system.interrupted', color: :red
28
+ exit(-3)
29
+ end
30
+ end
31
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ VERSION = '0.1.0rc1'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sti_deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0rc1
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Castro Azevedo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-05 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A small program to make commits and merges faster. This program automagically
84
+ bumps the version number, commits to the working branch, merges to the deploy branch,
85
+ and creates a release tag.
86
+ email:
87
+ - rod.c.azevedo@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - LICENSE
93
+ - README.md
94
+ - bin/sti_deploy
95
+ - lang/en.yml
96
+ - lang/pt-BR.yml
97
+ - lib/sti_deploy.rb
98
+ - lib/sti_deploy/configuration.rb
99
+ - lib/sti_deploy/deploy.rb
100
+ - lib/sti_deploy/deploy_type.rb
101
+ - lib/sti_deploy/git.rb
102
+ - lib/sti_deploy/messages.rb
103
+ - lib/sti_deploy/version.rb
104
+ - lib/version.rb
105
+ homepage: https://github.com/roooodcastro/sti_deploy
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">"
121
+ - !ruby/object:Gem::Version
122
+ version: 1.3.1
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.6.13
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A small program to make commits and merges faster.
129
+ test_files: []