ci: Add server failed tests as PR comment (#30888)

And, don't show duplicates. Not sure why we're seeing duplicates though.
This commit is contained in:
Shrikant Sharat Kandula 2024-02-06 16:07:43 +05:30 committed by GitHub
parent 1afd321e13
commit dbe138778a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View File

@ -183,11 +183,16 @@ jobs:
args+=("-DtestResultFile=$PWD/failed-server-tests.txt")
if ! mvn test "${args[@]}"; then
if [[ -s failed-server-tests.txt ]]; then
{
echo "## Failed tests"
content="$(
echo "## Failed server tests"
echo
sed 's/^/- /' 'failed-server-tests.txt'
} >> "$GITHUB_STEP_SUMMARY"
)"
echo "$content" >> "$GITHUB_STEP_SUMMARY"
# Add a comment to the PR with the list of failed tests.
curl --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--data "$(jq -n --arg body "$content" '$ARGS.named')" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/${{ inputs.pr }}/comments"
fi
exit 1
fi

View File

@ -6,8 +6,8 @@ import org.junit.jupiter.api.extension.TestWatcher;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.TreeSet;
/**
* The TestWatcher interface is used to react to the execution of tests.
@ -20,7 +20,7 @@ import java.util.List;
*/
public class TestResultLoggerExtension implements TestWatcher, AfterAllCallback {
private final List<String> failedTests = new ArrayList<>();
private final Collection<String> failedTests = new TreeSet<>();
/**
* This method is called after all the tests are run. It writes the failed tests to a file.