From ba9353d7cd4e26526aa7f1850b4ccac60d5746a5 Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Tue, 20 Jan 2026 20:36:37 +0900 Subject: ci: Add Test workflow --- .github/scripts/post-test-results.sh | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/scripts/post-test-results.sh (limited to '.github/scripts') diff --git a/.github/scripts/post-test-results.sh b/.github/scripts/post-test-results.sh new file mode 100644 index 0000000..a973db9 --- /dev/null +++ b/.github/scripts/post-test-results.sh @@ -0,0 +1,104 @@ +#!/bin/bash +set -e + +MARKER="" + +TEST_RESULTS_DIR="build/test-results/test" +TOTAL_TESTS=0 +PASSED_TESTS=0 +FAILED_TESTS=0 +SKIPPED_TESTS=0 +FAILED_TEST_NAMES="" + +if [ -d "$TEST_RESULTS_DIR" ]; then + for xml_file in "$TEST_RESULTS_DIR"/*.xml; do + if [ -f "$xml_file" ]; then + tests=$(sed -n 's/.*tests="\([0-9]*\)".*/\1/p' "$xml_file" | head -n1) + failures=$(sed -n 's/.*failures="\([0-9]*\)".*/\1/p' "$xml_file" | head -n1) + skipped=$(sed -n 's/.*skipped="\([0-9]*\)".*/\1/p' "$xml_file" | head -n1) + + tests=${tests:-0} + failures=${failures:-0} + skipped=${skipped:-0} + + TOTAL_TESTS=$((TOTAL_TESTS + tests)) + FAILED_TESTS=$((FAILED_TESTS + failures)) + SKIPPED_TESTS=$((SKIPPED_TESTS + skipped)) + + if [ "$failures" -gt 0 ]; then + failed_names=$(sed -n 's/.* +" +fi + +COMMENT_BODY="${COMMENT_BODY} + +--- +*Updated at $(date -u '+%Y-%m-%d %H:%M:%S UTC')*" + +echo "$COMMENT_BODY" > /tmp/test-comment.md + +PR_NUMBER="${GITHUB_REF#refs/pull/}" +PR_NUMBER="${PR_NUMBER%/merge}" + +if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "$GITHUB_REF" ]; then + echo "Not a pull request, skipping comment" + exit 0 +fi + +EXISTING_COMMENT_ID=$(gh api \ + "repos/$GITHUB_REPOSITORY/issues/${PR_NUMBER}/comments" \ + --jq ".[] | select(.body | contains(\"$MARKER\")) | .id" \ + | head -n 1 || echo "") + +if [ -n "$EXISTING_COMMENT_ID" ]; then + echo "Updating existing comment (ID: $EXISTING_COMMENT_ID)" + gh api \ + "repos/$GITHUB_REPOSITORY/issues/comments/${EXISTING_COMMENT_ID}" \ + -X PATCH \ + -f body="$(cat /tmp/test-comment.md)" +else + echo "Creating new comment" + gh pr comment "$PR_NUMBER" --body-file /tmp/test-comment.md +fi + +echo "Test results comment posted successfully" -- cgit v1.2.1