verto 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57720313b35dae31896c4cc8ed940487c14c6f268269474dcaf7a739eb31f371
4
- data.tar.gz: 37b947db3e863ba538e945eff7f02241f862b6d021b43223c9c95d28bf7df144
3
+ metadata.gz: ccba2d3e689dff838d612930a75a88c445f40dfb7a783179dee0fd8abdfe207a
4
+ data.tar.gz: d9ac8120dfba52e31efb8c40d8c3d057f499fd73ef69443430a61beb0aaa5a31
5
5
  SHA512:
6
- metadata.gz: e3791c56946d015d4199863331a836d661d159ceed0c817f80c169ee8ea71523a874b31a656be6df2fb7bf7671041ab2430dac4fcc08420292ee76e0fe826997
7
- data.tar.gz: dc69546ca9d8427bfe51610fd6444061d3356f840a6836fe81c275ad0bba5abe14592095b92be5bb719392e32de9678ecc9b85785d382084c22f8a2cd92f233a
6
+ metadata.gz: aedc4f24da4845fde6bd377f75a041dd6c6b683cb524a6e58843f80c12c18849d9844c665c65c51853186489f63e5527a8e5a5af310883f64c7b5bcbcdd329ec
7
+ data.tar.gz: 1557b99f71c2e81d69fb7e2c4dfd732bcdd4b86794e3ab71b65e17ce77e3683e593244ca2081fe2c23da08eff2088988ed514730c1322bc1fb5cc2c13fbd759a
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/Dockerfile ADDED
@@ -0,0 +1,43 @@
1
+ FROM ruby:2.6.5-alpine AS builder
2
+
3
+ ENV BUILD_PACKAGES build-base git
4
+
5
+ RUN mkdir /bundle
6
+
7
+ RUN apk update && \
8
+ apk upgrade && \
9
+ apk add $BUILD_PACKAGES && \
10
+ rm -rf /var/cache/apk/*
11
+
12
+ COPY verto.gemspec Gemfile Gemfile.lock ./
13
+
14
+ COPY lib/verto/version.rb lib/verto/version.rb
15
+
16
+ RUN gem install bundler -v 2.0.2
17
+
18
+ RUN bundle install
19
+
20
+ FROM ruby:2.6.5-alpine
21
+
22
+ ENV DEPENDENCIES git openssh-client
23
+
24
+ RUN apk update && \
25
+ apk upgrade && \
26
+ apk add $DEPENDENCIES && \
27
+ rm -rf /var/cache/apk/*
28
+
29
+ WORKDIR /usr/src/verto
30
+
31
+ COPY --from=builder /usr/local/bundle/ /usr/local/bundle
32
+
33
+ RUN gem install bundler -v 2.0.2
34
+
35
+ COPY . .
36
+
37
+ RUN chmod +x docker-entrypoint.sh
38
+
39
+ RUN rake install
40
+
41
+ WORKDIR /usr/src/project
42
+
43
+ ENTRYPOINT ["/usr/src/verto/docker-entrypoint.sh"]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- verto (0.1.0)
4
+ verto (0.2.0)
5
5
  dry-auto_inject (~> 0.6)
6
6
  dry-configurable (~> 0.8)
7
7
  dry-container (~> 0.7)
data/README.md CHANGED
@@ -4,15 +4,37 @@ Verto is a CLI to generate git tags (following the [Semantic Versioning](https:/
4
4
 
5
5
  ## Installation
6
6
 
7
+
8
+ ### Ruby Gem
7
9
  Verto is distributed as a ruby gem, to install run:
8
10
 
9
11
  ```
10
12
  $ gem install verto
11
13
  ```
12
14
 
15
+
16
+ ### Docker Image
17
+
18
+ You don't need to install verto in your machine, you can run verto via the docker image
19
+
20
+ To use verto in the same way that you use any other cli, you can set an alias in your `.bashrc`, `.zshrc`, etc:
21
+
22
+ ```
23
+ alias verto='docker run -v $(pwd):/usr/src/project -it catks/verto'
24
+ ```
25
+
26
+ If you want to use your ssh keys with verto container (for git push) you can set the alias sharing the ssh key file:
27
+
28
+ ```
29
+ 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'
30
+
31
+ ```
32
+
33
+ Now you can run any verto command! :)
34
+
13
35
  ## Usage
14
36
 
15
- Now you can run verto right out of the box without any configuration:
37
+ You can run verto right out of the box without any configuration:
16
38
 
17
39
  ```
18
40
  verto tag up --patch # Creates a new tag increasing the patch number
@@ -35,12 +57,12 @@ before { sh('echo "Creating Tag"') }
35
57
 
36
58
  context(branch('master')) {
37
59
  on('before_tag_creation') {
38
- versions_changes = "## #{new_version} - #{Time.now.strftime('%d/%m/%Y')}\n"
60
+ version_changes = "## #{new_version} - #{Time.now.strftime('%d/%m/%Y')}\n"
39
61
  exit unless confirm("Create a new release?\n" \
40
- "#{versions_changes}"
62
+ "#{version_changes}"
41
63
  )
42
64
 
43
- file('CHANGELOG.md').prepend(versions_changes)
65
+ file('CHANGELOG.md').prepend(version_changes)
44
66
  git('add CHANGELOG.md')
45
67
  git('commit -m "Updates CHANGELOG"')
46
68
  }
@@ -61,6 +83,10 @@ context(branch('qa')) {
61
83
  }
62
84
  }
63
85
 
86
+ context(branch(/feature.+/)) {
87
+ error "Can't create tags in feature branchs"
88
+ }
89
+
64
90
  ```
65
91
 
66
92
  #### Verto Syntax
@@ -71,7 +97,8 @@ context(branch('qa')) {
71
97
 
72
98
  1. Complete README.md description
73
99
  2. Add a configuration to enable, disable or specify the number of tags that a single commit can have(eg: only one release and one pre-release)
74
- 3. Enable the *sh* dsl output to be show as default
100
+ 3. Configure tag prefix (eg: 'v' to generate v0.1.0)
101
+ 4. Improve DSL Syntax Errors Messages(Ruby backtrace is printed currently)
75
102
 
76
103
  ## Contributing
77
104
 
data/Rakefile CHANGED
@@ -9,7 +9,9 @@ task :default => :spec
9
9
 
10
10
  desc 'Verto REPL'
11
11
  task :console do
12
- exec 'irb -r ./lib/verto -r ./spec/helpers/test_repo.rb'
12
+ require 'irb'
13
+ ARGV.clear
14
+ IRB.start
13
15
  end
14
16
 
15
17
  namespace :temp_repo do
@@ -20,6 +22,6 @@ namespace :temp_repo do
20
22
 
21
23
  desc 'clear the temp git repo'
22
24
  task :clear do
23
- TestRepo.new.clear
25
+ TestRepo.new.clear!
24
26
  end
25
27
  end
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
6
+ eval `ssh-agent -s` > /dev/null
7
+ ssh-add $SSH_PRIVATE_KEY 2> /dev/null
8
+ fi
9
+
10
+ exec verto "$@"
11
+
data/exe/verto CHANGED
@@ -4,6 +4,11 @@ require_relative '../lib/verto'
4
4
 
5
5
  vertofile_path = ENV['VERTOFILE_PATH'] || Pathname.new(Dir.pwd).join('Vertofile').to_s
6
6
 
7
- Verto::DSL.load_file(vertofile_path) if File.exists?(vertofile_path)
8
-
9
- Verto::MainCommand.start(ARGV)
7
+ begin
8
+ Verto::DSL.load_file(vertofile_path) if File.exists?(vertofile_path)
9
+
10
+ Verto::MainCommand.start(ARGV)
11
+ rescue Verto::ExitError
12
+ Verto.stderr.puts 'Exiting Verto...'
13
+ exit 1
14
+ end
@@ -7,7 +7,7 @@ module Verto
7
7
  private
8
8
 
9
9
  def command_error!(message)
10
- raise Thor::Error, message
10
+ raise Verto::CommandError, message
11
11
  end
12
12
 
13
13
  def options
@@ -10,7 +10,11 @@ module Verto
10
10
  end
11
11
 
12
12
  def branch(*branch_names)
13
- branch_names.map(&:to_s).include? current_branch
13
+ branch_names.any? do |branch|
14
+ return branch.match?(current_branch) if branch.is_a?(Regexp)
15
+
16
+ branch.to_s.include? current_branch
17
+ end
14
18
  end
15
19
 
16
20
  def context(condition, &block)
@@ -25,6 +29,10 @@ module Verto
25
29
  command_executor.run command
26
30
  end
27
31
 
32
+ def sh!(command)
33
+ raise Verto::ExitError unless sh(command).success?
34
+ end
35
+
28
36
  def command_options
29
37
  Verto.config.command_options
30
38
  end
@@ -61,6 +69,16 @@ module Verto
61
69
  shell_basic.yes?("#{text} (y/n)")
62
70
  end
63
71
 
72
+ def error(text)
73
+ stderr.puts text
74
+ end
75
+
76
+ def error!(text)
77
+ error(text)
78
+
79
+ raise Verto::ExitError
80
+ end
81
+
64
82
  private
65
83
 
66
84
  def command_executor
@@ -70,6 +88,10 @@ module Verto
70
88
  def shell_basic
71
89
  @shell_basic ||= Thor::Shell::Basic.new
72
90
  end
91
+
92
+ def stderr
93
+ Verto.stderr
94
+ end
73
95
  end
74
96
  end
75
97
  end
@@ -1,6 +1,6 @@
1
1
  module Verto
2
2
  class TagRepository
3
- include Verto.import[executor: 'system_command_executor']
3
+ include Verto.import[executor: 'system_command_executor_without_output']
4
4
 
5
5
  def latest(filter: nil)
6
6
  all(filter: filter).last
@@ -2,11 +2,11 @@ require 'open3'
2
2
 
3
3
  module Verto
4
4
  class SystemCommandExecutor
5
- include Verto.import['project.path']
5
+ include Verto.import['project.path', 'stdout', 'stderr']
6
6
 
7
7
  class Result < Struct.new(:output, :error, :result)
8
8
  def success?
9
- @result.success?
9
+ result.success?
10
10
  end
11
11
 
12
12
  def error?
@@ -16,19 +16,24 @@ module Verto
16
16
  Error = Class.new(StandardError)
17
17
 
18
18
  def run(command)
19
- Open3.popen3(command, chdir: path.to_s) do |stdin, stdout, stderr, wait_thread|
19
+ Open3.popen3(command, chdir: path.to_s) do |_, stdout, stderr, wait_thread|
20
20
  @output = stdout.read
21
21
  @error = stderr.read
22
22
  @result = wait_thread.value
23
23
  end
24
24
 
25
+ stdout << @output if stderr
26
+ stderr << @error if stderr
27
+
25
28
  Result.new(@output, @error, @result)
26
29
  end
27
30
 
28
31
  def run!(command)
29
- run(command)
32
+ result = run(command)
30
33
 
31
34
  raise Error, @error unless @error.empty?
35
+
36
+ result
32
37
  end
33
38
  end
34
39
  end
data/lib/verto/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Verto
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/verto.rb CHANGED
@@ -17,19 +17,42 @@ module Verto
17
17
  setting :path, './'
18
18
  end
19
19
 
20
+ setting :output do
21
+ setting :stdout_to, nil
22
+ setting :stderr_to, nil
23
+ end
24
+
20
25
  setting :hooks, []
21
26
  setting :command_options, Class.new(Hash) { alias_method :add, :merge! }.new
22
27
 
28
+ ExitError = Class.new(Thor::Error)
29
+ CommandError = Class.new(ExitError)
30
+
23
31
  def self.root_path
24
32
  Pathname.new File.expand_path(File.dirname(__FILE__) + '/..')
25
33
  end
26
34
 
35
+ def self.project_path
36
+ Pathname.new Verto.config.project.path
37
+ end
27
38
 
28
39
  def self.container
29
40
  @container ||= Dry::Container.new.tap do |container|
30
41
  container.register('system_command_executor') { SystemCommandExecutor.new }
42
+ container.register('system_command_executor_without_output') { SystemCommandExecutor.new(stdout: nil, stderr: nil) }
43
+
31
44
  container.register('tag_repository') { TagRepository.new }
32
45
 
46
+ container.register('stdout', memoize: true) do
47
+ stdout = Verto.config.output.stdout_to
48
+ stdout && Verto.project_path.join(stdout).open('a+') || $stdout
49
+ end
50
+
51
+ container.register('stderr', memoize: true) do
52
+ stderr = Verto.config.output.stderr_to
53
+ stderr && Verto.project_path.join(stderr).open('a+') || $stderr
54
+ end
55
+
33
56
  # TODO: Remove project.path from container
34
57
  container.namespace('project') do
35
58
  register('path') { Verto.config.project.path }
@@ -40,6 +63,10 @@ module Verto
40
63
  def self.import
41
64
  @import ||= Dry::AutoInject(container)
42
65
  end
66
+
67
+ def self.stderr
68
+ Verto.container.resolve('stderr')
69
+ end
43
70
  end
44
71
 
45
72
  require "verto/utils/semantic_version.rb"
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.1.0
4
+ version: 0.2.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-02-14 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -132,7 +132,9 @@ extra_rdoc_files: []
132
132
  files:
133
133
  - ".gitignore"
134
134
  - ".rspec"
135
+ - ".ruby-version"
135
136
  - ".travis.yml"
137
+ - Dockerfile
136
138
  - Gemfile
137
139
  - Gemfile.lock
138
140
  - LICENSE.txt
@@ -140,6 +142,7 @@ files:
140
142
  - Rakefile
141
143
  - bin/console
142
144
  - bin/setup
145
+ - docker-entrypoint.sh
143
146
  - exe/verto
144
147
  - lib/verto.rb
145
148
  - lib/verto/commands/base_command.rb