trent 0.1.0 → 0.2.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
- SHA1:
3
- metadata.gz: bd76ca7ec62253cf51678cf861497c9b7e994d2e
4
- data.tar.gz: 494bf1d60e7bed0be13746a83102359fe5e1aa0d
2
+ SHA256:
3
+ metadata.gz: ae2e50c64156a238d44cea8d8dd2f75d065a67181c83c4c8393b977185a780dc
4
+ data.tar.gz: 030376142fdf94609f35462eeaf57c6aeae1c3613c2cacaaa3a0b32090a54fea
5
5
  SHA512:
6
- metadata.gz: aedc27c0447919ba248ed0b883a2dc5d7f327422be206894dfdba9de9abdece1799e4096bd174cf1482bcb253725d5a4de06ffc26bdf9f2e763a4f89f48870c7
7
- data.tar.gz: 618011c76aee3f36ae61019f7614de36145db8f1ce836d7bf1f30e1f4bf9dce772bbcf0577e5d3349f58969e56a0f0b4f09b63bee88514c89bf3f782c42f1f79
6
+ metadata.gz: a04dada57e421b6c9b832dbed4c8f096448dcc89a61afb0da3f0086f2f865816b90e4d6b1f4be9be1d506a47fcf629a64a6bdd1c194407440476c1e145e7b622
7
+ data.tar.gz: f106b7156d6a8188e58ee7b802b411fc7a297e9dcf52dabcc562234d6710d5e3d91b95e6be45d702051ea2e3ee2e1d559d4d9eb7a6d25b5e95a1054e53c94285
data/CHANGELOG.md CHANGED
@@ -7,3 +7,13 @@ First release!
7
7
  - Ability to run remote ssh commands on Travis CI builds.
8
8
  - Ability to send a comment on the GitHub pull request for the Travis CI build.
9
9
  - Trent only works with Travis-CI at this time.
10
+
11
+ ### [0.2.0] 2018-08-08
12
+
13
+ Add `path` function to Trent to perform string replacing in your commands for you.
14
+
15
+ ### Added
16
+ - Add `path` function to Trent to perform string replacing in your commands for you.
17
+
18
+ ### Changed
19
+ - Each time you run `sh()` or `ssh()` commands, your command will perform a string replace with all commands you add to `path()`.
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # Trent
1
+ [![Gem](https://img.shields.io/gem/v/formatador.svg)](https://rubygems.org/gems/trent)
2
+ [![Travis (.com)](https://travis-ci.com/levibostian/Trent.svg?branch=development)](https://travis-ci.com/levibostian/Trent)
3
+ [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/levibostian/trent)
4
+
5
+ # Trent
2
6
 
3
7
  Run and debug bash commands on Travis-CI much easier.
4
8
 
@@ -34,6 +38,10 @@ This makes it difficult to debug when things go wrong. Knowing what commands wer
34
38
 
35
39
  ```
36
40
  $> bundle add trent
41
+
42
+ or...
43
+
44
+ $> gem install trent
37
45
  ```
38
46
 
39
47
  * Create a new Ruby file for the scripts you want to run and create an instance of `Trent`.
@@ -79,6 +87,9 @@ Let's break this down.
79
87
  ```ruby
80
88
  # Allow a command to fail and not fail the Travis build.
81
89
  ci.sh("false", :fail_non_success => false)
90
+
91
+ # Perform a string replace on your commands where "docker-compose" will be replaced with "/opt/bin/docker-compose"
92
+ ci.path("docker-compose", "/opt/bin/docker-compose")
82
93
  ```
83
94
 
84
95
  # Run remote SSH shell commmands
@@ -137,6 +148,10 @@ ci.config_github('wfoweifwoeifjweoijwefowefweoif')
137
148
  ci.github.comment("Tests pass!") # Send comment to pull request for the Travis build. The pull request information is automatically retrieved from the Travis virtual machine the build is running on.
138
149
  ```
139
150
 
151
+ # Docs
152
+
153
+ Trent documentation is hosted [here](https://www.rubydoc.info/gems/trent/0.1.0).
154
+
140
155
  # Advanced Trent configuration
141
156
 
142
157
  ```ruby
@@ -160,8 +175,8 @@ Trent is open for pull requests. Check out the [list of issues](https://github.c
160
175
  ### Building Trent
161
176
 
162
177
  ```
163
- $> gem build trent.gemspec
164
- $> gem install --dev ./trent-X.X.X.gem
178
+ $> bundle install --path vendor/bundle
179
+ $> bundle exec rake init
165
180
  ```
166
181
 
167
182
  This will install all dependencies including for development. You are ready to write some code.
@@ -169,14 +184,13 @@ This will install all dependencies including for development. You are ready to w
169
184
  While working on Trent, make sure to lint it:
170
185
 
171
186
  ```
172
- $> rubocop --auto-correct
187
+ $> bundle exec rake lint
173
188
  ```
174
189
 
175
190
  To test out Trent on your machine:
176
191
 
177
192
  ```
178
- $> gem build trent.gemspec
179
- $> gem install ./trent-X.X.X.gem
193
+ $> bundle exec rake build
180
194
  ```
181
195
 
182
196
  Then, you can use it on your own machine using `require 'trent'` in your ruby scripts.
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/trent'
4
+
5
+ ci = Trent.new
6
+ ci.config_github(ENV['DANGER_GITHUB_API_TOKEN'])
7
+
8
+ ci.sh('printf "%s\\n%s " "---" ":rubygems_api_key:" > ~/.gem/credentials')
9
+ ci.sh('printf $RUBYGEMS_KEY >> ~/.gem/credentials')
10
+ ci.sh('chmod 0600 ~/.gem/credentials')
11
+
12
+ ci.sh('bundle exec rake publish')
13
+
14
+ ci.github.comment("Success! Don't forget to create a git tag and git release.")
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Conventient methods when working with commands
4
+ class Command
5
+ # Takes a hash (paths) and replaces each occurance of the keys with the value within the "command" string.
6
+ # This is used when you have a "docker-compose ... up -d" command and you want to replace all occurances of "docker-compose" with "/opt/bin/docker-compose".
7
+ def self.path_replace(command, paths)
8
+ # I am doing command.split() instead of a simple `gsub()` because I need to replace *whole words* not substrings.
9
+ edited_command = []
10
+ command.split(' ').each do |command_phrase|
11
+ if paths.key? command_phrase
12
+ edited_command.push(paths[command_phrase])
13
+ else
14
+ edited_command.push(command_phrase)
15
+ end
16
+ end
17
+
18
+ edited_command.join(' ')
19
+ end
20
+ end
data/lib/command/sh/sh.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
2
4
 
3
5
  # Run bash commands locally on machine.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/ssh'
2
4
 
3
5
  # Run SSH commands remotely on a server.
data/lib/github/github.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
  require 'json'
3
5
  require_relative '../log'
@@ -21,6 +23,8 @@ class GitHub
21
23
  end
22
24
  end
23
25
 
26
+ private
27
+
24
28
  def comment_on_pull_request(message)
25
29
  puts "Commenting on GitHub pull request: #{ENV['TRAVIS_REPO_SLUG']}/#{ENV['TRAVIS_PULL_REQUEST']}"
26
30
  uri = URI("https://api.github.com/repos/#{ENV['TRAVIS_REPO_SLUG']}/issues/#{ENV['TRAVIS_PULL_REQUEST']}/comments")
data/lib/log.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'colorize'
2
4
 
3
5
  # Convenient class to log to console in certain ways
data/lib/trent.rb CHANGED
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'command/ssh/ssh'
2
4
  require 'github/github'
3
5
  require 'command/sh/sh'
4
6
  require 'colorize'
5
7
  require_relative './log'
8
+ require 'command/command'
6
9
 
7
10
  # Communicate with all of the Trent library with this class.
8
11
  class Trent
@@ -11,6 +14,8 @@ class Trent
11
14
 
12
15
  @color = color
13
16
  @sh = Sh.new
17
+
18
+ @paths = {}
14
19
  end
15
20
 
16
21
  # Configure how to run remote SSH commmands on server.
@@ -23,8 +28,18 @@ class Trent
23
28
  @github = GitHub.new(api_key)
24
29
  end
25
30
 
31
+ # While working with bash commands, some commands are not added to the path. That's annoying.
32
+ # Convenient method to assign a command to a path for replacing.
33
+ # Example:
34
+ # ci.path("docker-compose", "/opt/bin/docker-compose")
35
+ # Now, when you use ci.sh("docker-compose -f ... up -d"), it will run "/opt/bin/docker-compose -f ... up -d" instead.
36
+ def path(command, path)
37
+ @paths[command] = path
38
+ end
39
+
26
40
  ## Run ssh command
27
41
  def ssh(command, fail_non_success = true)
42
+ command = Command.path_replace(command, @paths)
28
43
  Log.fatal('You did not configure SSH yet.') unless @ssh
29
44
 
30
45
  puts command.colorize(@color)
@@ -37,6 +52,7 @@ class Trent
37
52
 
38
53
  # Run local bash command
39
54
  def sh(command, fail_non_success = true)
55
+ command = Command.path_replace(command, @paths)
40
56
  puts command.colorize(@color)
41
57
 
42
58
  result = @sh.run(command)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trent
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
  - Levi Bostian
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.58.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 12.3.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 12.3.1
55
69
  description: "I have been using Travis-CI for a few years to build, test, and deploy
56
70
  my apps. Bash is great, but using a higher level language for interacting with Travis
57
71
  and the build machine would be very beneficial. \n\n Trent is a convenient ruby
@@ -65,6 +79,8 @@ files:
65
79
  - CHANGELOG.md
66
80
  - LICENSE
67
81
  - README.md
82
+ - bin/gem-release.rb
83
+ - lib/command/command.rb
68
84
  - lib/command/sh/sh.rb
69
85
  - lib/command/ssh/ssh.rb
70
86
  - lib/github/github.rb
@@ -90,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
106
  version: '0'
91
107
  requirements: []
92
108
  rubyforge_project:
93
- rubygems_version: 2.5.2
109
+ rubygems_version: 2.7.7
94
110
  signing_key:
95
111
  specification_version: 4
96
112
  summary: Run and debug bash commands on Travis-CI much easier.