Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

hier #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ branding:
color: "green"
inputs:
type:
description: "lcov | simplecov"
description: "lcov | simplecov | phpunit"
required: true
default: "lcov"
token:
Expand Down
24 changes: 24 additions & 0 deletions lib/coverage_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def generate(type, report_path, data)
simplecov(report_path, data)
elsif type == 'lcov'
lcov(report_path, data)
elsif type == 'phpunit'
phpunit(report_path, data)
else
raise 'InvalidCoverageReportType'
end
Expand All @@ -25,6 +27,12 @@ def lcov(report_path, data)
{ 'lines' => { 'covered_percent' => lcov_covered_percent(lcov_result), 'minumum_percent' => minumum_percent } }
end

def phpunit(report_path, data)
phpunit_result = execute_phpunit_parse(report_path)
minumum_percent = data[:min]
{ 'lines' => { 'covered_percent' => phpunit_covered_percent(phpunit_result), 'minumum_percent' => minumum_percent} }
end

private

def lcov_covered_percent(lcov_result)
Expand All @@ -39,6 +47,22 @@ def execute_lcov_parse(report_path)
JSON.parse(`node #{bin_path}/lcov-parse.js #{report_path}`)
end


def phpunit_covered_percent(phpunit_result)
# example for
# phpunit --coverage-text
# Summary:
# Classes: 10.14% (14/138)
# Methods: 16.67% (107/642)
# Lines: 13.95% (1059/7591)

/Lines: * ([0-9\.]*)%/.match(phpunit_result)[1].to_f
end

def execute_phpunit_parse(report_path)
File.read(report_path)
end

def read_json(path)
JSON.parse(File.read(path))
end
Expand Down