diff --git a/README.md b/README.md index 4897fd8..a56273a 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,82 @@ # DBXCResultParser-Sonar -`DBXCResultParser-Sonar` is a Swift Package Manager tool designed to convert Xcode's test result files (`.xcresult`) into Sonar Generic Test Execution Report format (`.xml`). It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud. +The `DBXCResultParser-Sonar` package provides a Swift module for parsing `.xcresult` files generated by Xcode to produce [Sonar Generic Test Execution Report](https://docs.sonarsource.com/sonarqube/9.8/analyzing-source-code/test-coverage/generic-test-data/#generic-test-execution) `.xml`. It can be integrated into your CI/CD pipeline to enhance the visibility of test results in SonarQube or SonarCloud. -## Installation - -### As a Dependency - -To use `DBXCResultParser-Sonar` as a dependency in your project, add it to the dependencies in your `Package.swift` file: - -```swift -dependencies: [ - .package(url: "https://github.com/dodobrands/DBXCResultParser-Sonar.git", from: "1.0.0") -] -``` - -Then import `DBXCResultParser-Sonar` in your Swift files where you want to use it: - -```swift -import DBXCResultParserSonar -``` +## Usage ### As a Command Line Tool You can use `DBXCResultParser-Sonar` as a command line tool in two ways: 1. **Prebuilt Binary from Xcode Archive**: - Download the prebuilt binary from the [Releases](https://github.com/dodobrands/DBXCResultParser-Sonar/releases) page on the project's GitHub repository. + 1. Clone repo + 2. Open in Xcode + 3. Product → Archive + 4. Distribute Content → Built Products + 5. Run exported binary: + ```bash + ./DBXCResultParser-Sonar --xcresult-path --tests-path + ``` 2. **Using Swift Run**: + Clone the repository and run the tool using the Swift Package Manager: ```bash git clone https://github.com/dodobrands/DBXCResultParser-Sonar.git cd DBXCResultParser-Sonar - swift run DBXCResultParser-Sonar + swift run DBXCResultParser-Sonar --xcresult-path --tests-path + ``` + +#### Saving .xml report to file + +You can save report in two ways: + +1. **Using `>` operator**: + + Append `>` at the end of any bash command to redirect it's output into file. + ```bash + ./DBXCResultParser-Sonar --xcresult-path --tests-path > sonar-test-report.xml + ``` + +2. **Using `--output-path` option**: + + Specify option for resulting file. May be useful when you've provided `--verbode` flag so that it's logs won't conflict with output `.xml`. + ```bash + ./DBXCResultParser-Sonar --xcresult-path --tests-path --output-path ``` -## Usage ### As a Dependency -Create an instance of `SonarGenericTestExecutionReportFormatter` and use it to generate the `.xml` report: +To use `DBXCResultParser-Sonar` in your Swift package, add it to the dependencies for your `Package.swift` file: ```swift -let formatter = SonarGenericTestExecutionReportFormatter() -// Use formatter to generate the report +let package = Package( + name: "YourPackageName", + dependencies: [ + .package(url: "https://github.com/dodobrands/DBXCResultParser-Sonar", .upToNextMajor(from: "1.0.0")) + ], + targets: [ + .target( + name: "YourTargetName", + dependencies: ["DBXCResultParser"] + ) + ] +) ``` -### As a Command Line Tool +To parse an `.xcresult` file and access the report data, initialize a `DBXCReportModel` with the path to the `.xcresult` file: -To generate a Sonar Generic Test Execution Report from the command line, use the following command: +```swift +import DBXCResultParser_Sonar -```bash -swift run DBXCResultParser-Sonar --xcresult-path path/to/tests.xcresult --tests-path path/to/test-files > report.xml +let xcresultPath = URL(fileURLWithPath: "/path/to/your.xcresult") +let reportModel = try DBXCReportModel(xcresultPath: xcresultPath) +let formatter = SonarGenericTestExecutionReportFormatter() +let result = try formatter.sonarTestReport(from: reportModel) ``` -Replace `path/to/tests.xcresult` with the path to your `.xcresult` file and `path/to/test-files` with the path to your test files. ## Contributing @@ -63,5 +84,4 @@ Contributions are welcome! Please feel free to submit a pull request or open an ## License -This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details. -``` \ No newline at end of file +This project is licensed under the Apache License - see the [LICENSE](LICENSE) file for details. \ No newline at end of file