Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 127 additions & 123 deletions .github/workflows/benchmark_execution_time.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,148 +2,152 @@ name: ⏱️ Benchmark execution time comparison with the main branch

on:
issue_comment:
types: [created, edited, deleted]
types: [created]

permissions:
contents: read

env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

jobs:
building-pr-branch:
if: (github.event.issue.pull_request != null) && github.event.comment.body == '!github easy-benchmark'
resolve:
if: >-
github.event.issue.pull_request &&
github.event.comment.body == '/benchmark' &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)
runs-on: ubuntu-24.04
timeout-minutes: 15

timeout-minutes: 5
permissions:
contents: read
pull-requests: read
outputs:
pr-number: ${{ github.event.issue.number }}
base-sha: ${{ steps.shas.outputs.base-sha }}
pr-sha: ${{ steps.shas.outputs.pr-sha }}
steps:
- name: Checkout to PR branch
uses: actions/checkout@v4

- name: Install requirements
run: sudo ./.github/scripts/dependency.sh

- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.3.7

- name: Install Just
uses: taiki-e/install-action@just

- name: Building PR branch
run: just youki-release

- name: Uploading PR build to artifact
uses: actions/upload-artifact@v4
with:
name: pr-youki
path: ./youki

building-main-branch:
if: (github.event.issue.pull_request != null) && github.event.comment.body == '!github easy-benchmark'
- id: shas
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR: ${{ github.event.issue.number }}
run: |
pr=$(gh api "repos/{owner}/{repo}/pulls/$PR")
pr_sha=$(jq -r .head.sha <<<"$pr")
base_ref=$(jq -r .base.ref <<<"$pr")
base_sha=$(gh api "repos/{owner}/{repo}/compare/$base_ref...$pr_sha" --jq .merge_base_commit.sha)
echo "pr-sha=$pr_sha" >> "$GITHUB_OUTPUT"
echo "base-sha=$base_sha" >> "$GITHUB_OUTPUT"

build:
needs: resolve
runs-on: ubuntu-24.04
timeout-minutes: 15

timeout-minutes: 20
strategy:
matrix:
include:
- name: base
sha: ${{ needs.resolve.outputs.base-sha }}
- name: pr
sha: ${{ needs.resolve.outputs.pr-sha }}
steps:
- name: Checkout to main branch
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
ref: main

- name: Install requirements
run: sudo ./.github/scripts/dependency.sh

- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.3.7
ref: ${{ matrix.sha }}
persist-credentials: false
- name: Install just
uses: taiki-e/install-action@just

- name: Building main branch
run: just youki-release

- name: Uploading main build to artifact
uses: actions/upload-artifact@v4
- name: Install requirements
run: sudo env PATH=$PATH just ci-prepare
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
- run: just youki-release
- uses: actions/upload-artifact@v4
with:
name: main-youki
path: ./youki
name: youki-${{ matrix.name }}
path: youki

benchmark-exec:
if: (github.event.issue.pull_request != null) && github.event.comment.body == '!github easy-benchmark'
needs:
- building-pr-branch
- building-main-branch
bench:
needs: [resolve, build]
runs-on: ubuntu-24.04
timeout-minutes: 15

steps:
- name: Setup Linux env
run: |
sudo apt -y update
sudo apt install jq podman

- name: Checkout to PR branch
uses: actions/checkout@v4

- name: Downloading PR build from artifact
uses: actions/download-artifact@v4
- uses: actions/download-artifact@v4
with:
name: pr-youki
path: ./pr_youki

- name: Downloading main build from artifact
uses: actions/download-artifact@v4
pattern: youki-*
- name: Install hyperfine
uses: taiki-e/install-action@v2
with:
name: main-youki
path: ./main_youki

- name: Preparing binaries
tool: hyperfine@2.0.0
- name: Prepare bundle
run: |
mv ./main_youki/youki ./youki_main
mv ./pr_youki/youki ./youki_pr
chmod +x ./youki_main
chmod +x ./youki_pr

- name: Preparing benchmark bundle
chmod +x youki-base/youki youki-pr/youki
mkdir -p bundle/rootfs
docker export "$(docker create busybox:1.37)" | sudo tar -C bundle/rootfs -xf -
cd bundle
../youki-base/youki spec
jq '.process.terminal = false | .process.args = ["sh", "-c", "echo Hi, my PID is $$; echo Bye Bye"]' config.json > config.json.new
mv config.json.new config.json
- name: Smoke test
run: |
mkdir -p ./benchmark_exec_bundle/rootfs
cd benchmark_exec_bundle
sudo bash -c 'podman export $(podman create busybox) | tar -C rootfs -xvf -'
../youki_main spec
sed -i 's/"sh"/"sh", "-c", "echo Hi, my PID is $$; echo Bye Bye"/' config.json
sed -i 's/"terminal": true/"terminal": false/' config.json

- name: Installing hyperfine
for side in base pr; do
sudo "./youki-$side/youki" run -b bundle "smoke-$side"
sudo "./youki-$side/youki" delete -f "smoke-$side"
done
- name: Run benchmark
run: |
curl -s https://api.github.com/repos/sharkdp/hyperfine/releases/latest \
| jq -r '.assets[] | select(.name? | match("hyperfine-musl_.*_amd64.deb")) | .browser_download_url' \
| wget -qi - -O hyperfine.deb
sudo dpkg -i hyperfine.deb

- name: Running benchmark
sudo "$(command -v hyperfine)" \
--shell=default \
--output=pipe \
--warmup 10 \
--min-runs 100 \
--export-markdown result.md \
--command-name base './youki-base/youki run -b bundle base && ./youki-base/youki delete -f base' \
--command-name pr './youki-pr/youki run -b bundle pr && ./youki-pr/youki delete -f pr'
- name: Write report
env:
BASE_SHA: ${{ needs.resolve.outputs.base-sha }}
PR_SHA: ${{ needs.resolve.outputs.pr-sha }}
run: |
hyperfine --prepare 'sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' \
--export-markdown bench_exec_result.md \
--warmup 10 \
--min-runs 100 \
--command-name 'main youki build' \
'sudo ./youki_main run -b benchmark_exec_bundle main_container && sudo ./youki_main delete -f main_container' \
--command-name 'pr youki build' \
'sudo ./youki_pr run -b benchmark_exec_bundle pr_container && sudo ./youki_pr delete -f pr_container'

- name: Adding info into result
run: |
sed -i '1i > commit (${{ github.event.pull_request.head.sha }})\n' bench_exec_result.md

# since the GITHUB_TOKEN is needed to let the bot commit messages in the PR
# but right now it is controlled by the organization.
# TODO: change back to use this when the permission granted
# - name: Writing report to PR comment
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# append: true
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# path: ./bench_exec_result.md
{
echo "### ⏱️ Execution time benchmark"
echo
echo "- base: \`$BASE_SHA\` (merge base)"
echo "- pr: \`$PR_SHA\`"
echo
cat result.md
echo
echo "Two builds of the same code differ by up to 3% here, so treat a smaller change as noise."
echo
echo "[Workflow run]($RUN_URL)"
} > report.md
cat report.md >> "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@v4
with:
name: report
path: report.md

# temp solution, print the benchmark result in the terminal.
# glow is the prettiest markdown rendering tool I know.
# TODO: remove this step when GITHUB_TOKEN permission granted
- name: Printing report in the terminal
report:
needs: [resolve, bench]
if: always() && needs.resolve.result == 'success'
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
pull-requests: write
steps:
- uses: actions/download-artifact@v4
if: needs.bench.result == 'success'
with:
name: report
- env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR: ${{ needs.resolve.outputs.pr-number }}
BENCH_RESULT: ${{ needs.bench.result }}
run: |
curl -s https://api.github.com/repos/charmbracelet/glow/releases/latest \
| jq -r '.assets[] | select(.name? | match("glow_.*_linux_amd64.deb")) | .browser_download_url' \
| wget -qi - -O glow.deb
sudo dpkg -i glow.deb
glow bench_exec_result.md
if [ "$BENCH_RESULT" != success ]; then
echo "⏱️ The benchmark did not finish (bench: $BENCH_RESULT). See $RUN_URL" > report.md
fi
gh pr comment "$PR" --body-file report.md
Loading