Skip to content

Commit f25fa00

Browse files
authored
Merge pull request #27 from mariozig/master
Add a summaryJson reporter
2 parents 687fc8f + 0c2ac55 commit f25fa00

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This is an example of a report created from the Build Log of the [Kickstarter iO
1515
`XCLogParser` is written as a [SPM](https://github.com/apple/swift-package-manager/) executable and it supports three commands:
1616

1717
1. [Dump](#dump-command) the contents of an `xcactivitylog` into a `JSON` document.
18-
2. [Parse](#parse-command) the contents of an `xcactivitylog` into different kind of reports (`json`, `flatJson`, `chromeTracer` and `html`).
18+
2. [Parse](#parse-command) the contents of an `xcactivitylog` into different kind of reports (`json`, `flatJson`, `summaryJson`, `chromeTracer` and `html`).
1919
3. Dump the [Manifest](#manifest-command) contents of a `LogStoreManifest.plist` file into a `JSON` document.
2020

2121
Depending on your needs, there are various use-cases where `XCLogParser` can help you:
@@ -93,7 +93,7 @@ An example output has been omitted for brevity since it can contain a lot of inf
9393

9494
### Parse Command
9595

96-
Parses the build information from a `xcactivitylog` and converts it into different representations such as a [JSON file](#JSON-Reporter), [flat JSON file](#FlatJson-Reporter), [Chrome Tracer file](#ChromeTracer-Reporter) or a static [HTML page](#HTML-Reporter).
96+
Parses the build information from a `xcactivitylog` and converts it into different representations such as a [JSON file](#JSON-Reporter), [flat JSON file](#FlatJson-Reporter), [summary JSON file](#SummaryJson-Reporter), [Chrome Tracer file](#ChromeTracer-Reporter) or a static [HTML page](#HTML-Reporter).
9797

9898
Examples:
9999

@@ -110,7 +110,7 @@ Example output available in the [reporters](#reporters) section.
110110

111111
| Parameter Name | Description | Required |
112112
|-----|---|-----|
113-
| `--reporter` | The reporter used to transform the logs. It can be either `json`, `flatJson`, `chromeTracer` or `html`. (required) | Yes |
113+
| `--reporter` | The reporter used to transform the logs. It can be either `json`, `flatJson`, `summaryJson`, `chromeTracer` or `html`. (required) | Yes |
114114
| `--file` | The path to the `xcactivitylog`. | No * |
115115
| `--project` | The name of the project if you don't know the path to the log. The tool will try to find the latest Build log in a folder that starts with that name inside the `DerivedData` directory. | No * |
116116
| `--workspace` | The path to the `xcworkspace` file if you don't know the path to the log. It will generate the folder name for the project in the `DerivedData` folder using Xcode's hash algorithm and it will try to locate the latest Build Log inside that directory. | No * |
@@ -169,6 +169,7 @@ The [parse command](#parse-command) has different types of reporters built-in th
169169

170170
- [JSON](#json-reporter)
171171
- [Flat JSON](#flatojson-reporter)
172+
- [Summary JSON](#summaryjson-reporter)
172173
- [Chrome Tracer](#chrometracer-reporter)
173174
- [HTML](#html-reporter)
174175

@@ -317,6 +318,50 @@ xclogparser parse --file path/to/log.xcactivitylog --reporter flatJson
317318
```
318319
</details>
319320

321+
For more information regarding each field, check out the [JSON format documentation](https://github.com/spotify/XCLogParser/blob/master/docs/JSON%20Format.md).
322+
323+
### SummaryJson Reporter
324+
325+
Parses the log as a JSON object, with no nested steps (the field `subSteps` is always empty). Useful to get a high level summary of the build.
326+
327+
Example:
328+
329+
```bash
330+
xclogparser parse --file path/to/log.xcactivitylog --reporter summaryJson
331+
```
332+
333+
<details>
334+
<summary>Example Output</summary>
335+
336+
```json
337+
{
338+
"parentIdentifier" : "",
339+
"title" : "Build MobiusCore",
340+
"warningCount" : 0,
341+
"duration" : 0,
342+
"startTimestamp" : 1558590748,
343+
"signature" : "Build MobiusCore",
344+
"endDate" : "2019-05-23T05:52:28.274000Z",
345+
"errorCount" : 0,
346+
"domain" : "Xcode.IDEActivityLogDomainType.BuildLog",
347+
"type" : "main",
348+
"identifier" : "68a2bbd0048a454d91b3734b5d5dc45e_1558640253_1",
349+
"buildStatus" : "succeeded",
350+
"schema" : "MobiusCore",
351+
"subSteps" : [
352+
353+
],
354+
"endTimestamp" : 1558590748,
355+
"architecture" : "",
356+
"machineName" : "68a2bbd0048a454d91b3734b5d5dc45e",
357+
"buildIdentifier" : "68a2bbd0048a454d91b3734b5d5dc45e_1558640253",
358+
"startDate" : "2019-05-23T05:52:28.244000Z",
359+
"documentURL" : "",
360+
"detailStepType" : "none"
361+
}
362+
```
363+
</details>
364+
320365

321366
For more information regarding each field, check out the [JSON format documentation](https://github.com/spotify/XCLogParser/blob/master/docs/JSON%20Format.md).
322367

Sources/XCLogParser/parser/BuildStep.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,9 @@ public extension BuildStep {
257257
return details
258258
}
259259

260+
func summarize() -> BuildStep {
261+
var noSubSteps = self
262+
noSubSteps.subSteps = [BuildStep]()
263+
return noSubSteps
264+
}
260265
}

Sources/XCLogParser/reporter/Reporter.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Foundation
33
public enum Reporter: String {
44
case json
55
case flatJson
6+
case summaryJson
67
case chromeTracer
78
case html
89

@@ -14,6 +15,8 @@ public enum Reporter: String {
1415
return JsonReporter()
1516
case .flatJson:
1617
return FlatJsonReporter()
18+
case .summaryJson:
19+
return SummaryJsonReporter()
1720
case .html:
1821
return HtmlReporter()
1922
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
3+
public struct SummaryJsonReporter: LogReporter {
4+
5+
public func report(build: Any, output: ReporterOutput) throws {
6+
guard let steps = build as? BuildStep else {
7+
throw Error.errorCreatingReport("Type not supported \(type(of: build))")
8+
}
9+
let encoder = JSONEncoder()
10+
encoder.outputFormatting = .prettyPrinted
11+
let json = try encoder.encode(steps.summarize())
12+
try output.write(report: json)
13+
}
14+
15+
}

0 commit comments

Comments
 (0)