Skip to content

Commit

Permalink
generate benches in CI for matrix strategy by cargo bench -- --list -…
Browse files Browse the repository at this point in the history
…-format terse
  • Loading branch information
drink7036290 committed Dec 18, 2024
1 parent 297cec5 commit b74ab5e
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b74ab5e

Please sign in to comment.