Benchmark #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Benchmark | |
on: | |
workflow_dispatch: # Manual trigger | |
jobs: | |
benchmark: | |
name: Performance check | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout current branch (full) | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: coursier/setup-action@main | |
with: | |
jvm: temurin@17 | |
apps: mill | |
# Run benchmark with `go test -bench` and stores the output to a file | |
- name: Run benchmark | |
run: mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json | |
- name: Set variables | |
run: | | |
# Get the short commit hash | |
SHORT_SHA=$(git rev-parse --short $GITHUB_SHA) | |
# Get the current branch name | |
BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
# Get the date in YYYYMMDD format | |
DATESTAMP=$(date +"%Y%m%d") | |
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV | |
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | |
echo "DATESTAMP=${DATESTAMP}" >> $GITHUB_ENV | |
- name: Rename file | |
run: | | |
# Original filename | |
ORIGINAL_FILE="out/benchmark/runJmh.dest/jmh-result.json" | |
# Construct new filename with short hash, datestamp, and branch name | |
NEW_FILENAME="bench_${BRANCH_NAME}_${SHORT_SHA}_${DATESTAMP}.json" | |
# Rename the file | |
mv $ORIGINAL_FILE $NEW_FILENAME | |
echo "File renamed to: $NEW_FILENAME" | |
- name: Modify JSON contents and wrap in new object | |
run: | | |
# Read the contents of the new file | |
NEW_FILENAME="bench_${BRANCH_NAME}_${SHORT_SHA}_${DATESTAMP}.json" | |
# Read the original JSON array | |
ORIGINAL_JSON=$(cat $NEW_FILENAME) | |
# Create a new JSON object wrapping the array in "data" field and adding metadata including "host" | |
WRAPPED_JSON=$(jq -n \ | |
--arg branch "$BRANCH_NAME" \ | |
--arg commit "$SHORT_SHA" \ | |
--arg date "$DATESTAMP" \ | |
--arg host "gha" \ | |
--argjson data "$ORIGINAL_JSON" \ | |
'{"branch": $branch, "commit": $commit, "date": $date, "host": $host, "data": $data}') | |
# Overwrite the file with the new JSON object | |
echo $WRAPPED_JSON > benchmark_cache/$NEW_FILENAME | |
echo "File renamed and moved to: benchmark_cache/$NEW_FILENAME" | |
- name: Commit and push changes to benchmark branch | |
run: | | |
git config user.name "GitHub Action Benchmark" | |
git config user.email "action@github.com" | |
# Create new branch based on benchmark branch | |
git fetch origin benchmark | |
git checkout -b benchmark --track origin/benchmark || git checkout benchmark | |
# Stage the renamed and modified file | |
git add $NEW_FILENAME | |
# Commit the changes | |
git commit -m "$NEW_FILENAME bechmark results" | |
# Push the changes to the benchmark branch | |
git push origin benchmark |