firespring_dev_commands 2.1.21.pre.alpha.3 → 2.1.21.pre.alpha.4
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 +4 -4
- data/lib/firespring_dev_commands/coverage/cobertura.rb +15 -5
- data/lib/firespring_dev_commands/docker.rb +5 -0
- data/lib/firespring_dev_commands/php.rb +2 -2
- data/lib/firespring_dev_commands/templates/docker/php/application.rb +1 -1
- data/lib/firespring_dev_commands/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d35a98b66dfe013f7552c2d5baf17b373ad71e3893945844a24768620755bf5f
|
4
|
+
data.tar.gz: faa627fca3af6b2c2ef417fd1442439b16d7acafa6a1a3dfa5da1fc01c26e327
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434c1348564f615f90438f4682080aa70a659693a264e2b47ac17f94e935fb0dfbace4875df3c76dcd5ac76d2ce44cdc7ded70ec10882e5fa4927f01e9e4fb0c
|
7
|
+
data.tar.gz: a11c82d457d76e6eeca78217db40a62d7cc9c6eade77c2f07cb9c68ed89b4b1d274b6e7cad5e64abefa0c1814c23b29a03f2e4b0d837d9f9faece9b24ca5821b
|
@@ -3,11 +3,13 @@ module Dev
|
|
3
3
|
module Coverage
|
4
4
|
# Class for checking code coverage using cobertura
|
5
5
|
class Cobertura
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :local_path, :container_path, :filename, :threshold, :local_path, :local_filename, :container_path, :container_filename
|
7
7
|
|
8
8
|
def initialize(filename: 'cobertura.xml', threshold: nil, container_path: nil, local_path: nil)
|
9
9
|
@filename = filename
|
10
|
+
@local_path = local_path
|
10
11
|
@local_filename = File.join(local_path || '.', @filename)
|
12
|
+
@container_path = container_path
|
11
13
|
@container_filename = File.join(container_path || '.', @filename)
|
12
14
|
@threshold = threshold.to_f
|
13
15
|
end
|
@@ -18,17 +20,25 @@ module Dev
|
|
18
20
|
# Remove any previous coverage info
|
19
21
|
FileUtils.rm_f(local_filename, verbose: true)
|
20
22
|
|
23
|
+
# Return the needed php commands to generate the cobertura report
|
21
24
|
%W(--coverage-cobertura #{container_filename})
|
22
25
|
end
|
23
26
|
|
24
27
|
# Parse the cobertura file as a hash and check the total coverage against the desired threshold
|
25
|
-
def check
|
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
|
26
37
|
report = Ox.load(File.read(local_filename), mode: :hash)
|
27
38
|
attrs, = report[:coverage]
|
28
39
|
cov_pct = attrs[:'line-rate'].to_f * 100
|
29
|
-
|
30
|
-
|
31
|
-
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
|
32
42
|
end
|
33
43
|
end
|
34
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}... "
|
@@ -101,8 +101,8 @@ module Dev
|
|
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
|