@@ -31,15 +31,37 @@ jobs:
31
31
shell : bash
32
32
run : cat lint-result.json
33
33
34
- - name : Count Errors and Warnings
35
- id : count-errors-and-warnings
34
+ - name : Transform lint results into grouped JSON
36
35
run : |
37
- ERRORS=$(jq '[.[] | select(.severity == 0)] | length' lint-result.json)
38
- WARNINGS=$(jq '[.[] | select(.severity == 1)] | length' lint-result.json)
39
- echo "errors=$ERRORS" >> $GITHUB_OUTPUT
40
- echo "warnings=$WARNINGS" >> $GITHUB_OUTPUT
41
- echo "Found $ERRORS errors and $WARNINGS warnings."
42
- shell : bash
36
+ # Get the unique source file paths from lint-result.json
37
+ sources=$(jq -r '.[].source' lint-result.json | sort -u)
38
+
39
+ # Initialize an empty array to hold our row objects
40
+ rows_array=()
41
+
42
+ # Iterate over each unique source
43
+ while IFS= read -r src; do
44
+ echo "Processing spec file: $src"
45
+
46
+ # Extract the service name from the YAML file (using yq)
47
+ service=$(yq e '.info.title' "$src")
48
+
49
+ # Filter lint-result.json for entries with this source and map each to {rule, severity}
50
+ results=$(jq --arg src "$src" '[.[] | select(.source == $src) | {rule: .code, severity: .severity}]' lint-result.json)
51
+
52
+ # Build a row JSON object with the extracted service name and the result array
53
+ row=$(jq -n --arg service "$service" --argjson results "$results" '{json: {service: $service, result: $results}}')
54
+
55
+ # Append the row to our rows_array
56
+ rows_array+=("$row")
57
+ done <<< "$sources"
58
+
59
+ # Combine all rows into the final JSON structure
60
+ combined=$(printf '%s\n' "${rows_array[@]}" | jq -s '{rows: .}')
61
+
62
+ # Write the output to a file (or you could use it further in your workflow)
63
+ echo "$combined" > transformed.json
64
+ cat transformed.json
43
65
44
66
- id : login-gcp
45
67
if : false # disabled for now
0 commit comments