Skip to content

Test benchmarks pipeline #18

Test benchmarks pipeline

Test benchmarks pipeline #18

Workflow file for this run

name: Benchmark
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
permissions:
contents: read
pull-requests: write
jobs:
benchmarks:
if: contains(github.event.pull_request.labels.*.name, 'request-benchmarks')
runs-on: ubuntu-latest
steps:
- name: Install wrk
run: |
sudo apt-get update
sudo apt-get install -y wrk
- name: Checkout Source Branch
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
path: source
- name: Setup Node.js for Source Branch
uses: actions/setup-node@v3
with:
node-version: '22.x'
- name: Install Dependencies for Source Branch
run: |
cd source
npm install
- name: Run Benchmarks on Source Branch
run: |
cd source/benchmarks
make > source_results.log
- name: Save Source Results
id: save-source-results
uses: actions/upload-artifact@v2
with:
name: source-results
path: source/benchmarks/source_results.log
- name: Checkout Target Branch
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.ref }}
path: target
- name: Setup Node.js for Target Branch
uses: actions/setup-node@v3
with:
node-version: '22.x'
- name: Install Dependencies for Target Branch
run: |
cd target
npm install
- name: Run Benchmarks on Target Branch
run: |
cd target/benchmarks
make > target_results.log
- name: Save Target Results
id: save-target-results
uses: actions/upload-artifact@v2
with:
name: target-results
path: target/benchmarks/target_results.log
- name: Download Source Results
uses: actions/download-artifact@v2
with:
name: source-results
path: source-results
- name: Download Target Results
uses: actions/download-artifact@v2
with:
name: target-results
path: target-results
- name: Compare Results and Comment on PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
PR_COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
run: |
set -e
# Compare the benchmark results and generate a Markdown table for the comment
echo "Comparing benchmark results..."
# Ensure both results files exist
if [ ! -f source-results/source_results.log ] || [ ! -f target-results/target_results.log ]; then
echo "Results files not found!"
exit 1
fi
# Read results into arrays (assuming each line is a metric in the format "MetricName: Value")
mapfile -t source_results < source-results/source_results.log
mapfile -t target_results < target-results/target_results.log
# Start the Markdown table
COMMENT_BODY='### Benchmark Comparison\n\n'
COMMENT_BODY+='| Metric | Source Branch Value | Target Branch Value |\n'
COMMENT_BODY+='|--------|----------------------|----------------------|\n'
# Assuming the metrics are the same and in the same order for both source and target
for i in "${!source_results[@]}"; do
source_metric_name=$(echo "${source_results[$i]}" | cut -d ':' -f 1)
source_metric_value=$(echo "${source_results[$i]}" | cut -d ':' -f 2)
target_metric_value=$(echo "${target_results[$i]}" | cut -d ':' -f 2)
COMMENT_BODY+="| ${source_metric_name} | ${source_metric_value} | ${target_metric_value} |\n"
done
# Post the comment to the PR
PAYLOAD=$(jq -n --arg body "$COMMENT_BODY" '{body: $body}')
echo "Posting comment to PR..."
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$PR_COMMENTS_URL"
continue-on-error: true
- name: Remove request-benchmarks Label
run: |
curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
"${{ github.event.pull_request.issue_url }}/labels/request-benchmarks"