@@ -80,39 +80,33 @@ jobs:
8080 # Generate comment with Markdown table of added error codes:
8181 - name : ' Generate comment body with Markdown table of added error codes'
8282 run : |
83- # Get the diff of the CSV file:
84- git_diff=$(git diff lib/node_modules/@stdlib/error/tools/database/data/data.csv)
83+ # Save the added lines from the diff to a temporary file:
84+ git diff lib/node_modules/@stdlib/error/tools/database/data/data.csv | grep '^+' | grep -v '^\+\+' | sed 's/^+//' > /tmp/diff.csv
85+
86+ # Convert the CSV file to a TSV file (and drop first line and double quotes):
87+ awk -F '",' 'NR > 1 && !/^++/ { gsub(/^"|"$/, "", $1); gsub(/^"|"$/, "", $2); gsub(/^"|"$/, "", $3); print $1 "\t" $2 "\t" $3 }' /tmp/diff.csv > /tmp/diff.tsv
8588
8689 # Create the Markdown table header:
8790 table="| Code | Error Message | Type |\n|--------|---------------|------|\n"
8891
8992 # Extract added lines from the diff and append them to the Markdown table:
90- while IFS= read -r line ; do
93+ while IFS=$'\t' read -r code error_message type ; do
9194 # Check if the table length exceeds a maximum length:
9295 if [ ${#table} -gt 65000 ]; then
9396 table+="| ... | ... | ... |\nThis table has been truncated due to GitHub's comment character limit.\n"
9497 break
9598 fi
96-
97- # Check if the line starts with '+', indicating it's an added line:
98- if [[ $line == +* ]]; then
99- # Remove the '+' symbol:
100- line="${line#+}"
101- # Check if the line is not part of the CSV header:
102- if [[ $line != \"Code\"* ]]; then
103- # Split the CSV row into fields and format it as a Markdown table row:
104- IFS=',' read -ra fields <<< "$line"
105- table+="| ${fields[0]} | ${fields[1]} | ${fields[2]} |\n"
106- fi
107- fi
108- done <<< "$git_diff"
10999
110- # Remove double quotes from the Markdown table:
111- table="${table//\"/}"
100+ # Append the TSV row to the Markdown table:
101+ table+="| ${code} | ${error_message} | ${type} |\n"
102+ done < /tmp/diff.tsv
112103
113104 # Generate a comment body:
114105 body="This PR\n\n- updates the error databases\n\nThe following error codes were added:\n\n${table}"
115106
107+ # Escape '%' characters, which are interpreted as format specifiers by `printf`:
108+ body="${body//%/%%}"
109+
116110 # Write the comment body to a temporary file:
117111 printf "$body" > /tmp/body.md
118112 shell : bash
0 commit comments