From f6604dcfa921ede478b881d13b0493be9f1fd0a8 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 14 Apr 2021 11:47:19 +0200 Subject: [PATCH 1/8] name variable from github config --- lib/github_check_run_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_check_run_service.rb b/lib/github_check_run_service.rb index 6d8feca..c7c1fcb 100644 --- a/lib/github_check_run_service.rb +++ b/lib/github_check_run_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class GithubCheckRunService - CHECK_NAME = 'Coverage' + CHECK_NAME = defined? @github_data[:name] ? @github_data[:name] : 'Coverage' def initialize(report, github_data, report_adapter) @report = report From abd4aff55b76ed93a1e627fc6e11fb3225bc0f29 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 14 Apr 2021 12:10:17 +0200 Subject: [PATCH 2/8] properly get default values for report_name rename field to report_name --- action.yml | 3 +++ lib/github_check_run_service.rb | 8 +++----- lib/index.rb | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 673b54e..b8c4ad1 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: min_coverage: description: "Minimum coverage" default: "80" + report_name: + description: "Name of the github action check" + default: "Coverage" result_path: description: "Json with coverage result" required: true diff --git a/lib/github_check_run_service.rb b/lib/github_check_run_service.rb index c7c1fcb..b2287cf 100644 --- a/lib/github_check_run_service.rb +++ b/lib/github_check_run_service.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class GithubCheckRunService - CHECK_NAME = defined? @github_data[:name] ? @github_data[:name] : 'Coverage' - def initialize(report, github_data, report_adapter) @report = report @github_data = github_data @@ -34,7 +32,7 @@ def endpoint_url def create_check_payload { - name: CHECK_NAME, + name: @report_name, head_sha: @github_data[:sha], status: 'in_progress', started_at: Time.now.iso8601 @@ -43,13 +41,13 @@ def create_check_payload def update_check_payload { - name: CHECK_NAME, + name: @report_name, head_sha: @github_data[:sha], status: 'completed', completed_at: Time.now.iso8601, conclusion: @conclusion, output: { - title: "#{CHECK_NAME} #{@percent}%", + title: "#{@report_name} #{@percent}%", summary: @summary, annotations: @annotations } diff --git a/lib/index.rb b/lib/index.rb index e888441..67c3003 100644 --- a/lib/index.rb +++ b/lib/index.rb @@ -17,11 +17,12 @@ def read_json(path) sha: ENV['GITHUB_SHA'], token: ENV['INPUT_TOKEN'], owner: ENV['GITHUB_REPOSITORY_OWNER'] || @event_json.dig('repository', 'owner', 'login'), - repo: ENV['GITHUB_REPOSITORY_NAME'] || @event_json.dig('repository', 'name') + repo: ENV['GITHUB_REPOSITORY_NAME'] || @event_json.dig('repository', 'name'), } @coverage_type = ENV['INPUT_TYPE'] @report_path = ENV['INPUT_RESULT_PATH'] +@report_name: ENV['INPUT_REPORT_NAME'] @data = { min: ENV['INPUT_MIN_COVERAGE'] } @report = CoverageReport.generate(@coverage_type, @report_path, @data) From 8d4f7c6ab37a3b272c6f774e0ea88225b852dbe1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 14 Apr 2021 12:23:41 +0200 Subject: [PATCH 3/8] typo --- lib/index.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.rb b/lib/index.rb index 67c3003..3e4e029 100644 --- a/lib/index.rb +++ b/lib/index.rb @@ -22,7 +22,7 @@ def read_json(path) @coverage_type = ENV['INPUT_TYPE'] @report_path = ENV['INPUT_RESULT_PATH'] -@report_name: ENV['INPUT_REPORT_NAME'] +@report_name = ENV['INPUT_REPORT_NAME'] @data = { min: ENV['INPUT_MIN_COVERAGE'] } @report = CoverageReport.generate(@coverage_type, @report_path, @data) From 71b4a02b05220f8234d4396b555c912abdf59f7d Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 14 Apr 2021 12:42:11 +0200 Subject: [PATCH 4/8] more corrections --- lib/github_check_run_service.rb | 3 ++- lib/index.rb | 2 +- spec/github_check_run_service_spec.rb | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/github_check_run_service.rb b/lib/github_check_run_service.rb index b2287cf..878d81e 100644 --- a/lib/github_check_run_service.rb +++ b/lib/github_check_run_service.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true class GithubCheckRunService - def initialize(report, github_data, report_adapter) + def initialize(report, github_data, report_name, report_adapter) @report = report @github_data = github_data + @report_name = report_name @report_adapter = report_adapter @client = GithubClient.new(@github_data[:token], user_agent: 'coverage-action') end diff --git a/lib/index.rb b/lib/index.rb index 3e4e029..0b2e64c 100644 --- a/lib/index.rb +++ b/lib/index.rb @@ -27,4 +27,4 @@ def read_json(path) @report = CoverageReport.generate(@coverage_type, @report_path, @data) -GithubCheckRunService.new(@report, @github_data, ReportAdapter).run +GithubCheckRunService.new(@report, @github_data, @report_name, ReportAdapter).run diff --git a/spec/github_check_run_service_spec.rb b/spec/github_check_run_service_spec.rb index b76cb51..036a85e 100644 --- a/spec/github_check_run_service_spec.rb +++ b/spec/github_check_run_service_spec.rb @@ -7,7 +7,8 @@ { 'lines' => { 'covered_percent' => 80, 'minumum_percent' => 80 } } end let(:github_data) { { sha: 'sha', token: 'token', owner: 'owner', repo: 'repository_name' } } - let(:service) { GithubCheckRunService.new(report, github_data, ReportAdapter) } + let(:report_name) { 'Coverage' } + let(:service) { GithubCheckRunService.new(report, github_data, report_name, ReportAdapter) } it '#run' do stub_request(:any, 'https://api.github.com/repos/owner/repository_name/check-runs/id') From 09178ef7bfdee096c0d0563410bf35ecb7aa6dd0 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Wed, 14 Apr 2021 12:58:17 +0200 Subject: [PATCH 5/8] Some Docu --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 495078f..b381d7d 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,18 @@ But no need to generate any new token, you can use the Github action token (`${{ token: ${{ github.token }} ``` +#### Report name + +```yml +- uses: devmasx/coverage-check-action@v1.2.0 + with: + type: lcov + result_path: coverage/example.lcov + min_coverage: 90 + token: ${{ github.token }} + report_name: "My Github Action Check Name" +``` + ## Screenshots ![Success](./screenshots/success.png) From 432acf66ba6d43d5f2df886ab3cb584017bfff2f Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 11 Jun 2021 16:50:45 +0200 Subject: [PATCH 6/8] add get coverage per line from phpunit coverage report in text format --- action.yml | 2 +- lib/coverage_report.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b8c4ad1..e2f0dd9 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ branding: color: "green" inputs: type: - description: "lcov | simplecov" + description: "lcov | simplecov | phpunit" required: true default: "lcov" token: diff --git a/lib/coverage_report.rb b/lib/coverage_report.rb index 8752daa..0bb4b17 100644 --- a/lib/coverage_report.rb +++ b/lib/coverage_report.rb @@ -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 @@ -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) @@ -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] + end + + def execute_phpunit_parse(report_path) + File.read(report_path) + end + def read_json(path) JSON.parse(File.read(path)) end From ef143a2e3948826be33c2254fc6003dd523b3e5d Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 11 Jun 2021 17:08:04 +0200 Subject: [PATCH 7/8] add debug --- lib/coverage_report.rb | 2 ++ lib/report_adapter.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/coverage_report.rb b/lib/coverage_report.rb index 0bb4b17..1c237c7 100644 --- a/lib/coverage_report.rb +++ b/lib/coverage_report.rb @@ -29,6 +29,8 @@ def lcov(report_path, data) def phpunit(report_path, data) phpunit_result = execute_phpunit_parse(report_path) + puts phpunit_result + puts phpunit_covered_percent(phpunit_result) minumum_percent = data[:min] { 'lines' => { 'covered_percent' => phpunit_covered_percent(phpunit_result), 'minumum_percent' => minumum_percent} } end diff --git a/lib/report_adapter.rb b/lib/report_adapter.rb index c82843d..83a9a3c 100644 --- a/lib/report_adapter.rb +++ b/lib/report_adapter.rb @@ -7,6 +7,8 @@ class << self ANNOTATION_LEVEL = { notice: 'notice', warning: 'warning', failure: 'failure' }.freeze def conslusion(report) + puts report + puts lines_covered_percent(report) lines_covered_percent(report) >= lines_minimum_percent(report).to_f ? CONCLUSION_TYPES[:success] : CONCLUSION_TYPES[:failure] end From 4681b01d631afdc50aa793444beb5a8628ddd170 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Fri, 11 Jun 2021 17:13:18 +0200 Subject: [PATCH 8/8] remove debug, fix it (hopefully) --- lib/coverage_report.rb | 4 +--- lib/report_adapter.rb | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/coverage_report.rb b/lib/coverage_report.rb index 1c237c7..73ceae4 100644 --- a/lib/coverage_report.rb +++ b/lib/coverage_report.rb @@ -29,8 +29,6 @@ def lcov(report_path, data) def phpunit(report_path, data) phpunit_result = execute_phpunit_parse(report_path) - puts phpunit_result - puts phpunit_covered_percent(phpunit_result) minumum_percent = data[:min] { 'lines' => { 'covered_percent' => phpunit_covered_percent(phpunit_result), 'minumum_percent' => minumum_percent} } end @@ -58,7 +56,7 @@ def phpunit_covered_percent(phpunit_result) # Methods: 16.67% (107/642) # Lines: 13.95% (1059/7591) - /Lines: * ([0-9\.]*)%/.match(phpunit_result)[1] + /Lines: * ([0-9\.]*)%/.match(phpunit_result)[1].to_f end def execute_phpunit_parse(report_path) diff --git a/lib/report_adapter.rb b/lib/report_adapter.rb index 83a9a3c..c82843d 100644 --- a/lib/report_adapter.rb +++ b/lib/report_adapter.rb @@ -7,8 +7,6 @@ class << self ANNOTATION_LEVEL = { notice: 'notice', warning: 'warning', failure: 'failure' }.freeze def conslusion(report) - puts report - puts lines_covered_percent(report) lines_covered_percent(report) >= lines_minimum_percent(report).to_f ? CONCLUSION_TYPES[:success] : CONCLUSION_TYPES[:failure] end