onceover-codequality 0.5.2 → 0.8.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: 9cc85533082f17d96152a3c59fc6348ea8be68b55042b6d1bb0f6cff652ef2a4
4
- data.tar.gz: 87de572b5cfa41d75e561b11b6203a8b08ea9697dc6b34b9c5c9c08eb62b48b3
3
+ metadata.gz: c942e82eac32f3f3c723d0ed967fab3744b69bacd15a9dc79dad592ecccdeb9e
4
+ data.tar.gz: 5eb8ae6bb4b184eb7f5ac0244785f2fac2116f3891cfd0439abafc7e4fb1e61f
5
5
  SHA512:
6
- metadata.gz: dc5f19fa30675b22d3dcfa22426160270cfa701daf5b5e42873308276850a069af0b6457b0b637d28bc071ed767c63b0c93910dfece1874e5a349c573409a568
7
- data.tar.gz: 3613935fb0d6dca40cd26275db0db1242bf796b3e820b67085e55157db4e8a2035b5b64c89ec539961e71890538cd3dc8fa7317131201d90c626350448340302
6
+ metadata.gz: dd9b554d0958919559c5eabf71d5ee50c7803aeaee7dc3374f07ab00deabbe0e0202a55b7dc4c981a71466bd92f8d474cdfd480023adbadf75485e426c2767d8
7
+ data.tar.gz: 2ff44b19c6783658a3871665de84b0108dc4f69bcb91487d508387b762a1975295083fff8608892905c8c90f226b2ec378b3b36122e2a0d1012b8eaffde5c27b
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
2
+ **/.yardoc
3
+ **/REFERENCE.md
4
+ /spec/testcase/**/doc
4
5
  /_yardoc/
5
6
  /coverage/
6
7
  /doc/
@@ -12,3 +13,4 @@
12
13
  .rspec_status
13
14
  /.idea
14
15
  *.gem
16
+
data/Gemfile.lock ADDED
@@ -0,0 +1,154 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ onceover-codequality (0.8.0)
5
+ onceover (~> 3)
6
+ puppet-lint (~> 2)
7
+ puppet-strings (~> 2)
8
+ puppet-syntax (~> 3)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ backticks (1.0.2)
14
+ blockenspiel (0.5.0)
15
+ colored (1.2)
16
+ colored2 (3.1.2)
17
+ concurrent-ruby (1.1.8)
18
+ cri (2.15.11)
19
+ deep_merge (1.2.1)
20
+ diff-lcs (1.3)
21
+ facter (4.0.51)
22
+ hocon (~> 1.3)
23
+ thor (>= 1.0.1, < 2.0)
24
+ faraday (0.17.4)
25
+ multipart-post (>= 1.2, < 3)
26
+ faraday_middleware (0.14.0)
27
+ faraday (>= 0.7.4, < 1.0)
28
+ fast_gettext (1.1.2)
29
+ gettext (3.2.9)
30
+ locale (>= 2.0.5)
31
+ text (>= 1.3.0)
32
+ gettext-setup (0.34)
33
+ fast_gettext (~> 1.1.0)
34
+ gettext (>= 3.0.2, < 3.3.0)
35
+ locale
36
+ git (1.8.1)
37
+ rchardet (~> 1.8)
38
+ hiera (3.6.0)
39
+ hocon (1.3.1)
40
+ little-plugger (1.1.4)
41
+ locale (2.1.3)
42
+ log4r (1.1.10)
43
+ logging (2.3.0)
44
+ little-plugger (~> 1.1)
45
+ multi_json (~> 1.14)
46
+ minitar (0.9)
47
+ mocha (1.12.0)
48
+ multi_json (1.15.0)
49
+ multipart-post (2.1.1)
50
+ onceover (3.19.1)
51
+ backticks (>= 1.0.2)
52
+ colored (~> 1.2)
53
+ cri (>= 2.6)
54
+ deep_merge (>= 1.0.0)
55
+ git
56
+ logging (>= 2.0.0)
57
+ multi_json (~> 1.10)
58
+ parallel_tests (>= 2.0.0)
59
+ puppet (>= 4.0)
60
+ puppetlabs_spec_helper (>= 0.4.0)
61
+ r10k (>= 2.1.0)
62
+ rake (>= 10.0.0)
63
+ rspec (>= 3.0.0)
64
+ rspec-puppet (>= 2.4.0)
65
+ rspec_junit_formatter (>= 0.2.0)
66
+ terminal-table (>= 1.8.0)
67
+ versionomy (>= 0.5.0)
68
+ parallel (1.20.1)
69
+ parallel_tests (3.4.0)
70
+ parallel
71
+ pathspec (0.2.1)
72
+ puppet (7.4.0)
73
+ concurrent-ruby (~> 1.0)
74
+ deep_merge (~> 1.0)
75
+ facter (> 2.0.1, < 5)
76
+ fast_gettext (~> 1.1)
77
+ hiera (>= 3.2.1, < 4)
78
+ locale (~> 2.1)
79
+ multi_json (~> 1.10)
80
+ puppet-resource_api (~> 1.5)
81
+ scanf (~> 1.0)
82
+ semantic_puppet (~> 1.0)
83
+ puppet-lint (2.4.2)
84
+ puppet-resource_api (1.8.13)
85
+ hocon (>= 1.0)
86
+ puppet-strings (2.6.0)
87
+ rgen
88
+ yard (~> 0.9.5)
89
+ puppet-syntax (3.1.0)
90
+ puppet (>= 5)
91
+ rake
92
+ puppet_forge (2.3.4)
93
+ faraday (>= 0.9.0, < 0.18.0, != 0.13.1)
94
+ faraday_middleware (>= 0.9.0, < 0.15.0)
95
+ gettext-setup (~> 0.11)
96
+ minitar
97
+ semantic_puppet (~> 1.0)
98
+ puppetlabs_spec_helper (3.0.0)
99
+ mocha (~> 1.0)
100
+ pathspec (>= 0.2.1, < 1.1.0)
101
+ puppet-lint (~> 2.0)
102
+ puppet-syntax (>= 2.0, < 4)
103
+ rspec-puppet (~> 2.0)
104
+ r10k (3.7.0)
105
+ colored2 (= 3.1.2)
106
+ cri (>= 2.15.10, < 3.0.0)
107
+ fast_gettext (~> 1.1.0)
108
+ gettext (>= 3.0.2, < 3.3.0)
109
+ gettext-setup (~> 0.24)
110
+ log4r (= 1.1.10)
111
+ multi_json (~> 1.10)
112
+ puppet_forge (~> 2.3.0)
113
+ rake (13.0.1)
114
+ rchardet (1.8.0)
115
+ rgen (0.8.2)
116
+ rspec (3.8.0)
117
+ rspec-core (~> 3.8.0)
118
+ rspec-expectations (~> 3.8.0)
119
+ rspec-mocks (~> 3.8.0)
120
+ rspec-core (3.8.1)
121
+ rspec-support (~> 3.8.0)
122
+ rspec-expectations (3.8.4)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.8.0)
125
+ rspec-mocks (3.8.1)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.8.0)
128
+ rspec-puppet (2.8.0)
129
+ rspec
130
+ rspec-support (3.8.2)
131
+ rspec_junit_formatter (0.4.1)
132
+ rspec-core (>= 2, < 4, != 2.12.0)
133
+ scanf (1.0.0)
134
+ semantic_puppet (1.0.3)
135
+ terminal-table (3.0.0)
136
+ unicode-display_width (~> 1.1, >= 1.1.1)
137
+ text (1.3.1)
138
+ thor (1.1.0)
139
+ unicode-display_width (1.7.0)
140
+ versionomy (0.5.0)
141
+ blockenspiel (~> 0.5)
142
+ yard (0.9.26)
143
+
144
+ PLATFORMS
145
+ ruby
146
+
147
+ DEPENDENCIES
148
+ bundler (~> 2.0)
149
+ onceover-codequality!
150
+ rake (~> 13.0)
151
+ rspec (~> 3.0)
152
+
153
+ BUNDLED WITH
154
+ 2.0.1
@@ -3,7 +3,6 @@ require "onceover/codequality/cli"
3
3
 
4
4
  class Onceover
5
5
  module CodeQuality
6
- # Your code goes here...
7
6
  end
8
7
  end
9
8
 
@@ -2,6 +2,9 @@ require "onceover/codequality/lint"
2
2
  require "onceover/codequality/syntax"
3
3
  require "onceover/codequality/docs"
4
4
  require "onceover/codequality/puppetfile"
5
+ require "onceover/codequality/environment"
6
+ require "onceover/codequality/executor"
7
+ require "onceover/codequality/formatter"
5
8
  class Onceover
6
9
  module CodeQuality
7
10
  class CLI
@@ -29,6 +32,8 @@ class Onceover
29
32
  html_docs = opts[:html_docs] || false
30
33
  status = true
31
34
 
35
+ logger.info "Running Code Quality tests"
36
+
32
37
  if ! no_puppetfile
33
38
  status &= Onceover::CodeQuality::Puppetfile.puppetfile
34
39
  end
@@ -46,9 +51,9 @@ class Onceover
46
51
  end
47
52
 
48
53
  if status
49
- logger.info "Code Quality tests passed, have a nice day"
54
+ logger.info "Code Quality tests PASSED, have a nice day"
50
55
  else
51
- logger.error "Code Quality tests failed, see previous error"
56
+ logger.error "Code Quality tests FAILED, see previous error(s)"
52
57
  exit 1
53
58
  end
54
59
  end
@@ -1,26 +1,26 @@
1
1
  # Support for generating documentation using Puppet Strings for each module
2
- # listed in the site directory
2
+ # listed in the environment.conf modulepath
3
3
  class Onceover
4
4
  module CodeQuality
5
5
  module Docs
6
- LOCAL_MOD_DIR = "site"
7
6
 
8
7
  def self.puppet_strings(html_docs)
9
- logger.info "Generating documentation..."
10
8
  status = true
11
- format = html_docs ? "html" : "markdown"
12
- if Dir.exist?(LOCAL_MOD_DIR)
13
- Dir.glob("#{LOCAL_MOD_DIR}/*/") { |dir|
14
- Dir.chdir(dir) {
15
- # puppet strings prints useful metrics so don't swallow its output
16
- s = system("puppet strings generate --format #{format}")
17
- if ! s
18
- logger.error("Error running puppet strings - see previous output")
19
- end
20
- status &= s
9
+ format = html_docs ? "--markup html" : "--format markdown"
10
+
11
+ CodeQuality::Environment.get_site_dirs.each { |local_mod_dir|
12
+ if Dir.exist?(local_mod_dir)
13
+ Dir.glob("#{local_mod_dir}/*/") { |dir|
14
+ Dir.chdir(dir) {
15
+ CodeQuality::Formatter.start_test("Generate documentation in #{dir}")
16
+ # puppet strings prints useful metrics so don't swallow its output
17
+ output, ok = CodeQuality::Executor.run("puppet strings generate #{format}")
18
+ status &= ok
19
+ CodeQuality::Formatter.end_test(output, ok, true)
20
+ }
21
21
  }
22
- }
23
- end
22
+ end
23
+ }
24
24
 
25
25
  status
26
26
  end
@@ -0,0 +1,34 @@
1
+ class Onceover
2
+ module CodeQuality
3
+ module Environment
4
+
5
+ ENVIRONMENT_CONF = "environment.conf"
6
+
7
+ # Latest best practice is to change the name of `site` to be
8
+ # `site-modules`. This means we need to start processing `environment.conf`
9
+ # to extract this...
10
+ def self.get_site_dirs()
11
+ if File.exist?(ENVIRONMENT_CONF)
12
+ #modulepath = site-modules:modules:$basemodulepath
13
+ modulepath = open(ENVIRONMENT_CONF) { |f| f.each_line.find { |line| line.include?("modulepath") } }
14
+
15
+ begin
16
+ environments = modulepath.split("=")[1].split(":").reject { |e|
17
+ # reject any elements containing interpolation or referencing modules
18
+ # loaded by r10k
19
+ e =~ /\$/ || e == "modules" || e =~ /[\\.\/]/
20
+ }.map {
21
+ |e| e.strip
22
+ }
23
+ rescue NoMethodError => e
24
+ raise "Malformed environment configuration: #{ENVIRONMENT_CONF}"
25
+ end
26
+ else
27
+ raise "Missing environment configuration: #{ENVIRONMENT_CONF}"
28
+ end
29
+
30
+ environments
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ class Onceover
2
+ module CodeQuality
3
+ module Executor
4
+
5
+ # Capture all program output and check the exit status was zero
6
+ def self.run(*command)
7
+ output, s = Open3.capture2e(*command)
8
+ ok = s.exitstatus.zero?
9
+
10
+ return output, ok
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ class Onceover
2
+ module CodeQuality
3
+ module Formatter
4
+
5
+ START_TEST = "Checking".freeze
6
+ MSG_TEST_OK = "...OK".freeze
7
+
8
+
9
+ def self.start_test(test_name)
10
+ logger.info "Checking #{test_name}..."
11
+ end
12
+
13
+ def self.end_test(output, ok, show_output=false)
14
+ if !ok || show_output
15
+ output.each_line do |line|
16
+ logger.info("\t#{line.chomp}")
17
+ end
18
+ end
19
+
20
+ if ok
21
+ logger.info "...OK"
22
+ else
23
+ logger.error "...FAILED"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -5,7 +5,7 @@ class Onceover
5
5
  # Apply linting to the manifests directory and each module under `site`
6
6
  LINT_PATHS = [
7
7
  "manifests",
8
- ].concat(Dir.glob('site/*').select {|f| File.directory? f})
8
+ ]
9
9
 
10
10
  # use our default options unless user has created own settings
11
11
  if ! File.exist? ".puppet-lint.rc"
@@ -23,15 +23,19 @@ class Onceover
23
23
 
24
24
  def self.puppet
25
25
  status = true
26
- LINT_PATHS.each { |p|
27
- if Dir.exists?(p)
28
- logger.info("checking lint in #{p}...")
29
- if ! system("puppet-lint #{LINT_OPTIONS.join ' '} #{p}")
30
- status = false
31
- else
32
- logger.info("...ok")
33
- end
34
26
 
27
+ # wait until runtime to scan directories for unit tests
28
+ lint_paths = LINT_PATHS.concat(
29
+ CodeQuality::Environment.get_site_dirs.each { |site_dir|
30
+ Dir.glob("#{site_dir}/*").select { |f| File.directory? f}
31
+ }
32
+ )
33
+ lint_paths.each { |p|
34
+ if Dir.exist?(p)
35
+ CodeQuality::Formatter.start_test("lint in #{p}")
36
+ output, ok = CodeQuality::Executor.run("puppet-lint #{LINT_OPTIONS.join ' '} #{p}")
37
+ status &= ok
38
+ CodeQuality::Formatter.end_test(output, ok)
35
39
  end
36
40
  }
37
41
 
@@ -6,16 +6,12 @@ class Onceover
6
6
  def self.puppetfile
7
7
  status = true
8
8
  if File.exist?("Puppetfile")
9
- logger.info("Checking Puppetfile...")
10
- output, s = Open3.capture2e("r10k puppetfile check")
11
- ok = s.exitstatus.zero?
9
+ CodeQuality::Formatter.start_test("Puppetfile")
10
+ output, ok = CodeQuality::Executor.run("r10k puppetfile check")
11
+
12
12
  status &= ok
13
13
 
14
- if ok
15
- logger.info("...ok")
16
- else
17
- logger.error("Puppetfile validation failed: #{output}")
18
- end
14
+ CodeQuality::Formatter.end_test(output, ok)
19
15
  else
20
16
  logger.warn("No Puppetfile found... continuing")
21
17
  end
@@ -1,4 +1,4 @@
1
- require 'open3'
1
+
2
2
  class Onceover
3
3
  module CodeQuality
4
4
  module Syntax
@@ -10,7 +10,7 @@ class Onceover
10
10
  # puppet-syntax
11
11
  #
12
12
 
13
- logger.info("Checking syntax using puppet-syntax rake task...")
13
+ CodeQuality::Formatter.start_test("puppet-syntax rake task")
14
14
  # puppet-syntax seems to assign $stdout/$stderr internally in ways that
15
15
  # prevent capturing output. As a nasty hack, run it as inline ruby and
16
16
  # capture the output from the process...
@@ -19,15 +19,10 @@ class Onceover
19
19
  PuppetSyntax.exclude_paths = ['vendor/**/*','spec/templates/*.erb']
20
20
  Rake::Task['syntax'].invoke
21
21
  RUBY_CODE
22
- output, s = Open3.capture2e("ruby", "-e", inline_ruby)
23
- ok = s.exitstatus.zero?
22
+ #output, s = Open3.capture2e("ruby", "-e", inline_ruby)
23
+ output, ok = CodeQuality::Executor.run("ruby", "-e", inline_ruby)
24
24
  status &= ok
25
-
26
- if ok
27
- logger.info("...ok")
28
- else
29
- logger.error("puppet-syntax validation failed: #{output}")
30
- end
25
+ CodeQuality::Formatter.end_test(output, ok)
31
26
 
32
27
  #
33
28
  # python yaml
@@ -45,19 +40,13 @@ class Onceover
45
40
  # users would be advised to fix the file, so lets _also_ validate yaml
46
41
  # files with python if available on our path...
47
42
  if system("python --version && python -c 'import yaml'", :err => File::NULL)
48
- logger.info("Running additional python YAML validation")
43
+ CodeQuality::Formatter.start_test("Additional python YAML validation")
49
44
  script = File.join(File.dirname(File.expand_path(__FILE__)), "../../../res/validate_yaml.py")
50
- output, s = Open3.capture2e("python #{script}")
51
- ok = s.exitstatus.zero?
45
+ output, ok = CodeQuality::Executor.run("python #{script}")
52
46
  status &= ok
53
-
54
- if ok
55
- logger.info("...ok")
56
- else
57
- logger.error("Puppetfile validation failed: #{output}")
58
- end
47
+ CodeQuality::Formatter.end_test(output, ok)
59
48
  else
60
- logger.warn("Please install python and add it to your path for enhanced YAML validation")
49
+ logger.warn("Please install python and pyyaml for enhanced YAML validation (pip install pyyaml)")
61
50
  end
62
51
 
63
52
  status
@@ -1,5 +1,5 @@
1
1
  class Onceover
2
2
  module CodeQuality
3
- VERSION = "0.5.2"
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
@@ -20,12 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.15"
24
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", "~> 13.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
26
 
27
27
  spec.add_runtime_dependency 'onceover', '~> 3'
28
- spec.add_runtime_dependency 'puppet-syntax', '~> 2'
28
+ spec.add_runtime_dependency 'puppet-syntax', '~> 3'
29
29
  spec.add_runtime_dependency 'puppet-lint', '~> 2'
30
30
  spec.add_runtime_dependency 'puppet-strings', '~> 2'
31
31
  end
data/res/validate_yaml.py CHANGED
@@ -7,9 +7,9 @@ try:
7
7
  import yaml
8
8
  for root, dirs, files in os.walk("."):
9
9
  for f in files:
10
- # we want yaml files that are not in hidden (.) dirs. account for / vs \ on windows/linux
10
+ # we want yaml files that are not in hidden (.) dirs or vendor directory. account for / vs \ on windows/linux
11
11
  target = os.path.join(root, f)
12
- if target.endswith(".yaml") and not re.match("^\.(/|\\\)\.", target):
12
+ if target.endswith(".yaml") and not re.match("^\.(/|\\\)(\.|vendor)", target):
13
13
  try:
14
14
  yaml.safe_load(open(target,"r"))
15
15
  except Exception as e:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onceover-codequality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Declarative Systems
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2'
75
+ version: '3'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2'
82
+ version: '3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: puppet-lint
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ files:
119
119
  - ".rspec"
120
120
  - ".travis.yml"
121
121
  - Gemfile
122
+ - Gemfile.lock
122
123
  - LICENSE
123
124
  - README.md
124
125
  - Rakefile
@@ -127,6 +128,9 @@ files:
127
128
  - lib/onceover/codequality.rb
128
129
  - lib/onceover/codequality/cli.rb
129
130
  - lib/onceover/codequality/docs.rb
131
+ - lib/onceover/codequality/environment.rb
132
+ - lib/onceover/codequality/executor.rb
133
+ - lib/onceover/codequality/formatter.rb
130
134
  - lib/onceover/codequality/lint.rb
131
135
  - lib/onceover/codequality/puppetfile.rb
132
136
  - lib/onceover/codequality/syntax.rb