Skip to content

Apply the rulings, and stop a groupsign swallowing a whole run #192

Apply the rulings, and stop a groupsign swallowing a whole run

Apply the rulings, and stop a groupsign swallowing a whole run #192

Workflow file for this run

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
pull-requests: write
jobs:
testcase-report:
name: Testcase Report
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- 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 }')"
corpus_years='2021 2022 2023 2024 2025'
corpus_passed=0
corpus_total=0
corpus_rows=''
for year in $corpus_years; do
year_passed="$(printf '%s\n' "$clean_report" | awk -v key="^${year}_corpus:" '$0 ~ key { split($2, counts, "/"); gsub(/[^0-9]/, "", counts[1]); print counts[1]; exit }')"
year_total="$(printf '%s\n' "$clean_report" | awk -v key="^${year}_corpus:" '$0 ~ key { split($2, counts, "/"); gsub(/[^0-9]/, "", counts[2]); print counts[2]; exit }')"
year_passed="${year_passed:-0}"
year_total="${year_total:-0}"
if [ "$year_total" -le 0 ]; then
echo "::error::NIKL ${year} corpus summary was not found in the testcase output."
status=1
continue
fi
year_failed=$((year_total - year_passed))
year_rate="$(awk -v passed="$year_passed" -v total="$year_total" 'BEGIN { printf "%.2f", passed / total * 100 }')"
corpus_rows="${corpus_rows}| NIKL ${year} corpus | $year_passed | $year_total | $year_failed | $year_rate% |"$'\n'
corpus_passed=$((corpus_passed + year_passed))
corpus_total=$((corpus_total + year_total))
done
total="${total:-0}"
passed="${passed:-0}"
failed="${failed:-0}"
corpus_passed="${corpus_passed:-0}"
corpus_total="${corpus_total:-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
corpus_failed=$((corpus_total - corpus_passed))
corpus_success_rate="0.00"
if [ "$corpus_total" -gt 0 ]; then
corpus_success_rate="$(awk -v passed="$corpus_passed" -v total="$corpus_total" 'BEGIN { printf "%.2f", passed / total * 100 }')"
fi
{
echo '### Braillify testcase report'
echo
echo '| Suite | Passed | Total | Failed | Success rate |'
echo '| --- | ---: | ---: | ---: | ---: |'
echo "| Standard testcases | $passed | $total | $failed | $success_rate% |"
printf '%s' "$corpus_rows"
echo "| NIKL corpus (all years) | $corpus_passed | $corpus_total | $corpus_failed | $corpus_success_rate% |"
echo
echo 'Command: `cargo test test_by_testcase -- --nocapture`'
} > testcase-report.md
cat testcase-report.md >> "$GITHUB_STEP_SUMMARY"
{
echo 'report<<EOF'
cat testcase-report.md
echo 'EOF'
} >> "$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@v9
env:
REPORT: ${{ steps.testcase.outputs.report }}
with:
script: |
const marker = '<!-- braillify-testcase-report -->'
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,
})
}