firespring_dev_commands 2.1.21.pre.alpha.2 → 2.1.21.pre.alpha.4

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: 87e1ba4de217508ebdec8d17da4156baaab7bfb45154519d5b5aa930d8f8755b
4
- data.tar.gz: 9b208c659543d76dc89b7b9e92d21991445056d9cae72bf7616bed2b5169d6b8
3
+ metadata.gz: d35a98b66dfe013f7552c2d5baf17b373ad71e3893945844a24768620755bf5f
4
+ data.tar.gz: faa627fca3af6b2c2ef417fd1442439b16d7acafa6a1a3dfa5da1fc01c26e327
5
5
  SHA512:
6
- metadata.gz: a6c7ef9927e5b2cd60a0f21ebd50d6a2b0f96aa383c69d9b8196c2d4c4c11700350e231dcb34b5e1bf83f5953cc999ebbf6b7edcc8d0a9ee200275e936fda4cd
7
- data.tar.gz: e97e145d2820c3ecd8143fafcf5a730edb39351fdfb2bf61b95344039e0ae54801c0029dccb6d1b313cd093aa195bcd775674145a23b2ba6a6838b77b3cf4297
6
+ metadata.gz: 434c1348564f615f90438f4682080aa70a659693a264e2b47ac17f94e935fb0dfbace4875df3c76dcd5ac76d2ce44cdc7ded70ec10882e5fa4927f01e9e4fb0c
7
+ data.tar.gz: a11c82d457d76e6eeca78217db40a62d7cc9c6eade77c2f07cb9c68ed89b4b1d274b6e7cad5e64abefa0c1814c23b29a03f2e4b0d837d9f9faece9b24ca5821b
@@ -1,29 +1,44 @@
1
1
  module Dev
2
+ # Module containing different classes for interfacing with coverage files
2
3
  module Coverage
4
+ # Class for checking code coverage using cobertura
3
5
  class Cobertura
4
- attr_reader :local_filename, :container_filename, :filename, :threshold
6
+ attr_reader :local_path, :container_path, :filename, :threshold, :local_path, :local_filename, :container_path, :container_filename
5
7
 
6
8
  def initialize(filename: 'cobertura.xml', threshold: nil, container_path: nil, local_path: nil)
7
9
  @filename = filename
10
+ @local_path = local_path
8
11
  @local_filename = File.join(local_path || '.', @filename)
12
+ @container_path = container_path
9
13
  @container_filename = File.join(container_path || '.', @filename)
10
14
  @threshold = threshold.to_f
15
+ end
11
16
 
17
+ # Remove any previous versions of the local file that will be output
18
+ # return the phpunit options needed to regenerate the cobertura xml file
19
+ def php_options
12
20
  # Remove any previous coverage info
13
21
  FileUtils.rm_f(local_filename, verbose: true)
14
- end
15
22
 
16
- def options
23
+ # Return the needed php commands to generate the cobertura report
17
24
  %W(--coverage-cobertura #{container_filename})
18
25
  end
19
26
 
20
- def check
27
+ # Parse the cobertura file as a hash and check the total coverage against the desired threshold
28
+ def check(application: nil)
29
+ # If an application has been specified and the file does not exist locally, attempt to copy it back from the docker container
30
+ if application && !File.exist?(local_filename)
31
+ container = Dev::Docker::Compose.new.container_by_name(application)
32
+ workdir = Dev::Docker.new.default_working_dir(container)
33
+ Dev::Docker.new.copy_from_container(container, File.join(workdir, filename), local_filename, required: true)
34
+ end
35
+
36
+ # Load the file from disk and parse with ox
21
37
  report = Ox.load(File.read(local_filename), mode: :hash)
22
38
  attrs, = report[:coverage]
23
39
  cov_pct = attrs[:'line-rate'].to_f * 100
24
- raise format('Line coverage %.2f%% is less than the threshold %.2f%%', cov_pct, threshold) if cov_pct < threshold
25
-
26
- puts format('Line coverage %.2f%% is above the threshold %.2f%%', cov_pct, threshold)
40
+ puts format('Line coverage was %.2f%%. Configured threshold was %.2f%%', cov_pct, threshold)
41
+ raise 'Code coverage not met' if cov_pct < threshold
27
42
  end
28
43
  end
29
44
  end
@@ -138,6 +138,11 @@ module Dev
138
138
  Docker::Compose.new.mapped_public_port(name, private_port)
139
139
  end
140
140
 
141
+ # Gets the default working dir of the container
142
+ def default_working_dir(container)
143
+ container.json['Config']['WorkingDir']
144
+ end
145
+
141
146
  # Copies the source path on your local machine to the destination path on the container
142
147
  def copy_to_container(container, source_path, dest_path)
143
148
  LOG.info "Copying #{source_path} to #{dest_path}... "
@@ -95,14 +95,14 @@ module Dev
95
95
  def test_command
96
96
  test = []
97
97
  test << './vendor/bin/phpunit'
98
- test << coverage.options if coverage
98
+ test << coverage.php_options if coverage
99
99
  test.concat(Dev::Common.new.tokenize(ENV['OPTS'].to_s))
100
100
  test
101
101
  end
102
102
 
103
103
  # Run the check to ensure code coverage meets the desired threshold
104
- def check_test_coverage
105
- coverage.check
104
+ def check_test_coverage(application:)
105
+ coverage.check(application:)
106
106
  end
107
107
 
108
108
  # Build the php fast test command
@@ -135,7 +135,7 @@ module Dev
135
135
  options = []
136
136
  options << '-T' if Dev::Common.new.running_codebuild?
137
137
  Dev::Docker::Compose.new(services: application, options:).exec(*php.test_command)
138
- php.check_test_coverage
138
+ php.check_test_coverage(application:)
139
139
  end
140
140
  end
141
141
  end
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.21.pre.alpha.2'.freeze
9
+ VERSION = '2.1.21.pre.alpha.4'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.21.pre.alpha.2
4
+ version: 2.1.21.pre.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring