Skip to content

Commit

Permalink
adds new flag for output file
Browse files Browse the repository at this point in the history
  • Loading branch information
Heitor Araujo committed Oct 26, 2021
1 parent c84a60b commit 952db57
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 28 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,28 @@ $ npm install -g sfdx-ci-reports
$ sfdx COMMAND
running command...
$ sfdx (-v|--version|version)
sfdx-ci-reports/0.0.1 darwin-x64 node-v15.6.0
sfdx-ci-reports/0.0.2 darwin-x64 node-v15.6.0
$ sfdx --help [COMMAND]
USAGE
$ sfdx COMMAND
...
```
<!-- usagestop -->
<!-- commands -->
* [`sfdx sfci:coverage -i <string> -r <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sfcicoverage--i-string--r-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx sfci:report [-i <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sfcireport--i-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx sfci:coverage -i <string> -r <string> -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sfcicoverage--i-string--r-string--f-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)
* [`sfdx sfci:report -f <string> [-i <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`](#sfdx-sfcireport--f-string--i-string--u-string---apiversion-string---json---loglevel-tracedebuginfowarnerrorfataltracedebuginfowarnerrorfatal)

## `sfdx sfci:coverage -i <string> -r <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
## `sfdx sfci:coverage -i <string> -r <string> -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

```
USAGE
$ sfdx sfci:coverage -i <string> -r <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel
$ sfdx sfci:coverage -i <string> -r <string> -f <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-f, --outputfile=outputfile (required) Output file for the
generated report
-i, --id=id (required) name to print
-r, --result=result (required) Result format (cobertura
Expand All @@ -58,16 +61,19 @@ OPTIONS
this command invocation
```

_See code: [src/commands/sfci/coverage.ts](https://github.com/hsaraujo/sfdx-ci-reports/blob/v0.0.1/src/commands/sfci/coverage.ts)_
_See code: [src/commands/sfci/coverage.ts](https://github.com/hsaraujo/sfdx-ci-reports/blob/v0.0.2/src/commands/sfci/coverage.ts)_

## `sfdx sfci:report [-i <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`
## `sfdx sfci:report -f <string> [-i <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]`

```
USAGE
$ sfdx sfci:report [-i <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
$ sfdx sfci:report -f <string> [-i <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-f, --outputfile=outputfile (required) Output file for the
generated report
-i, --id=id name to print
-u, --targetusername=targetusername username or alias for the target
Expand All @@ -82,7 +88,7 @@ OPTIONS
this command invocation
```

_See code: [src/commands/sfci/report.ts](https://github.com/hsaraujo/sfdx-ci-reports/blob/v0.0.1/src/commands/sfci/report.ts)_
_See code: [src/commands/sfci/report.ts](https://github.com/hsaraujo/sfdx-ci-reports/blob/v0.0.2/src/commands/sfci/report.ts)_
<!-- commandsstop -->
<!-- debugging-your-plugin -->
# Debugging your plugin
Expand Down
3 changes: 2 additions & 1 deletion messages/org.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"nameFlagDescription": "name to print",
"forceFlagDescription": "example boolean flag",
"errorNoOrgResults": "No results found for the org '%s'.",
"resultsFlagDescription": "Result format (cobertura | jacoco)"
"resultsFlagDescription": "Result format (cobertura | jacoco)",
"outputFile": "Output file for the generated report"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sfdx-ci-reports",
"description": "Reports for Salesforce CI/CD",
"version": "0.0.1",
"version": "0.0.2",
"author": "Heitor Araujo",
"bugs": "https://github.com/hsaraujo/sfdx-ci-reports/issues",
"dependencies": {
Expand Down
9 changes: 5 additions & 4 deletions src/commands/sfci/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ export default class Coverage extends SfdxCommand {
protected static flagsConfig = {
// flag with a value (-n, --name=VALUE)
id: flags.string({char: 'i', required: true, description: messages.getMessage('nameFlagDescription')}),
result : flags.string({char: 'r', required: true, description: messages.getMessage('resultsFlagDescription')})
result : flags.string({char: 'r', required: true, description: messages.getMessage('resultsFlagDescription')}),
outputfile: flags.string({char: 'f', required: true, description: messages.getMessage('outputFile')})
};

public async run(): Promise<any> {

this.exec(`mkdir -p test-reports`, {});
// this.exec(`mkdir -p test-reports`, {});
// this.ux.log(this.flags.targetusername)
const deployReportJson = this.exec(`sfdx force:source:deploy:report -i ${this.flags.id} -u ${this.flags.targetusername} --json`, {trim: true});

const deployReport: DeployReport = JSON.parse(deployReportJson)

if(this.flags.result == 'cobertura')
new CoberturaReporter().generate(deployReport);
new CoberturaReporter().generate(deployReport, { outputFile : this.flags.outputfile });
else if(this.flags.result == 'jacoco')
new JacocoReporter().generate(deployReport);
new JacocoReporter().generate(deployReport, { outputFile : this.flags.outputfile });

}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/sfci/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export default class Report extends SfdxCommand {

protected static flagsConfig = {
// flag with a value (-n, --name=VALUE)
id: flags.string({char: 'i', description: messages.getMessage('nameFlagDescription')})
id: flags.string({char: 'i', description: messages.getMessage('nameFlagDescription')}),
outputfile: flags.string({char: 'f', required: true, description: messages.getMessage('outputFile')})
};

public async run(): Promise<any> {

this.exec(`mkdir -p test-reports`, {});
// this.ux.log(this.flags.targetusername)
const deployReportJson = this.exec(`sfdx force:source:deploy:report -i ${this.flags.id} -u ${this.flags.targetusername} --json`, {trim: true});

Expand Down Expand Up @@ -86,7 +86,7 @@ export default class Report extends SfdxCommand {
}
});

fs.writeFileSync(`test-reports/${this.flags.id}-junit.xml`, xml);
fs.writeFileSync(this.flags.outputfile, xml);

}

Expand Down
4 changes: 4 additions & 0 deletions src/models/deploy/reportOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ReportOption {

outputFile: string;
}
12 changes: 5 additions & 7 deletions src/reporters/coberturaReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ import * as xml2js from 'xml2js';
import { BuilderOptions } from 'xml2js'
import * as fs from 'fs';
import CodeCoverage from "../models/deploy/codeCoverage";
import { ReportOption } from "../models/deploy/reportOption";

export default class CoberturaReporter implements IReporter{

generate(deployReport: DeployReport): void {
generate(deployReport: DeployReport, options: ReportOption): void {

const options: BuilderOptions = {
const builderOptions: BuilderOptions = {
doctype: { 'sysID' : 'http://cobertura.sourceforge.net/xml/coverage-04.dtd'},
xmldec: {'version': '1.0', 'encoding': 'UTF-8'}
};

const builder = new xml2js.Builder(options);
const builder = new xml2js.Builder(builderOptions);

const xml = builder.buildObject({
'coverage': {
$ : this.coverageAttributes(deployReport),
'sources': {
'source': '/home/vsts/work/1/s/test-reports'
},
'packages': {
'package': {
$ : this.packageAttributes(deployReport),
Expand All @@ -33,7 +31,7 @@ export default class CoberturaReporter implements IReporter{
}
});

fs.writeFileSync(`test-reports/coverage-cobertura.xml`, xml);
fs.writeFileSync(options.outputFile, xml);

}

Expand Down
3 changes: 2 additions & 1 deletion src/reporters/ireporter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DeployReport } from "../models/deploy/deployReport";
import { ReportOption } from "../models/deploy/reportOption";

export default interface IReporter {

generate(deployReport: DeployReport): void;
generate(deployReport: DeployReport, options: ReportOption): void;
}
5 changes: 3 additions & 2 deletions src/reporters/jacocoReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { DeployReport } from "../models/deploy/deployReport";
import IReporter from "./ireporter";
import * as xml2js from 'xml2js';
import * as fs from 'fs';
import { ReportOption } from "../models/deploy/reportOption";

export default class JacocoReporter implements IReporter{

generate(deployReport: DeployReport): void {
generate(deployReport: DeployReport, options: ReportOption): void {

let sourceFiles = [];
let totalLinesCovered: number = 0;
Expand Down Expand Up @@ -63,7 +64,7 @@ export default class JacocoReporter implements IReporter{
}
});

fs.writeFileSync(`test-reports/coverage-jacoco.xml`, xml);
fs.writeFileSync(options.outputFile, xml);

}

Expand Down

0 comments on commit 952db57

Please sign in to comment.