Skip to content

Commit

Permalink
Merge 163fcb2 into f5bfe91
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Jun 7, 2023
2 parents f5bfe91 + 163fcb2 commit a0917e1
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 92 deletions.
61 changes: 41 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,60 +49,81 @@ Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releas

```bash
# Automatic lookup for supported reports and sending them to https://coveralls.io
coveralls
coveralls report

# Provide explicit repo token
coveralls --repo-token=rg8ZznwNq05g3HDfknodmueeRciuiiPDE
coveralls report --repo-token=rg8ZznwNq05g3HDfknodmueeRciuiiPDE

# Use concrete report file
coveralls --file coverage/lcov.info
coveralls report coverage/lcov.info

# Use parallel reports
coveralls --file project1/coverage/lcov.info --parallel
coveralls --file project2/coverage/lcov.info --parallel
# Use parallel reports (must reference the same build number)
coveralls report project1/coverage/lcov.info --parallel --build-number 1
coveralls report project2/coverage/lcov.info --parallel --build-number 1
# ...
coveralls --done
coveralls done --build-number 1

# Provide a job flag and use carry-forwarding
coveralls --job-flag "unit-tests" --parallel
coveralls --job-flag "integration-tests" --parallel
coveralls --done --carryforward "unit-tests,integration-tests"
coveralls report --job-flag "unit-tests" --parallel --build-number 2
coveralls report --job-flag "integration-tests" --parallel --build-number 2
coveralls done --carryforward "unit-tests,integration-tests" --build-number 2

# Testing options: no real reporting, print payload
coveralls --debug --dry-run
coveralls report --debug --dry-run
```

<details>
<summary>For more options see <code>coveralls -h/--help</code></summary>

```
$ coveralls -h
Coveralls Coverage Reporter v0.3.3
Usage: coveralls [options]
Usage: coveralls [command] [options]
report Report coverage
done Close a parallel build
version Print version
--debug Debug mode: data being sent to Coveralls will be printed to console
--dry-run Dry run (no request sent)
-n, --no-logo Do not show Coveralls logo in logs
-q, --quiet Suppress all output
-h, --help Show this help
-rTOKEN, --repo-token=TOKEN Sets coveralls repo token, overrides settings in yaml or environment variable
-cPATH, --config-path=PATH Set the coveralls yaml config file location, will default to check '.coveralls.yml'
-bPATH, --base-path=PATH Path to the root folder of the project the coverage was collected in
-fFILENAME, --file=FILENAME Coverage artifact file to be reported, e.g. coverage/lcov.info (detected by default)
-jFLAG, --job-flag=FLAG Coverage job flag name, e.g. Unit Tests
-p, --parallel Set the parallel flag. Requires webhook for completion (coveralls --done)
-d, --done Call webhook after all parallel jobs (-p) done
$ coveralls report -h
Usage: coveralls report [file reports] [options]
--debug Debug mode: data being sent to Coveralls will be printed to console
--dry-run Dry run (no request sent)
-n, --no-logo Do not show Coveralls logo in logs
-q, --quiet Suppress all output
-h, --help Show this help
-rTOKEN, --repo-token=TOKEN Sets coveralls repo token, overrides settings in yaml or environment variable
-cPATH, --config-path=PATH Set the coveralls yaml config file location, will default to check '.coveralls.yml'
--build-number=ID Build number
-bPATH, --base-path=PATH Path to the root folder of the project the coverage was collected in
-jFLAG, --job-flag=FLAG Coverage job flag name, e.g. Unit Tests
-p, --parallel Set the parallel flag. Requires webhook for completion (coveralls done)
--format=FORMAT Force coverage file format, supported formats: lcov, simplecov, cobertura, jacoco, gcov, golang, python
--allow-empty Allow empty coverage results and exit 0
--compare-ref=REF Git branch name to compare the coverage with
--compare-sha=SHA Git commit SHA to compare the coverage with
--carryforward=FLAGS Comma-separated list of parallel job flags
--service-name=NAME Build service name override
--service-job-id=ID Build job override
--service-build-url=URL Build URL override
--service-job-url=URL Build job URL override
--service-branch=NAME Branch name override
--service-pull-request=NUMBER PR number override
$ coveralls done -h
Usage: coveralls done [options]
--debug Debug mode: data being sent to Coveralls will be printed to console
--dry-run Dry run (no request sent)
-v, --version Show version
-n, --no-logo Do not show Coveralls logo in logs
-q, --quiet Suppress all output
-h, --help Show this help
-rTOKEN, --repo-token=TOKEN Sets coveralls repo token, overrides settings in yaml or environment variable
-cPATH, --config-path=PATH Set the coveralls yaml config file location, will default to check '.coveralls.yml'
--carryforward=FLAGS Comma-separated list of parallel job flags
--build-number=ID Build number
```

</details>
Expand Down
84 changes: 81 additions & 3 deletions spec/coverage_reporter/cli/cmd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@ Spectator.describe CoverageReporter::Cli do
})
end

it "parses overrides" do
reporter = subject.run %w(
report
--parallel
-j super-flag
--base-path src/*
--service-name=service-name
--service-job-id=job-id
--service-build-url=build-url
--service-job-url=job-url
--service-branch=branch
--service-pull-request=pr
--build-number=build-number
--compare-ref=develop
--dry-run
)

expect(reporter.job_flag_name).to eq "super-flag"
expect(reporter.parallel).to eq true
expect(reporter.compare_ref).to eq "develop"
expect(reporter.dry_run).to eq true
expect(reporter.base_path).to eq "src/*"
expect(reporter.overrides.try(&.to_h)).to eq({
:service_name => "service-name",
:service_number => "build-number",
:service_job_id => "job-id",
:service_build_url => "build-url",
:service_job_url => "job-url",
:service_branch => "branch",
:service_pull_request => "pr",
})
end

it "doesn't apply empty values as overrides" do
reporter = subject.run %w(
--service-name=
Expand Down Expand Up @@ -49,11 +82,25 @@ Spectator.describe CoverageReporter::Cli do

it "accepts --carryforward option" do
reporter = subject.run %w(
--carryforward "1,2,3"
--carryforward 1,2,3
--dry-run
)

expect(reporter.carryforward).to eq "\"1,2,3\""
expect(reporter.carryforward).to eq "1,2,3"
end

it "accepts --carryforward option" do
reporter = subject.run %w(
done
--build-number 3
--carryforward 1,2,3
--dry-run
)

expect(reporter.carryforward).to eq "1,2,3"
expect(reporter.overrides.try(&.to_h)).to eq({
:service_number => "3",
})
end

it "accepts --format option" do
Expand All @@ -71,7 +118,38 @@ Spectator.describe CoverageReporter::Cli do
--dry-run
)

expect(reporter.coverage_file).to eq "spec/fixtures/lcov/test.lcov"
expect(reporter.coverage_files).to eq ["spec/fixtures/lcov/test.lcov"]
end

it "reports multiple files" do
reporter = subject.run %w(
report
spec/fixtures/lcov/test.lcov
spec/fixtures/lcov/test.lcov
spec/fixtures/lcov/empty.lcov
--dry-run
)

expect(reporter.coverage_files).to eq [
"spec/fixtures/lcov/test.lcov",
"spec/fixtures/lcov/empty.lcov",
]
end

it "reports multiple files after --" do
reporter = subject.run %w(
report
--dry-run
--
spec/fixtures/lcov/test.lcov
spec/fixtures/lcov/test.lcov
spec/fixtures/lcov/empty.lcov
)

expect(reporter.coverage_files).to eq [
"spec/fixtures/lcov/test.lcov",
"spec/fixtures/lcov/empty.lcov",
]
end
end
end
14 changes: 7 additions & 7 deletions spec/coverage_reporter/parser_spec.cr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require "../spec_helper"

Spectator.describe CoverageReporter::Parser do
subject { described_class.new(coverage_file, coverage_format, base_path) }
subject { described_class.new(coverage_files, coverage_format, base_path) }

let(coverage_file) { nil }
let(coverage_files) { nil }
let(coverage_format) { nil }
let(base_path) { nil }

describe "#parse" do
context "for exact file" do
let(coverage_file) { "spec/fixtures/lcov/test.lcov" }
let(coverage_files) { ["spec/fixtures/lcov/test.lcov"] }

it "returns reports for one file" do
reports = subject.parse
Expand All @@ -18,7 +18,7 @@ Spectator.describe CoverageReporter::Parser do
end

context "for non-existing file" do
let(coverage_file) { "spec/fixtures/oops/coverage" }
let(coverage_files) { ["spec/fixtures/oops/coverage"] }

it "raises error" do
expect { subject.parse }
Expand All @@ -27,7 +27,7 @@ Spectator.describe CoverageReporter::Parser do
end

context "for an unknown file format" do
let(coverage_file) { "spec/fixtures/lcov/test.js" }
let(coverage_files) { ["spec/fixtures/lcov/test.js"] }

it "returns reports for one file" do
reports = subject.parse
Expand All @@ -46,7 +46,7 @@ Spectator.describe CoverageReporter::Parser do
end

context "when a file is specified" do
let(coverage_file) { "spec/fixtures/lcov/for-base-path-lcov" }
let(coverage_files) { ["spec/fixtures/lcov/for-base-path-lcov"] }
let(base_path) { "spec/fixtures/lcov" }

it "returns report only for specified file" do
Expand All @@ -57,7 +57,7 @@ Spectator.describe CoverageReporter::Parser do
end

context "when another format file specified" do
let(coverage_file) { "spec/fixtures/gcov/main.c.gcov" }
let(coverage_files) { ["spec/fixtures/gcov/main.c.gcov"] }

it "returns empty report" do
reports = subject.parse
Expand Down
6 changes: 3 additions & 3 deletions spec/coverage_reporter/reporter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Spectator.describe CoverageReporter::Reporter do
compare_ref: compare_ref,
compare_sha: compare_sha,
config_path: config_path,
coverage_file: coverage_file,
coverage_files: coverage_files,
coverage_format: coverage_format,
dry_run: false,
fail_empty: fail_empty,
Expand All @@ -24,7 +24,7 @@ Spectator.describe CoverageReporter::Reporter do
let(compare_ref) { nil }
let(compare_sha) { nil }
let(config_path) { nil }
let(coverage_file) { nil }
let(coverage_files) { nil }
let(coverage_format) { nil }
let(fail_empty) { true }
let(job_flag_name) { nil }
Expand Down Expand Up @@ -73,7 +73,7 @@ Spectator.describe CoverageReporter::Reporter do
end

context "when report is empty" do
let(coverage_file) { "spec/fixtures/lcov/empty.lcov" }
let(coverage_files) { ["spec/fixtures/lcov/empty.lcov"] }

it "raises NoSourceFiles" do
expect { subject.report }
Expand Down
16 changes: 14 additions & 2 deletions src/coverage_reporter/api/jobs.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ module CoverageReporter
@source_files : SourceFiles,
@git_info : Hash(Symbol, Hash(Symbol, String) | String)
)
service_number = @config.to_h[:service_number]?
if @parallel
Log.info "⭐️ Running in parallel mode. " \
"You must call the webhook after all jobs finish: `coveralls --done`"
Log.info(
String.build do |io|
io << "⭐️ Running in parallel mode. "
if service_number
io << "You must call the webhook after all jobs finish: `coveralls done --build-number #{service_number}`"
end
end
)
unless service_number
Log.warn("⚠️ You won't be able to close the build because build number is empty.\n" \
"⚠️ Provide --build-number option or COVERALLS_SERVICE_NUMBER environment variable to " \
"create parallel jobs for one build and be able to close it.")
end
end
end

Expand Down
Loading

0 comments on commit a0917e1

Please sign in to comment.