Skip to content

Commit 46bad52

Browse files
committed
Report merge conflicts in step summary
1 parent 29407b1 commit 46bad52

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

merge

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ install_gh() {
3939
install_tools
4040
}
4141

42+
wrap_in_backticks() {
43+
b=$(
44+
perl -e 'my $longest = 2;
45+
while (<>) {
46+
while (/(`+)/g) {
47+
my $length = length $1;
48+
$longest = $length if $length > $longest;
49+
}
50+
}
51+
my $q = q<`>x ($longest + 1);
52+
print $q;
53+
' "$1"
54+
)
55+
echo "$b"
56+
cat "$1"
57+
echo "$b"
58+
}
59+
4260
report_failure() {
4361
echo "MERGE_FAILED=1" >> "$GITHUB_ENV"
4462
echo 'status=failed' >> "$GITHUB_OUTPUT"
@@ -49,13 +67,20 @@ report_failure() {
4967
echo "# checkout-merge failed
5068
5169
:x: $1" >> "$GITHUB_STEP_SUMMARY"
70+
if [ -s "$log" ]; then
71+
echo
72+
wrap_in_backticks "$log"
73+
fi
5274
fi
5375
fi
5476
exit 0
5577
}
5678

5779
command_v gh || install_gh
5880

81+
log=$(mktemp)
82+
merge_log=$(mktemp)
83+
5984
cd "$INPUT_PATH" || report_failure "Could not change to input_path ($INPUT_PATH)"
6085
SENDER=$(jq -r .sender.login "$GITHUB_EVENT_PATH")
6186
USER_JSON=$(mktemp)
@@ -94,9 +119,18 @@ git fetch origin "$INPUT_HEAD_REF" ||
94119

95120
GITHUB_HEAD_SHA=$(git rev-parse FETCH_HEAD)
96121
echo '::group::Merging'
97-
git merge -m "Merge $GITHUB_HEAD_SHA into $GITHUB_BASE_SHA" FETCH_HEAD &&
98-
echo '::endgroup::' ||
99-
report_failure "Can't generate merge; there's probably a conflict. Resolve it to get workflow feedback." &&
122+
if !(git merge -m "Merge $GITHUB_HEAD_SHA into $GITHUB_BASE_SHA" FETCH_HEAD 2>&1) > "$merge_log"; then
123+
cat "$merge_log"
100124
echo '::endgroup::'
125+
if grep '^CONFLICT ' "$merge_log" > "$log"; then
126+
report_failure "Can't generate merge; there's a conflict. Resolve it to get workflow feedback."
127+
else
128+
cp "$merge_log" "$log"
129+
report_failure "Can't generate merge; there's might be a conflict. Resolve it to get workflow feedback."
130+
fi
131+
fi
132+
133+
cat "$merge_log"
134+
echo '::endgroup::'
101135

102136
echo 'status=success' >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)