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 +++++++++++++++++++++++++++++++++++ .github/workflows/ci.yaml | 16 ++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/scripts/post-test-results.sh (limited to '.github') 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" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 987ceb4..6cab034 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,6 +11,10 @@ on: jobs: build_plugin: runs-on: ubuntu-24.04 + permissions: + contents: read + pull-requests: write + issues: write steps: - name: Checkout repository uses: actions/checkout@v6 @@ -24,6 +28,18 @@ jobs: - name: Check ktlint run: ./gradlew ktlintCheck --no-daemon + - name: Run tests + run: ./gradlew test --no-daemon + continue-on-error: true + + - name: Post test results to PR + if: github.event_name == 'pull_request' && always() + env: + GH_TOKEN: ${{ github.token }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_REF: ${{ github.ref }} + run: .github/scripts/post-test-results.sh + - name: Build with shadowJar run: ./gradlew :platform-paper:shadowJar --parallel --no-daemon -- cgit v1.2.1