Compare commits

..

9 Commits

Author SHA1 Message Date
09178ef7bf
Some Docu 2021-04-14 12:58:17 +02:00
71b4a02b05
more corrections 2021-04-14 12:42:11 +02:00
8d4f7c6ab3
typo 2021-04-14 12:23:41 +02:00
abd4aff55b
properly get default values for report_name
rename field to report_name
2021-04-14 12:10:17 +02:00
f6604dcfa9
name variable from github config 2021-04-14 11:47:19 +02:00
Miguel Savignano
0bc53bbf5c update README with github token instructions 2020-12-21 22:12:53 +01:00
Miguel Savignano
4a754f8957 update CHANGELOG and README 2020-10-04 19:13:35 +02:00
Abimael Martell
b8506db951
Add percentage on result title (#4)
* Add percentage to action name

* Test with percentage in output title
2020-10-04 19:10:13 +02:00
Miguel Savignano
2454e13902 update action yml 2019-11-03 02:15:13 +01:00
7 changed files with 46 additions and 19 deletions

View File

@ -1,6 +1,14 @@
# Changelog # Changelog
## v1.2.0
- Added the coverage percent to result title on Check [#4](https://github.com/devmasx/coverage-check-action/pull/4)
## v1.1.0
- Lcov
## v1.0.0 ## v1.0.0
- Create check run in github - Create check run in github
- Adapter for brakeman report - Simplecov

View File

@ -2,28 +2,43 @@
A GitHub Action that check minimum coverage percentage! A GitHub Action that check minimum coverage percentage!
This action requires a Github token with `checks:write` scope to allow create the check run using the Github API v3.
But no need to generate any new token, you can use the Github action token (`${{ github.token }}`)
### Usage ### Usage
#### Lcov #### Lcov
```yml ```yml
- uses: devmasx/coverage-check-action@v1.1.0 - uses: devmasx/coverage-check-action@v1.2.0
with: with:
type: lcov type: lcov
result_path: coverage/example.lcov result_path: coverage/example.lcov
min_coverage: 90 min_coverage: 90
token: ${{secrets.GITHUB_TOKEN}} token: ${{ github.token }}
``` ```
#### [Simplecov](https://github.com/colszowka/simplecov) #### [Simplecov](https://github.com/colszowka/simplecov)
```yml ```yml
- uses: devmasx/coverage-check-action@v1.1.0 - uses: devmasx/coverage-check-action@v1.2.0
with: with:
type: simplecov type: simplecov
result_path: coverage/.last_run.json result_path: coverage/.last_run.json
min_coverage: 90 min_coverage: 90
token: ${{secrets.GITHUB_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 ## Screenshots

View File

@ -12,10 +12,12 @@ inputs:
token: token:
description: "Github token for create checks" description: "Github token for create checks"
required: true required: true
default: "World"
min_coverage: min_coverage:
description: "Minimum coverage" description: "Minimum coverage"
default: "80" default: "80"
report_name:
description: "Name of the github action check"
default: "Coverage"
result_path: result_path:
description: "Json with coverage result" description: "Json with coverage result"
required: true required: true

View File

@ -1,11 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
class GithubCheckRunService class GithubCheckRunService
CHECK_NAME = 'Coverage' def initialize(report, github_data, report_name, report_adapter)
def initialize(report, github_data, report_adapter)
@report = report @report = report
@github_data = github_data @github_data = github_data
@report_name = report_name
@report_adapter = report_adapter @report_adapter = report_adapter
@client = GithubClient.new(@github_data[:token], user_agent: 'coverage-action') @client = GithubClient.new(@github_data[:token], user_agent: 'coverage-action')
end end
@ -18,6 +17,7 @@ class GithubCheckRunService
@summary = @report_adapter.summary(@report) @summary = @report_adapter.summary(@report)
@annotations = @report_adapter.annotations(@report) @annotations = @report_adapter.annotations(@report)
@conclusion = @report_adapter.conslusion(@report) @conclusion = @report_adapter.conslusion(@report)
@percent = @report_adapter.lines_covered_percent(@report)
@client.patch( @client.patch(
"#{endpoint_url}/#{id}", "#{endpoint_url}/#{id}",
@ -33,7 +33,7 @@ class GithubCheckRunService
def create_check_payload def create_check_payload
{ {
name: CHECK_NAME, name: @report_name,
head_sha: @github_data[:sha], head_sha: @github_data[:sha],
status: 'in_progress', status: 'in_progress',
started_at: Time.now.iso8601 started_at: Time.now.iso8601
@ -42,13 +42,13 @@ class GithubCheckRunService
def update_check_payload def update_check_payload
{ {
name: CHECK_NAME, name: @report_name,
head_sha: @github_data[:sha], head_sha: @github_data[:sha],
status: 'completed', status: 'completed',
completed_at: Time.now.iso8601, completed_at: Time.now.iso8601,
conclusion: @conclusion, conclusion: @conclusion,
output: { output: {
title: CHECK_NAME, title: "#{@report_name} #{@percent}%",
summary: @summary, summary: @summary,
annotations: @annotations annotations: @annotations
} }

View File

@ -17,13 +17,14 @@ end
sha: ENV['GITHUB_SHA'], sha: ENV['GITHUB_SHA'],
token: ENV['INPUT_TOKEN'], token: ENV['INPUT_TOKEN'],
owner: ENV['GITHUB_REPOSITORY_OWNER'] || @event_json.dig('repository', 'owner', 'login'), 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'] @coverage_type = ENV['INPUT_TYPE']
@report_path = ENV['INPUT_RESULT_PATH'] @report_path = ENV['INPUT_RESULT_PATH']
@report_name = ENV['INPUT_REPORT_NAME']
@data = { min: ENV['INPUT_MIN_COVERAGE'] } @data = { min: ENV['INPUT_MIN_COVERAGE'] }
@report = CoverageReport.generate(@coverage_type, @report_path, @data) @report = CoverageReport.generate(@coverage_type, @report_path, @data)
GithubCheckRunService.new(@report, @github_data, ReportAdapter).run GithubCheckRunService.new(@report, @github_data, @report_name, ReportAdapter).run

View File

@ -18,16 +18,16 @@ class ReportAdapter
[] []
end end
def lines_covered_percent(report)
@lines_covered_percent ||= report.dig('lines', 'covered_percent')
end
private private
def table_head def table_head
"| Type | covered | minimum |\n| ----- | ------- | ------- |" "| Type | covered | minimum |\n| ----- | ------- | ------- |"
end end
def lines_covered_percent(report)
@lines_covered_percent ||= report.dig('lines', 'covered_percent')
end
def lines_minimum_percent(report) def lines_minimum_percent(report)
@lines_minimum_percent ||= report.dig('lines', 'minumum_percent') @lines_minimum_percent ||= report.dig('lines', 'minumum_percent')
end end

View File

@ -7,7 +7,8 @@ describe GithubCheckRunService do
{ 'lines' => { 'covered_percent' => 80, 'minumum_percent' => 80 } } { 'lines' => { 'covered_percent' => 80, 'minumum_percent' => 80 } }
end end
let(:github_data) { { sha: 'sha', token: 'token', owner: 'owner', repo: 'repository_name' } } 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 it '#run' do
stub_request(:any, 'https://api.github.com/repos/owner/repository_name/check-runs/id') stub_request(:any, 'https://api.github.com/repos/owner/repository_name/check-runs/id')