Skip to content

Commit 4cf9fb2

Browse files
authored
Merge pull request #104106 from jldohmann/update-script-BSD
[prow/ci] fix compatibility for testing on macOS
2 parents 62f8b9e + 2e48a1f commit 4cf9fb2

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)
@@ -120,13 +124,21 @@ do
120124

121125
# Check if there is a comma in the number pairing before @@
122126
if [[ $line =~ \+.*\,.*\ @@ ]]; then
123-
# 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.
124-
added_lines=$(echo "$line" | grep -oP '\d+\s+@@' | grep -oP '\d+')
127+
# 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.
128+
if [[ "$OSTYPE" == "darwin"* ]]; then
129+
added_lines=$(echo "$line" | grep -oE '[0-9]+[[:space:]]+@@' | grep -oE '[0-9]+')
130+
else
131+
added_lines=$(echo "$line" | grep -oP '\d+\s+@@' | grep -oP '\d+')
132+
fi
125133
diff_start_line=$(echo "$line" | awk -F'+' '{print $2}' | awk -F',' '{print $1}')
126134
else
127135
# 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
128136
added_lines=0
129-
diff_start_line=$(echo "$line" | grep -oP '\+\d+\s+@@' | grep -oP '\d+')
137+
if [[ "$OSTYPE" == "darwin"* ]]; then
138+
diff_start_line=$(echo "$line" | grep -oE '\+[0-9]+[[:space:]]+@@' | grep -oE '[0-9]+')
139+
else
140+
diff_start_line=$(echo "$line" | grep -oP '\+\d+\s+@@' | grep -oP '\d+')
141+
fi
130142
fi
131143

132144
# 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)