verto 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9cf99e88c0aba3a13434d4507aa20da7caf42f67fd9e0a466973560ed30c4b6
4
- data.tar.gz: 02eef1a0ac463fdbf6e3bd88b78c704bfe0fb5478f02299c6fe1d6a13ee48b9a
3
+ metadata.gz: 3d8e4c4c7f370860515641f6e6ef1434b9b7d8d99dba5e141d8fec5aaf267293
4
+ data.tar.gz: 7a1cb951a8ed2bce249ab18b2e27297161d2324db77ab288eb9d2dbd677837f8
5
5
  SHA512:
6
- metadata.gz: 709df38d0b3579f99521b90d2924fe553f13d7666050b26c4d0785f1a3022dbd97b7287beb80bee0c5b179aa3747a1471ed98e94951ba61586e54eb3b8df09af
7
- data.tar.gz: 83c4b2c413d7a37d612704f0f37437ac6f92edc709dacda0c3829a5bd77ce27d5de6db15a0fc30776e38849cd56828f040d042fb86eb93690883a66c195f6928
6
+ metadata.gz: 7c0965949b73fb2327d943b28b89d796d5e3e7e5358f805c0767778f5b3c15bf10fe6b73af7284e4e800f3314fa7e36d533fef80a263aef1e6ab20b63d3a8f11
7
+ data.tar.gz: c4b35bf0353b9dfecfdf869edb8aa560616a5c04c46e934876f3e27721d1cf1ed528afd7374bcffe15b6fdc1230a2556e1781b9671b3a4e19b65c6a7886c4d0b
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- verto (0.3.1)
4
+ verto (0.4.0)
5
5
  dry-auto_inject (~> 0.7)
6
6
  dry-configurable (~> 0.8)
7
7
  dry-container (~> 0.7)
8
8
  thor (~> 1.0.1)
9
+ vseries (~> 0.1)
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
@@ -16,7 +17,7 @@ GEM
16
17
  docile (1.3.2)
17
18
  dry-auto_inject (0.7.0)
18
19
  dry-container (>= 0.3.4)
19
- dry-configurable (0.11.4)
20
+ dry-configurable (0.11.5)
20
21
  concurrent-ruby (~> 1.0)
21
22
  dry-core (~> 0.4, >= 0.4.7)
22
23
  dry-equalizer (~> 0.2)
@@ -45,6 +46,7 @@ GEM
45
46
  simplecov-html (~> 0.11)
46
47
  simplecov-html (0.12.2)
47
48
  thor (1.0.1)
49
+ vseries (0.1.1)
48
50
 
49
51
  PLATFORMS
50
52
  ruby
@@ -58,4 +60,4 @@ DEPENDENCIES
58
60
  verto!
59
61
 
60
62
  BUNDLED WITH
61
- 2.0.2
63
+ 2.1.4
data/README.md CHANGED
@@ -32,20 +32,20 @@ You don't need to install verto in your machine, you can run verto via the docke
32
32
  To use verto in the same way that you use any other cli, you can set an alias in your `.bashrc`, `.zshrc`, etc:
33
33
 
34
34
  ```
35
- alias verto='docker run -v $(pwd):/usr/src/project -it catks/verto:0.3.0'
35
+ alias verto='docker run -v $(pwd):/usr/src/project -it catks/verto:0.4.0'
36
36
  ```
37
37
 
38
38
  If you want you can share your git configuration and known_hosts with:
39
39
 
40
40
  ```
41
- alias verto='docker run -v ~/.gitconfig:/etc/gitconfig -v $(pwd):/usr/src/project -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -it catks/verto:0.3.0'
41
+ alias verto='docker run -v ~/.gitconfig:/etc/gitconfig -v $(pwd):/usr/src/project -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -it catks/verto:0.4.0'
42
42
 
43
43
  ```
44
44
 
45
45
  You can also use your ssh keys with verto container (for git push):
46
46
 
47
47
  ```
48
- alias verto='docker run -v $(pwd):/usr/src/project -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa -e SSH_PRIVATE_KEY=/root/.ssh/id_rsa -it catks/verto:0.3.0'
48
+ alias verto='docker run -v $(pwd):/usr/src/project -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa -e SSH_PRIVATE_KEY=/root/.ssh/id_rsa -it catks/verto:0.4.0'
49
49
 
50
50
  ```
51
51
 
@@ -53,7 +53,7 @@ Or share the git config, known_hosts and ssh_keys:
53
53
 
54
54
 
55
55
  ```
56
- alias verto='docker run -v ~/.gitconfig:/etc/gitconfig -v $(pwd):/usr/src/project -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa -e SSH_PRIVATE_KEY=/root/.ssh/id_rsa -it catks/verto:0.3.0'
56
+ alias verto='docker run -v ~/.gitconfig:/etc/gitconfig -v $(pwd):/usr/src/project -v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa -e SSH_PRIVATE_KEY=/root/.ssh/id_rsa -it catks/verto:0.4.0'
57
57
 
58
58
  ```
59
59
 
@@ -73,27 +73,44 @@ You can run verto right out of the box without any configuration:
73
73
 
74
74
  If you need a more specific configuration or want to reflect your development proccess in some way, you can use Verto DSL creating a Vertofile with the configuration.
75
75
 
76
+ You can create a new Vertofile, with `verto init` or following the next example:
77
+
76
78
  ```ruby
77
79
  # Vertofile
78
80
 
79
- verto_version "0.3.0"
80
-
81
- config {
82
- pre_release.initial_number = 0
83
- project.path = "my/repo/path"
84
- }
85
-
86
- before { sh('echo "Creating Tag"') }
81
+ verto_version '0.4.0'
87
82
 
88
83
  context(branch('master')) {
84
+ before_command('tag_up') {
85
+ git!('origin master')
86
+ command_options.add(filter: 'release_only')
87
+ }
88
+
89
89
  on('before_tag_creation') {
90
- version_changes = "## #{new_version} - #{Time.now.strftime('%d/%m/%Y')}\n"
91
- exit unless confirm("Create a new release?\n" \
92
- "#{version_changes}"
90
+
91
+ version_changes = ""
92
+ bitbucket_changes = sh(
93
+ %q#git log --oneline --decorate | grep -B 100 -m 1 "tag:" | grep "pull request" | awk '{print $1}' | xargs git show --format='%b' | grep -v Approved | grep -v "^$" | grep -E "^[[:space:]]*\[.*\]" | sed 's/^[[:space:]]*\(.*\)/ * \1/'#, output: false
94
+ ).output
95
+ version_changes = bitbucket_changes
96
+
97
+
98
+ puts "---------------------------"
99
+ version_changes = "## #{new_version} - #{Time.now.strftime('%d/%m/%Y')}\n#{version_changes}\n"
100
+ exit unless confirm("Create new Realease?\n" \
101
+ "---------------------------\n" \
102
+ "#{version_changes}" \
103
+ "---------------------------\n"
93
104
  )
94
105
 
106
+ # CHANGELOG
95
107
  file('CHANGELOG.md').prepend(version_changes)
96
108
  git('add CHANGELOG.md')
109
+
110
+ # Uncomment to update the version in other files, like package.json
111
+ # file('package.json').replace(/"(\d+)\.(\d+)\.(\d+)(-?.*)"/, %Q{"#{new_version}"})
112
+ # git('add package.json')
113
+
97
114
  git('commit -m "Updates CHANGELOG"')
98
115
  }
99
116
 
@@ -103,21 +120,31 @@ context(branch('master')) {
103
120
  }
104
121
  }
105
122
 
106
- context(branch('qa')) {
123
+ context(branch('staging')) {
107
124
  before_command('tag_up') {
125
+ git!('pull origin staging')
108
126
  command_options.add(pre_release: 'rc')
109
127
  }
110
128
 
129
+ on('before_tag_creation') {
130
+ # file('package.json').replace(/"(\d+)\.(\d+)\.(\d+)(-?.*)"/, %Q{"#{new_version}"})
131
+ # git('add package.json')
132
+
133
+ git('commit -m "Release QA"')
134
+ git('commit --allow-empty -m "Staging Release"')
135
+ }
136
+
111
137
  after_command('tag_up') {
112
- file('releases.log').append(new_version.to_s)
138
+ git('push --tags')
139
+ git('push origin staging')
113
140
  }
114
141
  }
115
142
 
116
- context(branch(/feature.+/)) {
117
- error "Can't create tags in feature branchs"
143
+ # Block tag creation in other branchs
144
+ context(!branch('master', 'staging')) {
145
+ error "Tags only can be created in master or staging branch"
118
146
  exit
119
147
  }
120
-
121
148
  ```
122
149
 
123
150
  #### Verto Syntax
data/exe/verto CHANGED
@@ -8,6 +8,8 @@ begin
8
8
  Verto::DSL.load_file(vertofile_path) if File.exists?(vertofile_path)
9
9
 
10
10
  Verto::MainCommand.start(ARGV)
11
+
12
+ # TODO: Improve error Message Handling
11
13
  rescue Verto::ExitError => ex
12
14
  Verto.stderr.puts ex.message
13
15
  Verto.stderr.puts 'Exiting Verto...'
@@ -2,5 +2,27 @@ module Verto
2
2
  class MainCommand < BaseCommand
3
3
  desc "tag SUBCOMMAND ...ARGS", "manage the repository tags"
4
4
  subcommand 'tag', Verto::TagCommand
5
+
6
+ desc "init", "Initialize a Vertofile in your repository"
7
+
8
+ option :path, type: :string, default: nil
9
+ def init
10
+ path = options[:path] || Verto.config.project.path
11
+
12
+ validate_current_vertofile!(path)
13
+
14
+ Template.render('Vertofile', to: path)
15
+ end
16
+
17
+ private
18
+
19
+ def validate_current_vertofile!(path)
20
+ command_error!(
21
+ <<~ERROR
22
+ Project already have a Vertofile.
23
+ If you want to generate a new with verto init, delete the current one with: `rm Vertofile`
24
+ ERROR
25
+ ) if Pathname.new(path).join('Vertofile').exist?
26
+ end
5
27
  end
6
28
  end
@@ -3,10 +3,18 @@ module Verto
3
3
  class Interpreter
4
4
  include DSL::Syntax
5
5
 
6
+ # TODO: Wrap stacktrace
7
+ Error = Class.new(Verto::ExitError)
8
+
6
9
  def evaluate(vertofile_content=nil, attributes: {}, &block)
7
10
  with_attributes(attributes) do
8
11
  vertofile_content ? instance_eval(vertofile_content) : instance_eval(&block)
9
12
  end
13
+
14
+ rescue StandardError => error
15
+ raise error if error.is_a?(Verto::ExitError)
16
+
17
+ raise Error, error.message
10
18
  end
11
19
 
12
20
  private
@@ -27,7 +27,7 @@ module Verto
27
27
  end
28
28
 
29
29
  def current_branch
30
- git('rev-parse --abbrev-ref HEAD', output: false).output.chomp.strip
30
+ @current_branch ||= git('rev-parse --abbrev-ref HEAD', output: false).output.chomp.strip
31
31
  end
32
32
 
33
33
  def branch(*branch_names)
@@ -46,6 +46,10 @@ module Verto
46
46
  sh("git #{subcommand}", output: output)
47
47
  end
48
48
 
49
+ def git!(subcommand, output: :from_config)
50
+ sh!("git #{subcommand}", output: output)
51
+ end
52
+
49
53
  def sh(command, output: :from_config)
50
54
  command_executor(output: output).run command
51
55
  end
data/lib/verto/dsl.rb CHANGED
@@ -9,5 +9,9 @@ module Verto
9
9
  def self.interpreter
10
10
  @interpreter ||= Interpreter.new
11
11
  end
12
+
13
+ def self.reset_interpreter!
14
+ @interpreter = nil
15
+ end
12
16
  end
13
17
  end
@@ -1,126 +1,5 @@
1
1
  module Verto
2
- class SemanticVersion
3
- include Comparable
4
-
5
- REGEXP = /(\d+)\.(\d+)\.(\d+)(-?.*)/
6
-
7
- class PreRelease
8
- include Comparable
9
-
10
- REGEXP = /-?(.+)\.(\d+)/
11
-
12
- attr_accessor :name, :number
13
-
14
- def self.with(name:, number: Verto.config.pre_release.initial_number)
15
- instance = allocate
16
- instance.name = name
17
- instance.number = number
18
- instance
19
- end
20
-
21
- def initialize(pre_release, initial_number: Verto.config.pre_release.initial_number)
22
- name, number = pre_release.match(REGEXP)&.captures
23
-
24
- @initial_number = initial_number
25
- return if name.nil? && number.nil?
26
-
27
- @name = name
28
- @number = number ? number.to_i : initial_number
29
- end
30
-
31
- def up
32
- raise BlankPreRelease if blank?
33
-
34
- new_pre_release = self.dup
35
- new_pre_release.number = number ? number + 1 : @initial_number
36
- new_pre_release
37
- end
38
-
39
- def <=>(other)
40
- return -1 if present? && other.blank?
41
- return 1 if blank? && other.present?
42
- to_s <=> other.to_s
43
- end
44
-
45
- def blank?
46
- name.nil? && number.nil?
47
- end
48
-
49
- def present?
50
- !blank?
51
- end
52
-
53
- def to_s
54
- return '' if blank?
55
-
56
- "-#{@name}.#{@number}"
57
- end
58
- end
59
-
60
- attr_accessor :major, :minor, :patch, :pre_release
61
-
62
- def initialize(version, pre_release_initial_number: Verto.config.pre_release.initial_number)
63
- major, minor, patch, pre_release = version.match(REGEXP).captures
64
-
65
- @major = major.to_i
66
- @minor = minor.to_i
67
- @patch = patch.to_i
68
- @pre_release = PreRelease.new(pre_release)
69
-
70
- @pre_release_initial_number = pre_release_initial_number
71
- end
72
-
73
- def up(version_type)
74
- new_version = self.dup
75
-
76
- case version_type
77
- when :major
78
- new_version.major += 1
79
- new_version.minor = 0
80
- new_version.patch = 0
81
- new_version.pre_release.number = @pre_release_initial_number if pre_release?
82
- when :minor
83
- new_version.minor += 1
84
- new_version.patch = 0
85
- new_version.pre_release.number = @pre_release_initial_number if pre_release?
86
- when :patch
87
- new_version.patch += 1
88
- new_version.pre_release.number = @pre_release_initial_number if pre_release?
89
- when :pre_release
90
- new_version.pre_release = new_version.pre_release.up
91
- end
92
-
93
- new_version
94
- end
95
-
96
- def with_pre_release(name)
97
- new_version = self.dup
98
-
99
- return new_version if new_version.pre_release? && new_version.pre_release.name == name
100
-
101
- new_version.pre_release = PreRelease.with(name: name)
102
-
103
- new_version
104
- end
105
-
106
- def pre_release?
107
- pre_release.present?
108
- end
109
-
110
- def <=>(other)
111
- return 1 if major > other.major
112
- return 1 if major == other.major && minor > other.minor
113
- return 1 if major == other.major && minor == other.minor && patch > other.patch
114
- return 1 if major == other.major && minor == other.minor && patch == other.patch && pre_release > other.pre_release
115
- return 0 if major == other.major && minor == other.minor && patch == other.patch && pre_release == other.pre_release
116
-
117
- -1
118
- end
119
-
120
- def to_s
121
- version = "#{@major}.#{@minor}.#{@patch}"
122
- version << @pre_release.to_s if @pre_release
123
- version
124
- end
2
+ class SemanticVersion < Vseries::SemanticVersion
3
+ DEFAULT_PRE_RELEASE_INITIAL_NUMBER = Verto.config.pre_release.initial_number
125
4
  end
126
5
  end
@@ -0,0 +1,26 @@
1
+ module Verto
2
+ class Template
3
+ def self.render(template_name, to:)
4
+ new(template_name).render(to: to)
5
+ end
6
+
7
+ def initialize(template_name)
8
+ @template_name = template_name
9
+ end
10
+
11
+ def render(to:)
12
+ path = Pathname.new(to)
13
+ path.join(@template_name).write(template_content)
14
+ end
15
+
16
+ private
17
+
18
+ def template_content
19
+ @template_content = template_path.join(@template_name).read
20
+ end
21
+
22
+ def template_path
23
+ Verto.root_path.join('lib/verto/utils/templates')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ verto_version '0.4.0'
2
+
3
+ context(branch('master')) {
4
+ before_command('tag_up') {
5
+ git!('origin master')
6
+ command_options.add(filter: 'release_only')
7
+ }
8
+
9
+ on('before_tag_creation') {
10
+
11
+ version_changes = ""
12
+ # Uncomment to get Bitbucket Merged PRs Titles as changes to add in CHANGELOG.
13
+ # bitbucket_changes = sh(
14
+ # %q#git log --oneline --decorate | grep -B 100 -m 1 "tag:" | grep "pull request" | awk '{print $1}' | xargs git show --format='%b' | grep -v Approved | grep -v "^$" | grep -E "^[[:space:]]*\[.*\]" | sed 's/^[[:space:]]*\(.*\)/ * \1/'#, output: false
15
+ # ).output
16
+ # version_changes = bitbucket_changes
17
+
18
+
19
+ puts "---------------------------"
20
+ version_changes = "## #{new_version} - #{Time.now.strftime('%d/%m/%Y')}\n#{version_changes}\n"
21
+ exit unless confirm("Create new Realease?\n" \
22
+ "---------------------------\n" \
23
+ "#{version_changes}" \
24
+ "---------------------------\n"
25
+ )
26
+
27
+ # CHANGELOG
28
+ file('CHANGELOG.md').prepend(version_changes)
29
+ git('add CHANGELOG.md')
30
+
31
+ # Uncomment to update the version in other files, like package.json
32
+ # file('package.json').replace(/"(\d+)\.(\d+)\.(\d+)(-?.*)"/, %Q{"#{new_version}"})
33
+ # git('add package.json')
34
+
35
+ git('commit -m "Updates CHANGELOG"')
36
+ }
37
+
38
+ after_command('tag_up') {
39
+ git('push --tags')
40
+ git('push origin master')
41
+ }
42
+ }
43
+
44
+ # Uncomment to get a specific pre_release proccess, like a staging or qa branch
45
+ # context(branch('staging')) {
46
+ # before_command('tag_up') {
47
+ # git!('pull origin staging')
48
+ # command_options.add(pre_release: 'rc')
49
+ # }
50
+ #
51
+ # on('before_tag_creation') {
52
+ # file('package.json').replace(/"(\d+)\.(\d+)\.(\d+)(-?.*)"/, %Q{"#{new_version}"}) # Atualiza versão do package.json
53
+ # git('add package.json')
54
+ # git('commit --allow-empty -m "Staging Release"')
55
+ # }
56
+
57
+ # after_command('tag_up') {
58
+ # git('push --tags')
59
+ # git('push origin staging')
60
+ # }
61
+ #}
62
+
63
+ # Uncomment to block tag creation in other branchs
64
+ #context(!branch('master', 'staging')) {
65
+ # error "Tags only can be created in master or staging branch"
66
+ # exit
67
+ #}
data/lib/verto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Verto
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/verto.rb CHANGED
@@ -2,6 +2,7 @@ require "thor"
2
2
  require "dry-container"
3
3
  require "dry-configurable"
4
4
  require "dry-auto_inject"
5
+ require "vseries"
5
6
  require "pathname"
6
7
 
7
8
  require "verto/version"
@@ -73,6 +74,7 @@ end
73
74
  require "verto/utils/semantic_version.rb"
74
75
  require "verto/utils/system_command_executor"
75
76
  require "verto/utils/tag_filter"
77
+ require "verto/utils/template"
76
78
  require "verto/dsl"
77
79
  require "verto/dsl/syntax"
78
80
  require "verto/dsl/interpreter"
data/verto.gemspec CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "dry-configurable", "~> 0.8"
31
31
  spec.add_dependency "dry-container", "~> 0.7"
32
32
  spec.add_dependency "dry-auto_inject", "~> 0.7"
33
+ spec.add_dependency "vseries", "~> 0.1"
33
34
 
34
35
  spec.add_development_dependency "byebug"
35
36
  spec.add_development_dependency "bundler", "~> 2.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Atkinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-24 00:00:00.000000000 Z
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vseries
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: byebug
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -172,6 +186,8 @@ files:
172
186
  - lib/verto/utils/semantic_version.rb
173
187
  - lib/verto/utils/system_command_executor.rb
174
188
  - lib/verto/utils/tag_filter.rb
189
+ - lib/verto/utils/template.rb
190
+ - lib/verto/utils/templates/Vertofile
175
191
  - lib/verto/version.rb
176
192
  - verto.gemspec
177
193
  homepage: https://github.com/catks/verto