renuo-bin-check 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +33 -0
  3. data/.editorconfig +20 -0
  4. data/.gitignore +9 -0
  5. data/.reek +18 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +26 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +32 -0
  10. data/CHANGELOG.md +36 -0
  11. data/CODE_OF_CONDUCT.md +13 -0
  12. data/CONTRIBUTING.md +41 -0
  13. data/Gemfile +3 -0
  14. data/LICENSE +22 -0
  15. data/README.md +142 -0
  16. data/Rakefile +7 -0
  17. data/bin/check +66 -0
  18. data/bin/setup +61 -0
  19. data/lib/renuo-bin-check.rb +8 -0
  20. data/lib/renuo_bin_check/cacher.rb +46 -0
  21. data/lib/renuo_bin_check/default_scripts/default_rails.rb +160 -0
  22. data/lib/renuo_bin_check/initializer.rb +21 -0
  23. data/lib/renuo_bin_check/master_thread.rb +42 -0
  24. data/lib/renuo_bin_check/printer.rb +15 -0
  25. data/lib/renuo_bin_check/result.rb +10 -0
  26. data/lib/renuo_bin_check/script_config.rb +61 -0
  27. data/lib/renuo_bin_check/servant_thread.rb +43 -0
  28. data/lib/renuo_bin_check/version.rb +4 -0
  29. data/renuo-bin-check.gemspec +35 -0
  30. data/spec/code_climate.rb +0 -0
  31. data/spec/code_climate.travis.rb +4 -0
  32. data/spec/factories/cacher.rb +16 -0
  33. data/spec/factories/result.rb +29 -0
  34. data/spec/factories/script_config.rb +41 -0
  35. data/spec/integration/initializer_spec.rb +209 -0
  36. data/spec/renuo/bin-check/cacher_spec.rb +51 -0
  37. data/spec/renuo/bin-check/initializer_spec.rb +23 -0
  38. data/spec/renuo/bin-check/master_thread_spec.rb +46 -0
  39. data/spec/renuo/bin-check/printer_spec.rb +25 -0
  40. data/spec/renuo/bin-check/result_spec.rb +18 -0
  41. data/spec/renuo/bin-check/script_config_spec.rb +69 -0
  42. data/spec/renuo/bin-check/servant_thread_spec.rb +97 -0
  43. data/spec/spec-files/file1 +1 -0
  44. data/spec/spec-files/file2 +1 -0
  45. data/spec/spec-files/file2_copy +1 -0
  46. data/spec/spec-files/test_script_exit0 +5 -0
  47. data/spec/spec-files/test_script_exit1 +5 -0
  48. data/spec/spec-files/test_script_exit1_no_error_output +3 -0
  49. data/spec/spec-files/test_script_sleep1 +2 -0
  50. data/spec/spec-files/test_script_sleep2 +2 -0
  51. data/spec/spec_helper.rb +35 -0
  52. metadata +288 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 202e3b412e3df80b06111b7b2b2258216bb6d787
4
+ data.tar.gz: 6e5b397dbb112bd0815246f5f87b86f4f8d42a01
5
+ SHA512:
6
+ metadata.gz: 8370dcb55c014cc6037104c61a5075393e1ac886ca6b886a81860d4801ced4c4d763e26c1558124cacf7e80001c3e78b1bb02913be071430b7cd47b3f0177a46
7
+ data.tar.gz: e204c67f5f9b2d2a5914f1da1aba397fe12228f24d16b1210ee1ca99840eb785223848e812632bb01a6d542e46afcb1dfe1161f069ce32cf67df11d7e68c993d
data/.codeclimate.yml ADDED
@@ -0,0 +1,33 @@
1
+ ---
2
+ engines:
3
+ brakeman:
4
+ enabled: true
5
+ bundler-audit:
6
+ enabled: true
7
+ duplication:
8
+ enabled: true
9
+ config:
10
+ languages:
11
+ - ruby
12
+ - javascript
13
+ - python
14
+ - php
15
+ fixme:
16
+ enabled: true
17
+ rubocop:
18
+ enabled: true
19
+ ratings:
20
+ paths:
21
+ - Gemfile.lock
22
+ - "**.erb"
23
+ - "**.haml"
24
+ - "**.rb"
25
+ - "**.rhtml"
26
+ - "**.slim"
27
+ - "**.inc"
28
+ - "**.js"
29
+ - "**.jsx"
30
+ - "**.module"
31
+ - "**.php"
32
+ - "**.py"
33
+ exclude_paths:- spec/
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ # Change these settings to your own preference
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ # We recommend you to keep these unchanged
14
+ end_of_line = lf
15
+ charset = utf-8
16
+ trim_trailing_whitespace = true
17
+ insert_final_newline = true
18
+
19
+ [*.md]
20
+ trim_trailing_whitespace = false
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.reek ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ IrresponsibleModule:
3
+ enabled: false
4
+ Attribute:
5
+ enabled: false
6
+ "app/helpers":
7
+ UtilityFunction:
8
+ enabled: false
9
+
10
+ exclude_paths:
11
+ - tmp
12
+ - spec
13
+ - vendor
14
+ - log
15
+ - coverage
16
+ - config
17
+ - bin
18
+ - db/migrate
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ Rails:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/NonNilCheck:
11
+ IncludeSemanticChanges: true
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ AllCops:
17
+ TargetRubyVersion: 2.3
18
+ Include:
19
+ - '**/Rakefile'
20
+ - '**/config.ru'
21
+ Exclude:
22
+ - 'bin/**/*'
23
+ - 'log/**/*'
24
+ - 'tmp/**/*'
25
+ - 'vendor/bundle/**/*'
26
+ - 'lib/renuo-bin-check.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ addons:
6
+ apt:
7
+ packages:
8
+ - zsh
9
+ postgresql: '9.4'
10
+ code_climate:
11
+ repo_token: c578db3d0b7d0bc01f2331b4027f54fbc0de43ede5a4c93646bf4957d3c1d962
12
+ services:
13
+ - postgresql
14
+ bundler_args: --jobs=3 --retry=3
15
+ cache:
16
+ bundler: true
17
+ apt: true
18
+ directories:
19
+ - coverage
20
+ - node_modules
21
+ before_install:
22
+ - export TZ=Europe/Zurich
23
+ before_script:
24
+ - export DISPLAY=:99.0
25
+ - sh -e /etc/init.d/xvfb start
26
+ - cp spec/code_climate.travis.rb spec/code_climate.rb
27
+ # if you need tsd - echo {\"token\":\"$TSDRC_TOKEN\"} > .tsdrc
28
+ script: bin/setup
29
+ notifications:
30
+ email:
31
+ on_success: change
32
+ on_failure: always
data/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ ## Version 0.0.0
2
+
3
+ First release after 10 days of planning and developing. Main functionality is implemented.
4
+ There is a known bug and it is not recommanded to use this version.
5
+
6
+ ## Version 0.1.0
7
+
8
+ This release should make it possible to actually use the Gem:
9
+
10
+ * known Bugs are fixed
11
+
12
+ * New feature: Results can be reversed
13
+ * mark the script you configure as reversed if you want
14
+ * Output will be Error-Output
15
+ * Error-Output will be Output
16
+ * Exit code > 0 will be 0
17
+ * Exit code 0 will be 1
18
+
19
+
20
+
21
+ ## Version 0.2.0
22
+
23
+ In this release are more features implemented and the Gem is available in rubygems.org:
24
+
25
+ * gem is generated and available on rubygems.org
26
+
27
+ ### New Features
28
+
29
+ * Output will be shown if the Error-Ouput is empty, even though the Script failed.
30
+ This was implemented as many Scripts use the Standard-Output for Outputs even if they fail.
31
+
32
+ * Standard-Output can be appended or overridden
33
+
34
+ * Error-Output can be appended or overridden
35
+
36
+ * Default-Script for faster Configuration of a bin/check in rails applications
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,41 @@
1
+ # Contributing
2
+
3
+ ### We love pull requests. Here's a quick guide.
4
+
5
+ Fork, then clone the repo:
6
+ ```
7
+ git clone git@github.com:your-username/renuo-bin-check.git
8
+ ```
9
+
10
+ Set up your machine:
11
+ ```
12
+ git checkout -b your-branch-name
13
+ bin/setup
14
+ ```
15
+
16
+ Make sure the tests pass:
17
+ ```
18
+ bin/check
19
+ ```
20
+
21
+ Make your change. Add tests for your change. Make the tests pass:
22
+ ```
23
+ bin/check
24
+ ```
25
+
26
+ Push to your fork and [submit a pull request][pr].
27
+ ```
28
+ git push origin your-branch-name
29
+ ```
30
+
31
+ [pr]: https://github.com/renuo/renuo-bin-check/compare/
32
+
33
+ At this point you're waiting on us. We like to at least comment on pull requests within three business days
34
+ (and, typically, one business day). We may suggest some changes or improvements or alternatives.
35
+
36
+ Some things that will increase the chance that your pull request is accepted:
37
+
38
+ * Write tests.
39
+ * Write a [good commit message][commit].
40
+
41
+ [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Renuo GmbH
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,142 @@
1
+ [![Build Status](https://travis-ci.org/renuo/renuo-bin-check.svg?branch=master)](https://travis-ci.org/renuo/renuo-bin-check) [![Build Status](https://travis-ci.org/renuo/renuo-bin-check.svg?branch=develop)](https://travis-ci.org/renuo/renuo-bin-check) [![Build Status](https://travis-ci.org/renuo/renuo-bin-check.svg?branch=testing)](https://travis-ci.org/renuo/renuo-bin-check) [![Code Climate](https://codeclimate.com/github/renuo/renuo-bin-check/badges/gpa.svg)](https://codeclimate.com/github/renuo/renuo-bin-check) [![Issue Count](https://codeclimate.com/github/renuo/renuo-bin-check/badges/issue_count.svg)](https://codeclimate.com/github/renuo/renuo-bin-check) [![Test Coverage](https://codeclimate.com/github/renuo/renuo-bin-check/badges/coverage.svg)](https://codeclimate.com/github/renuo/renuo-bin-check/coverage)
2
+ # renuo-bin-check
3
+
4
+ ## Setup
5
+
6
+ ```
7
+ git clone git@github.com:renuo/renuo-bin-check.git
8
+ cd renuo-bin-check
9
+ bin/setup
10
+ ```
11
+
12
+ ## Run Tests
13
+
14
+ The following script will run rspec, rubocop, reek, scanner for debugging outputs and a scanner for TODOs
15
+
16
+ ```
17
+ bin/check
18
+ ```
19
+
20
+ Run automated tests only with: `rspec`
21
+
22
+ Run Lining only: `rubocop`
23
+
24
+ Run Code Smell detector only: `reek``
25
+
26
+ ## How To Use renuo-bin-check
27
+
28
+ Install renuo-bin-check locally: see Setup
29
+
30
+ Add renuo-bin-check to your Gemfile:
31
+
32
+ ```rb
33
+ gem 'renuo-bin-check', path: '<path-to-renuo-bin-check>'
34
+ ```
35
+
36
+ Create a file at any place you want. Usually it would be called bin/check though.
37
+
38
+ You can now configure your scripts like that:
39
+
40
+ ```rb
41
+ # Initialize bin-check
42
+ require 'renuo-bin-check'
43
+
44
+ bin_check = RenuoBinCheck::Initializer.new
45
+
46
+ # add a script, do this for as many scripts as you would like to run
47
+ bin_check.check do |config|
48
+ config.command "<a one line command or a path to a script>"
49
+ config.name "<name-of-script>"
50
+ config.files ['<path-to-file-1>', '<path-to-file-2>']
51
+ config.reversed_exit <true or false>
52
+ end
53
+
54
+ #run everything
55
+ bin_check.run
56
+ ```
57
+
58
+ ### Options
59
+
60
+ #### command
61
+
62
+ This option is required. It is either a one-liner such as `ls -al` or a path to a script, that will be runned.
63
+ If command is not configured, the program will raise a RuntimeError.
64
+
65
+ #### name
66
+
67
+ This option is optional. It makes it possible to configure the name of the script.
68
+ It will be used as folder name in the cache.
69
+
70
+ If it is not set, the hashed command will be used as folder name in the cache.
71
+
72
+ Attention: If you set the same name twice, it won't raise an error,
73
+ but it can cause unexpected behaviour, hence it is not recommanded to do so.
74
+
75
+ #### files
76
+
77
+ This option is optional. If configured the script output will be cached. You need to list all files in array form,
78
+ which influence the outcome of the configured script.
79
+
80
+ Even though this option is optional, it is recommended to set it, as it can make a run much faster.
81
+
82
+ #### success_message
83
+
84
+ This option is optional. You can use it to override the standard output of a script or to append a further output.
85
+
86
+ If you want to override it just write the message, that you want to be shown. If you want to append a message, start
87
+ your message with a ```+```.
88
+
89
+ #### error_message
90
+
91
+ This option is optional. You can use it to override the error output of a script or to append a further output.
92
+
93
+ If you want to override it just write the message, that you want to be shown. If you want to append a message, start
94
+ your message with a ```+```.
95
+
96
+ #### reversed_exit
97
+
98
+ This option is optional. You can set it truthy or falsey. if not set it's automatically set falsey.
99
+
100
+ If set to truthy, the output of the configured script will be reversed. Which means:
101
+ * Error-Outputs will be Outputs
102
+ * Outputs will be Error-Output
103
+ * Exit Code of 0 will be 1
104
+ * Exit Code of not-0 will be 0
105
+
106
+ An example where this option is used, is the command that searches for TODOs.
107
+ The script should fail though if something is found and not if nothing is found.
108
+
109
+ ### Example
110
+
111
+ The following example configures a script that looks for TODOs in a project.
112
+ The configuration options can be called in any order.
113
+
114
+ ```rb
115
+ bin_check.check do |config|
116
+ config.command "grep --exclude-dir='app/assets/typings/**' -i -r 'TODO'"\
117
+ "app spec config db Rakefile README.md Gemfile"
118
+ config.name "todo-grepper"
119
+ config.files ['app/**/*', 'spec/**/*', 'config/**/*', 'db/**/*', 'Rakefile', 'README.md', 'Gemfile']
120
+ config.success_message "No TODO was found :)"
121
+ config.error_message "+TODO found! Please get rid of them"
122
+ config.reversed_exit true
123
+ end
124
+ ```
125
+
126
+ ## Contribute
127
+
128
+ If you would like to contribute, you're very welcome to.
129
+
130
+ Please follow these instructions:
131
+
132
+ https://github.com/renuo/renuo-bin-check/blob/develop/CONTRIBUTING.md
133
+
134
+ https://github.com/renuo/renuo-bin-check/blob/develop/CODE_OF_CONDUCT.md
135
+
136
+ ## License
137
+
138
+ Copyright (c) 2016 Renuo GmbH
139
+
140
+ MIT License
141
+
142
+ Read more: https://github.com/renuo/renuo-bin-check/blob/develop/LICENSE
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
data/bin/check ADDED
@@ -0,0 +1,66 @@
1
+ #!/bin/zsh
2
+
3
+ source ~/.zshrc
4
+
5
+ grep 'rack-mini-profiler' Gemfile.lock >> /dev/null
6
+ if [ $? -eq 0 ]; then
7
+ echo 'rack-mini-profiler detected in Gemfile.lock.'
8
+ echo 'Please remove rack-mini-profiler from your Gemfile(.local), run bundle and commit again, commit aborted'
9
+ exit 1
10
+ fi
11
+
12
+ grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r 'TODO' lib spec Gemfile
13
+ if [ $? -eq 0 ]; then
14
+ echo 'TODOs found. Please fix them and try again, commit aborted'
15
+ exit 1
16
+ fi
17
+
18
+ grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r 'console.log' lib spec
19
+ if [ $? -eq 0 ]; then
20
+ echo 'console.log found. Please fix them and try again, commit aborted'
21
+ exit 1
22
+ fi
23
+
24
+ grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' puts ' lib spec
25
+ if [ $? -eq 0 ]; then
26
+ echo 'puts found. Please fix them and try again, commit aborted'
27
+ exit 1
28
+ fi
29
+
30
+ grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' puts(' lib spec
31
+ if [ $? -eq 0 ]; then
32
+ echo 'puts found. Please fix them and try again, commit aborted'
33
+ exit 1
34
+ fi
35
+
36
+ grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' p ' lib spec
37
+ if [ $? -eq 0 ]; then
38
+ echo 'p found. Please fix them and try again, commit aborted'
39
+ exit 1
40
+ fi
41
+
42
+ grep --exclude-dir="lib/renuo_bin_check/default_scripts" -i -r ' p(' lib spec
43
+ if [ $? -eq 0 ]; then
44
+ echo 'p found. Please fix them and try again, commit aborted'
45
+ exit 1
46
+ fi
47
+
48
+ bundle exec rubocop -D -c .rubocop.yml --fail-fast
49
+ if [ ! $? -eq 0 ]; then
50
+ echo 'rubocop detected issues!'
51
+ bundle exec rubocop -a -D -c .rubocop.yml
52
+ echo 'Tried to auto correct the issues, but must be reviewed manually, commit aborted'
53
+ exit 1
54
+ fi
55
+
56
+ bundle exec reek
57
+ if [ ! $? -eq 0 ]; then
58
+ echo 'reek detected code smells, commit aborted'
59
+ exit 1
60
+ fi
61
+
62
+ bundle exec rspec
63
+ if [ ! $? -eq 0 ]; then
64
+ echo 'rspec did not run successfully, commit aborted'
65
+ exit 1
66
+ fi