Skip to content

Commit ea303db

Browse files
committed
Linting with locally installed spectral-cli
1 parent 80c6900 commit ea303db

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

.github/workflows/lint.yml

+30-8
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,37 @@ jobs:
3131
shell: bash
3232
run: cat lint-result.json
3333

34-
- name: Count Errors and Warnings
35-
id: count-errors-and-warnings
34+
- name: Transform lint results into grouped JSON
3635
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
4365
4466
- id: login-gcp
4567
if: false #disabled for now

0 commit comments

Comments
 (0)