benchmark #4
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: | |
pull_request_review: | |
types: [submitted] | |
pull_request: | |
branches: [ main ] | |
types: [synchronize] | |
paths: | |
- 'Sources/*.swift' | |
- .github/workflows/benchmark.yml | |
jobs: | |
benchmark-vs-main: | |
runs-on: | |
- runs-on=${{ github.run_id }} | |
- runner=2cpu-linux-arm64 | |
container: swift:jammy | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: jemalloc dependency | |
run: apt-get update && apt-get install -y libjemalloc-dev | |
- name: Fix Git config | |
run: | | |
git config --global --add safe.directory "${GITHUB_WORKSPACE}" | |
- name: Run benchmarks for PR branch | |
run: | | |
swift package -c release --package-path Benchmarks --disable-sandbox benchmark baseline update pull_request --no-progress --quiet | |
echo "### PR Branch Benchmark Results" >> "${GITHUB_STEP_SUMMARY}" | |
swift package -c release --package-path Benchmarks benchmark list --format markdown >> "${GITHUB_STEP_SUMMARY}" | |
- name: Check if Benchmarks/Package.swift exists on main | |
id: check_benchmarks | |
run: | | |
git checkout main | |
if [ -f "Benchmarks/Package.swift" ]; then | |
echo "exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "exists=false" >> $GITHUB_OUTPUT | |
fi | |
git checkout - | |
- name: Run benchmarks for 'main' branch | |
if: steps.check_benchmarks.outputs.exists == 'true' | |
run: | | |
git stash | |
git checkout main | |
swift package -c release --package-path Benchmarks --disable-sandbox benchmark baseline update main --no-progress --quiet | |
- name: Compare benchmarks | |
if: steps.check_benchmarks.outputs.exists == 'true' | |
run: | | |
echo "### Comparison with Main Branch" >> "${GITHUB_STEP_SUMMARY}" | |
date >> "${GITHUB_STEP_SUMMARY}" | |
swift package -c release --package-path Benchmarks benchmark baseline check main pull_request --format markdown >> "${GITHUB_STEP_SUMMARY}" | |
- name: Get formatted date | |
if: steps.check_benchmarks.outputs.exists == 'true' | |
id: get-date | |
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT | |
- uses: thollander/actions-comment-pull-request@v3 | |
with: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
message: | | |
${{ format('[PR benchmarks run at {0}]({1}/{2}/actions/runs/{3})', steps.get-date.outputs.date, github.server_url, github.repository, github.run_id) }} | |
${{ steps.check_benchmarks.outputs.exists == 'true' && '(includes comparison with main)' || '(main branch benchmarks not available)' }} | |
comment_tag: 'PR benchmark comparison Linux' |