Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files exist flag for coverage publish #1491

Open
wants to merge 3 commits into
base: main
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
6 changes: 6 additions & 0 deletions qlty-cli/src/commands/coverage/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ pub struct Publish {

// Paths to coverage reports
pub paths: Vec<String>,

#[arg(long)]
/// Check if the files in the coverage report actually exist on the file system
pub files_exist: bool,
}

impl Publish {
Expand Down Expand Up @@ -108,6 +112,7 @@ impl Publish {
tag: self.tag.clone(),
report_format: self.report_format,
paths: self.paths.clone(),
files_exist: self.files_exist,
},
)
.compute()?;
Expand Down Expand Up @@ -310,6 +315,7 @@ mod tests {
json: false,
quiet: true,
paths: vec![],
files_exist: false,
}
}

Expand Down
1 change: 1 addition & 0 deletions qlty-cli/tests/cmd/coverage/files_exist.in/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
5 changes: 5 additions & 0 deletions qlty-cli/tests/cmd/coverage/files_exist.in/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.qlty/results
.qlty/logs
.qlty/out
.qlty/sources
tmp
76 changes: 76 additions & 0 deletions qlty-cli/tests/cmd/coverage/files_exist.in/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
TN:
SF:src/formatter.js
FN:10,Formatter
FN:14,(anonymous_2)
FN:18,(anonymous_3)
FN:28,(anonymous_4)
FN:31,(anonymous_5)
FN:51,(anonymous_6)
FN:65,(anonymous_7)
FN:68,(anonymous_8)
FN:83,(anonymous_9)
FN:86,(anonymous_10)
FNF:10
FNH:10
FNDA:1,Formatter
FNDA:5,(anonymous_2)
FNDA:2,(anonymous_3)
FNDA:2,(anonymous_4)
FNDA:2,(anonymous_5)
FNDA:2,(anonymous_6)
FNDA:2,(anonymous_7)
FNDA:5,(anonymous_8)
FNDA:5,(anonymous_9)
FNDA:817,(anonymous_10)
DA:1,1
DA:2,1
DA:3,1
DA:4,1
DA:5,1
DA:6,1
DA:7,1
DA:8,1
DA:10,1
DA:11,1
DA:14,1
DA:15,5
DA:18,1
DA:19,2
DA:20,1
DA:21,1
DA:22,1
DA:24,0
DA:28,1
DA:29,2
DA:31,2
DA:32,2
DA:33,0
DA:36,2
DA:46,2
DA:52,2
LF:52
LH:47
BRDA:11,1,0,1
BRDA:11,1,1,0
BRDA:15,2,0,5
BRDA:15,2,1,0
BRDA:19,3,0,1
BRDA:19,3,1,1
BRDA:21,4,0,1
BRDA:21,4,1,0
BRDA:32,5,0,0
BRDA:32,5,1,2
BRDA:52,6,0,0
BRDA:52,6,1,2
BRDA:73,7,0,5
BRDA:73,7,1,0
BRDA:91,8,0,0
BRDA:91,8,1,5
BRF:16
BRH:9
end_of_record
SF:src/doesnt_exist.js
DA:1,1
DA:2,0
DA:5,10
end_of_record
Empty file.
11 changes: 11 additions & 0 deletions qlty-cli/tests/cmd/coverage/files_exist.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
qlty [..] [..]-[..] ([..] debug [..])
https://qlty.sh/d/coverage

Retrieving CI metadata...
→ unknown CI commit "2ca1bc45a94e37c8dbae6fd9e19fc069ba64bd67" on branch ""

Reading code coverage data...
→ Found 1 files with code coverage data

Exporting code coverage data...
→ Exported to "tmp/qlty-coverage"
91 changes: 91 additions & 0 deletions qlty-cli/tests/cmd/coverage/files_exist.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"metadata": {
"buildId": "123",
"ci": "unknown",
"commitSha": "2ca1bc45a94e37c8dbae6fd9e19fc069ba64bd67",
"commitMessage": "initial/n",
"authorName": "TEST",
"authorEmail": "[email protected]",
"authorTime": "2024-01-01T00:00:00+00:00",
"committerName": "TEST",
"committerEmail": "[email protected]",
"commitTime": "2024-01-01T00:00:00+00:00",
"uploadedAt": "[..]",
"cliVersion": "[..]"
},
"report_files": [
{
"buildId": "123",
"format": "lcov",
"path": "lcov.info"
}
],
"file_coverages": [
{
"buildId": "123",
"path": "src/formatter.js",
"summary": {
"covered": "24",
"missed": "2",
"omit": "26",
"total": "52"
},
"hits": [
"1",
"1",
"1",
"1",
"1",
"1",
"1",
"1",
"-1",
"1",
"1",
"-1",
"-1",
"1",
"5",
"-1",
"-1",
"1",
"2",
"1",
"1",
"1",
"-1",
"0",
"-1",
"-1",
"-1",
"1",
"2",
"-1",
"2",
"2",
"0",
"-1",
"-1",
"2",
"-1",
"-1",
"-1",
"-1",
"-1",
"-1",
"-1",
"-1",
"-1",
"2",
"-1",
"-1",
"-1",
"-1",
"-1",
"2"
],
"commitSha": "2ca1bc45a94e37c8dbae6fd9e19fc069ba64bd67",
"uploadedAt": "[..]"
}
]
}
20 changes: 20 additions & 0 deletions qlty-cli/tests/cmd/coverage/files_exist.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
args = [
"coverage",
"publish",
"--dry-run",
"--override-commit-sha",
"2ca1bc45a94e37c8dbae6fd9e19fc069ba64bd67",
"--override-build-id",
"123",
"lcov.info",
"--print",
"--json",
"--files-exist"
]
bin.name = "qlty"

[env]
remove = ["GITHUB_ACTIONS"]

[env.add]
QLTY_COVERAGE_TOKEN = "123"
1 change: 1 addition & 0 deletions qlty-cli/tests/cmd/coverage/ignore_patterns.in/lcov.info
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ BRDA:91,8,0,0
BRDA:91,8,1,5
BRF:16
BRH:9
end_of_record
SF:src/ignore.js
DA:1,1
DA:2,0
Expand Down
6 changes: 6 additions & 0 deletions qlty-coverage/src/publish/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::publish::Settings;
use crate::transformer::AddPrefix;
use crate::transformer::AppendMetadata;
use crate::transformer::ComputeSummary;
use crate::transformer::FileExistanceCheck;
use crate::transformer::IgnorePaths;
use crate::transformer::StripDotSlashPrefix;
use crate::transformer::StripPrefix;
Expand Down Expand Up @@ -145,6 +146,11 @@ impl Planner {
transformers.push(Box::new(AddPrefix::new(&prefix)));
}

// Should be placed after AddPrefix/StripPrefix or any path changes
if self.settings.files_exist {
transformers.push(Box::new(FileExistanceCheck));
}

transformers.push(Box::new(AppendMetadata::new(metadata)));
Ok(transformers)
}
Expand Down
2 changes: 2 additions & 0 deletions qlty-coverage/src/publish/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ pub struct Settings {

pub add_prefix: Option<String>,
pub strip_prefix: Option<String>,

pub files_exist: bool,
}
16 changes: 16 additions & 0 deletions qlty-coverage/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ impl Transformer for StripDotSlashPrefix {
}
}

#[derive(Debug, Clone)]
pub struct FileExistanceCheck;

impl Transformer for FileExistanceCheck {
fn transform(&self, file_coverage: FileCoverage) -> Option<FileCoverage> {
match PathBuf::from(&file_coverage.path).try_exists() {
Ok(true) => Some(file_coverage),
_ => None,
}
}

fn clone_box(&self) -> Box<dyn Transformer> {
Box::new(Self)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading