From f60431789d26926f1506d6d792e1aba339821eae Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Sat, 3 Jan 2026 19:54:26 -0600 Subject: [PATCH] feat(workflows): add benchmarking PR result posting --- .gitea/workflows/bench.yml | 16 ++++++++++-- scripts/post_bench_results.sh | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 scripts/post_bench_results.sh diff --git a/.gitea/workflows/bench.yml b/.gitea/workflows/bench.yml index 809defb..749dcc9 100644 --- a/.gitea/workflows/bench.yml +++ b/.gitea/workflows/bench.yml @@ -37,7 +37,19 @@ jobs: run: task install - name: Run Benchmarks - run: task bench + id: bench + run: | + set -o pipefail + task bench 2>&1 | tee bench_results.txt - name: Run Integrity Tests - run: task test-integrity + id: integrity + run: | + set -o pipefail + task test-integrity 2>&1 | tee -a bench_results.txt + + - name: Post Results to PR + if: always() && github.event_name == 'pull_request' + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: bash scripts/post_bench_results.sh diff --git a/scripts/post_bench_results.sh b/scripts/post_bench_results.sh new file mode 100755 index 0000000..218ea95 --- /dev/null +++ b/scripts/post_bench_results.sh @@ -0,0 +1,46 @@ +#!/bin/bash +set -e + +# Required environment variables: +# GITEA_TOKEN +# GITHUB_REPOSITORY +# GITHUB_EVENT_PATH + +if [ -z "$GITEA_TOKEN" ]; then + echo "GITEA_TOKEN is not set. Skipping PR comment." + exit 0 +fi + +if [ ! -f "bench_results.txt" ]; then + echo "bench_results.txt not found. Nothing to post." + exit 0 +fi + +# Extract PR number from the event JSON +PR_NUMBER=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH") + +if [ "$PR_NUMBER" == "null" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +# Filter out progress lines to keep the comment clean +grep -v "Progress:" bench_results.txt > bench_filtered.txt || true + +# Construct the message +HEADER="### Benchmark and Integrity Results (automated report)" +RESULTS=$(cat bench_filtered.txt) + +# Use jq to construct the JSON payload safely +JSON_PAYLOAD=$(jq -n \ + --arg results "$RESULTS" \ + --arg header "$HEADER" \ + '{body: ($header + "\n\n```text\n" + $results + "\n```"), event: "COMMENT"}') + +# Post to Gitea +curl -f -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD" \ + "https://git.quad4.io/api/v1/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/reviews" +