Skip to content

Commit

Permalink
docs: update documentation and comments
Browse files Browse the repository at this point in the history
ci: add --verbose arg to tests

fix: support empty git output

ci: fix build on Github actions

chore: fix random tests

fix: correct git params and ARGV parsing

fix: allow empty commit hash
  • Loading branch information
mrexox committed Mar 3, 2023
1 parent d27ee85 commit 9f9288a
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/crystal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: shards install
- name: Run tests
run: crystal spec --verbose --order random --error-on-warnings
run: crystal spec --verbose --order random

lint:
runs-on: ubuntu-latest
Expand Down
88 changes: 5 additions & 83 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,86 +90,8 @@ dist/coveralls --repo-token=<...> --file coverage/coverage.mycov

Checklist to add new CI options:

1. Add a module at [src/coverage_reporter/ci/](../src/coverage_reporter/ci/) and implement `.options` method.

```crystal
# CI options template.
#
# src/coverage_reporter/ci/my_ci.cr
require "./options"
module CoverageReporter
module CI
module MyCI
extend self
def options
# NOTE: `.options` method should return `nil` if environment doesn't match the CI.
return unless ENV["MY_CI"]?
Options.new(
service_name: "my-ci",
service_job_id: ENV["MY_CI_JOB_ID"]?,
service_pull_request: ENV["MY_CI_PR_NUMBER"]?,
service_branch: ENV["MY_CI_GIT_BRANCH"]?,
commit_sha: ENV["MY_CI_COMMIT_SHA"]?,
# ... provide as many options as you can.
).to_h
end
end
end
end
```

2. Provide as many options as you can (see [`CI::Options`](../src/coverage_reporter/ci/options.cr) for the full list).

3. Add your module to `CI_OPTIONS` tuple.

```crystal
# src/coverage_reporter/config.cr
module CoverageReporter
class Config
CI_OPTIONS = {
# ...
MyCI,
}
# ...
end
end
```

4. Write the specs for your CI options.

```crystal
# spec/coverage_reporter/config_spec.cr
Spectator.describe CoverageReporter::Config do
# ...
describe "#to_h" do
# ...
context "for My CI" do
before_each do
ENV["MY_CI"] = "1"
ENV["MY_CI_GIT_BRANCH"] = "my-ci-git-branch"
ENV["MY_CI_JOB_ID"] = "my-ci-job-id"
ENV["MY_CI_COMMIT_SHA"] = "my-ci-commit-sha"
ENV["MY_CI_PR_NUMBER"] = "13"
end
it "gets info from ENV" do
expect(subject).to eq({
:repo_token => "repo_token",
:service_name => "my-ci",
:service_branch => "my-ci-git-branch",
:service_job_id => "my-ci-job-id",
:commit_sha => "my-ci-commit-sha",
:service_pull_request => "13",
})
end
end
end
end
```
- Add a module at [src/coverage_reporter/ci/](../src/coverage_reporter/ci/) and implement `.options` method.
- Note: `.options` method should return `nil` if environment doesn't match the CI.
- Provide as many options as you can (see [`CI::Options`](../src/coverage_reporter/ci/options.cr) for the full list).
- Add your module to `CI_OPTIONS` tuple.
- Write the specs for your CI options.
2 changes: 1 addition & 1 deletion spec/coverage_reporter/parsers/lcov_parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Spectator.describe CoverageReporter::LcovParser do
describe "#parse" do
let(filename) { "spec/fixtures/test.lcov" }
let(coverage) do
[1, 1, 1, nil, 1, 66, 66, nil, nil, 1, 323, 63, 63, 63, 60, nil, 3, nil, 63, 32, nil, 63, 63, 63, 3, nil, 63, 60, nil, 3, nil, 63, 27, 27, 27, nil, nil, 323, nil, nil, 1, 5, 5, nil, 2, nil, nil, 3, 3, 1, 1, 1, 1, nil, 0, nil, nil, 2, 2, 2, 0, nil, 2, nil, nil, 2, 2, nil, nil, nil, nil, 1, 1, 1, 1, 1, 1, nil, 1, 1, nil, 1, 87, 87, 6, 6, 6, 6, 9, 6, 6, nil, 81, nil, nil, nil, 1, 1, nil, nil, 1, 1, nil, nil, 1, nil, 2, 2, 2, 1, nil, 2, nil, nil, 1, 3, 1, 1, nil, nil, 2, 2, 2, nil, 1, 1, nil, 2, nil, nil, nil, 1, 1, nil, nil, 1, 50, 50, 50, 50, 20, nil, 50, 50, 2, nil, 50, 50, 50, 31, nil, 50, 24, nil, 50, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
[1, 1, 1, nil, 1, 66, 66, nil, nil, 1, 323, 63, 63, 63, 60, nil, 3, nil, 63, 32, nil, 63, 63, 63, 3, nil, 63, 60, nil, 3, nil, 63, 27, 27, 27, nil, nil, 323, nil, nil, 1, 5, 5, nil, 2, nil, nil, 3, 3, 1, 1, 1, 1, nil, 0, nil, nil, 2, 2, 2, 0, nil, 2, nil, nil, 2, 2, nil, nil, nil, nil, 1, 1, 1, 1, 1, 1, nil, 1, 1, nil, 1, 87, 87, 6, 6, 6, 6, 9, 6, 6, nil, 81, nil, nil, nil, 1, 1, nil, nil, 1, 1, nil, nil, 1, nil, 2, 2, 2, 1, nil, 2, nil, nil, 1, 3, 1, 1, nil, nil, 2, 2, 2, nil, 1, 1, nil, 2, nil, nil, nil, 1, 1, nil, nil, 1, 50, 50, 50, 50, 20, nil, 50, 50, 2, nil, 50, 50, 50, 31, nil, 50, 24, nil, 50, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] of Int64?
end

it "parses correctly" do
Expand Down
7 changes: 1 addition & 6 deletions src/coverage_reporter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ module CoverageReporter
# Refers to a build via `service_number` parameter which is either taken
# from a CI-specific ENV, or can be set explicitly via `COVERALLS_SERVICE_NUMBER`
# environment variable.
def parallel_done(
repo_token : String?,
config_path : String,
carryforward : String?,
dry_run : Bool
)
def parallel_done(repo_token : String?, config_path : String, dry_run : Bool)
config = Config.new(repo_token: repo_token, path: config_path)
api = Api::Webhook.new(config, carryforward)

Expand Down
2 changes: 1 addition & 1 deletion src/coverage_reporter/api/jobs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "json"

module CoverageReporter
class Api::Jobs
@source : Array(Hash(Symbol, String | Array(Int32?)))
@source : Array(Hash(Symbol, String | Array(Int64?)))

def initialize(
@config : Config,
Expand Down
4 changes: 2 additions & 2 deletions src/coverage_reporter/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ module CoverageReporter::Cli
end

private def parse_args(args, opts = Opts.new)
option_parser = OptionParser.new do |parser|
parser.banner = "Usage: coveralls [options]"
OptionParser.parse(args) do |parser|
parser.banner = "Usage coveralls [arguments]"
parser.on(
"-rTOKEN",
"--repo-token=TOKEN",
Expand Down
4 changes: 2 additions & 2 deletions src/coverage_reporter/file_report.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module CoverageReporter
def initialize(
@name : String,
@coverage : Array(Int64?),
@branches : Array(Int64?) | Array(Int64) | Nil = nil
@branches : Array(Int64?) | Nil = nil
)
end

def to_h : Hash(Symbol, String | Array(Int64?) | Array(Int64))
def to_h : Hash(Symbol, String | Array(Int64?))
{
:name => @name,
:coverage => @coverage,
Expand Down
14 changes: 7 additions & 7 deletions src/coverage_reporter/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module CoverageReporter
:head => {
:id => config[:commit_sha]? || head.commit,
:committer_email => head.committer_email,
:committer_name => head.committer_email,
:committer_name => head.committer_name,
:author_email => head.author_email,
:author_name => head.author_name,
:message => head.message,
Expand All @@ -26,27 +26,27 @@ module CoverageReporter
@info : Array(String)?

def commit
ENV["GIT_ID"]? || info[0].presence
ENV["GIT_ID"]? || info[0]?.presence
end

def author_name
ENV["GIT_AUTHOR_NAME"]? || info[1].presence
ENV["GIT_AUTHOR_NAME"]? || info[1]?.presence
end

def author_email
ENV["GIT_AUTHOR_EMAIL"]? || info[2].presence
ENV["GIT_AUTHOR_EMAIL"]? || info[2]?.presence
end

def committer_name
ENV["GIT_COMMITTER_NAME"]? || info[3].presence
ENV["GIT_COMMITTER_NAME"]? || info[3]?.presence
end

def committer_email
ENV["GIT_COMMITTER_EMAIL"]? || info[4].presence
ENV["GIT_COMMITTER_EMAIL"]? || info[4]?.presence
end

def message
ENV["GIT_MESSAGE"]? || info[5].presence
ENV["GIT_MESSAGE"]? || info[5]?.presence
end

# Returns git-related info about the HEAD.
Expand Down
4 changes: 0 additions & 4 deletions src/coverage_reporter/parsers/lcov_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ module CoverageReporter
def initialize(@base_path : String?)
end

# Use *base_path* to join with paths found in reports.
def initialize(@base_path : String?)
end

def globs : Array(String)
[
"*.lcov",
Expand Down
7 changes: 3 additions & 4 deletions src/coverage_reporter/parsers/simplecov_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module CoverageReporter
#
# See: [https://github.com/simplecov-ruby/simplecov](https://github.com/simplecov-ruby/simplecov)
class SimplecovParser < BaseParser
alias Coverage = Array(Int32?)
alias Stats = Hash(String, Array(Int32?))
alias Timestamp = Int32
alias Coverage = Array(Int64?)
alias Stats = Hash(String, Array(Int64?))
alias Timestamp = Int64
alias FileStats = Hash(String, Coverage | Stats)
alias SimplecovFormat = Hash(String, Hash(String, FileStats | Timestamp))

Expand All @@ -30,7 +30,6 @@ module CoverageReporter
data.each do |_service, output|
output["coverage"].as(FileStats).each do |name, info|
coverage = [] of Int64?
branches = [] of Int64?

case info
when Coverage
Expand Down

0 comments on commit 9f9288a

Please sign in to comment.