Skip to content

Commit 2e48a1f

Browse files
committed
fix compatibility for testing on macOS
1 parent ac48c5d commit 2e48a1f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

scripts/prow-vale-review.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ do
6060
fi
6161

6262
# Update conditional markup in place
63-
sed -i 's/ifdef::.*/ifdef::temp-ifdef[]/; s/ifeval::.*/ifeval::["{temp-ifeval}" == "temp"]/; s/ifndef::.*/ifndef::temp-ifndef[]/; s/endif::.*/endif::[]/;' "$FILE"
63+
if [[ "$OSTYPE" == "darwin"* ]]; then
64+
sed -i '' 's/ifdef::.*/ifdef::temp-ifdef[]/; s/ifeval::.*/ifeval::["{temp-ifeval}" == "temp"]/; s/ifndef::.*/ifndef::temp-ifndef[]/; s/endif::.*/endif::[]/;' "$FILE"
65+
else
66+
sed -i 's/ifdef::.*/ifdef::temp-ifdef[]/; s/ifeval::.*/ifeval::["{temp-ifeval}" == "temp"]/; s/ifndef::.*/ifndef::temp-ifndef[]/; s/endif::.*/endif::[]/;' "$FILE"
67+
fi
6468

6569
# Parse for vale errors
6670
vale_json=$(vale --minAlertLevel=error --output=.vale/templates/bot-comment-output.tmpl --config="$INI" "$FILE" | jq)
@@ -113,13 +117,21 @@ do
113117

114118
# Check if there is a comma in the number pairing before @@
115119
if [[ $line =~ \+.*\,.*\ @@ ]]; then
116-
# There are comma separated numbers before closing @@. Grab the number before the comma as the diff_start_line, after the comma is the added_lines.
117-
added_lines=$(echo "$line" | grep -oP '\d+\s+@@' | grep -oP '\d+')
120+
# There are comma separated numbers before closing @@. Grab the number before the comma as the diff_start_line, after the comma is the added_lines.
121+
if [[ "$OSTYPE" == "darwin"* ]]; then
122+
added_lines=$(echo "$line" | grep -oE '[0-9]+[[:space:]]+@@' | grep -oE '[0-9]+')
123+
else
124+
added_lines=$(echo "$line" | grep -oP '\d+\s+@@' | grep -oP '\d+')
125+
fi
118126
diff_start_line=$(echo "$line" | awk -F'+' '{print $2}' | awk -F',' '{print $1}')
119127
else
120128
# There are no comma seperated numbers. Consider the number after the plus as diff_start_line with no added lines - this means there's a modification on a single line
121129
added_lines=0
122-
diff_start_line=$(echo "$line" | grep -oP '\+\d+\s+@@' | grep -oP '\d+')
130+
if [[ "$OSTYPE" == "darwin"* ]]; then
131+
diff_start_line=$(echo "$line" | grep -oE '\+[0-9]+[[:space:]]+@@' | grep -oE '[0-9]+')
132+
else
133+
diff_start_line=$(echo "$line" | grep -oP '\+\d+\s+@@' | grep -oP '\d+')
134+
fi
123135
fi
124136

125137
# If the last_number is 0, disregard the hunk and move to the next hunk as zero lines were modified (deletions only)

0 commit comments

Comments
 (0)