From b74ab5ea79e1e8e77e6ad394d8d739d07ff94dc7 Mon Sep 17 00:00:00 2001 From: marshall_lee Date: Wed, 18 Dec 2024 22:11:04 +0800 Subject: [PATCH] generate benches in CI for matrix strategy by cargo bench -- --list --format terse --- .github/workflows/ci.yml | 42 +++++++++++++++------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dd7f23..8b2cf19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,8 +22,8 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Discover benches - id: discover + - name: Discover subcrates + id: discover_subcrates run: | set -euo pipefail @@ -40,32 +40,22 @@ jobs: # Output the JSON array to GitHub Actions output echo "subcrates=$SUBCRATES_JSON" >> "$GITHUB_OUTPUT" - SUBCRATES_FOR_BENCHES=$(echo "$SUBCRATES" | grep q146 || true) - - # Build a JSON array of objects - # Each object: { "subcrate": "xxx", "bench": "yyy" } - # For each subcrate, we look under benches/ for *.rs files - JSON='[' - first=true - for crate in $SUBCRATES_FOR_BENCHES; do - BENCH_FILES=$(find "implementations/$crate/benches" -maxdepth 1 -name '*.rs' -printf '%f\n' 2>/dev/null || true) - for bf in $BENCH_FILES; do - bench_name="${bf%.rs}" # remove .rs extension - if [ "$first" = true ]; then - first=false - else - JSON="$JSON," - fi - JSON="$JSON{\"subcrate\":\"$crate\",\"bench\":\"$bench_name\"}" - done - done - JSON="$JSON]" - - echo "benches=$JSON" >> "$GITHUB_OUTPUT" + - name: Discover benches + id: discover_benches + run: | + BENCHES=$(cargo bench -- --list --format terse | grep q146 || true) + # Remove the trailing ": benchmark" + BENCHES_CLEANED=$(echo "$BENCHES" | sed 's/: benchmark$//') + + # Convert each line into a JSON string and then wrap them into a JSON array + BENCHES_JSON=$(echo "$BENCHES_CLEANED" | jq -R . | jq -s . | jq -c .) + + # Output the JSON array to GitHub Actions output + echo "benches=$BENCHES_JSON" >> "$GITHUB_OUTPUT" outputs: - benches: ${{ steps.discover.outputs.benches }} - subcrates: ${{ steps.discover.outputs.subcrates }} + benches: ${{ steps.discover_benches.outputs.benches }} + subcrates: ${{ steps.discover_subcrates.outputs.subcrates }} bench: needs: define-matrix