From 257b16119d95a699fc5e989c432c8626b2427586 Mon Sep 17 00:00:00 2001 From: snoopuppy582 Date: Thu, 14 May 2026 06:32:29 +0900 Subject: [PATCH] ci: add testcase report workflow --- .github/workflows/testcase-report.yml | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 .github/workflows/testcase-report.yml diff --git a/.github/workflows/testcase-report.yml b/.github/workflows/testcase-report.yml new file mode 100644 index 00000000..237c4ea6 --- /dev/null +++ b/.github/workflows/testcase-report.yml @@ -0,0 +1,110 @@ +name: Testcase Report + +on: + pull_request: + branches: + - main + paths: + - '.github/workflows/testcase-report.yml' + - 'Cargo.lock' + - 'Cargo.toml' + - 'libs/braillify/**' + - 'test_cases/**' + workflow_dispatch: + +permissions: + contents: read + issues: write + +jobs: + testcase-report: + name: Testcase Report + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + + - name: Run testcase report + id: testcase + shell: bash + run: | + set +e + cargo test test_by_testcase -- --nocapture 2>&1 | tee testcase-report.log + status=${PIPESTATUS[0]} + clean_report="$(perl -pe 's/\x1b\[[0-9;]*m//g' testcase-report.log)" + + total="$(printf '%s\n' "$clean_report" | awk -F': ' '/총 테스트 케이스/ { gsub(/[^0-9]/, "", $2); print $2; exit }')" + passed="$(printf '%s\n' "$clean_report" | awk -F': ' '/^성공:/ { gsub(/[^0-9]/, "", $2); print $2; exit }')" + failed="$(printf '%s\n' "$clean_report" | awk -F': ' '/^실패:/ { gsub(/[^0-9]/, "", $2); print $2; exit }')" + + total="${total:-0}" + passed="${passed:-0}" + failed="${failed:-0}" + success_rate="0.00" + if [ "$total" -gt 0 ]; then + success_rate="$(awk -v passed="$passed" -v total="$total" 'BEGIN { printf "%.2f", passed / total * 100 }')" + fi + + { + echo '### Braillify testcase report' + echo + echo '| Metric | Count |' + echo '| --- | ---: |' + echo "| Total | $total |" + echo "| Passed | $passed |" + echo "| Failed | $failed |" + echo "| Success rate | $success_rate% |" + echo + echo 'Command: `cargo test test_by_testcase -- --nocapture`' + } > testcase-report.md + + cat testcase-report.md >> "$GITHUB_STEP_SUMMARY" + + { + echo 'report<> "$GITHUB_OUTPUT" + + exit "$status" + + - name: Comment testcase report + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository + uses: actions/github-script@v7 + env: + REPORT: ${{ steps.testcase.outputs.report }} + with: + script: | + const marker = '' + const body = `${marker}\n${process.env.REPORT}` + const issue_number = context.payload.pull_request.number + const { owner, repo } = context.repo + const comments = await github.paginate( + github.rest.issues.listComments, + { owner, repo, issue_number, per_page: 100 }, + ) + const previous = comments.find( + (comment) => + comment.user?.type === 'Bot' && comment.body?.includes(marker), + ) + + if (previous) { + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: previous.id, + body, + }) + } else { + await github.rest.issues.createComment({ + owner, + repo, + issue_number, + body, + }) + }