127435ae3SJohnnie Birch# This is a workflow triggered by PR or triggered manually
227435ae3SJohnnie Birch# Runs quick performance tests and reports the comparison against HEAD
327435ae3SJohnnie Birch# Test should take less than 10 minutes to run on current self-hosted devices
427435ae3SJohnnie Birchname: "Performance Testing"
527435ae3SJohnnie Birch
627435ae3SJohnnie Birch# Controls when the action will run.
727435ae3SJohnnie Birch# This workflow runs when manually triggered by keywords used in the start of a review comment
827435ae3SJohnnie Birch# Currently that phrase is /bench_x64. /bench_aarch64 and /bench_all are TODOs.
927435ae3SJohnnie Birchon:
10f2105f95SJohnnie Birch  issue_comment:
11f2105f95SJohnnie Birch    types: [created]
1227435ae3SJohnnie Birch  push:
1327435ae3SJohnnie Birch
1427435ae3SJohnnie Birch# Env variables
1527435ae3SJohnnie Birchenv:
165285ba15SJohnnie Birch  SG_COMMIT: 2ab01ac
1727435ae3SJohnnie Birch  GITHUB_CONTEXT: ${{ toJson(github) }}
1827435ae3SJohnnie Birch
1927435ae3SJohnnie Birchjobs:
2027435ae3SJohnnie Birch  Wasmtime_Repo_On_PR_Comment:
2127435ae3SJohnnie Birch    name: Benchmark x64 on PR comment Wasmtime repo
2227435ae3SJohnnie Birch    runs-on: ubuntu-latest
2327435ae3SJohnnie Birch    if: |
24f2105f95SJohnnie Birch      (github.event_name == 'issue_comment') &&
25f2105f95SJohnnie Birch      (github.event.issue.pull_request.url) &&
26f2105f95SJohnnie Birch      (contains(github.event.comment.body, '/bench_x64')) &&
27f2105f95SJohnnie Birch      (('abrown' == github.event.comment.user.login)
28f2105f95SJohnnie Birch        || ('afonso360' == github.event.comment.user.login)
29f2105f95SJohnnie Birch        || ('akirilov-arm' == github.event.comment.user.login)
30f2105f95SJohnnie Birch        || ('alexcrichton' == github.event.comment.user.login)
31f2105f95SJohnnie Birch        || ('bbouvier' == github.event.comment.user.login)
32f2105f95SJohnnie Birch        || ('bjorn3' == github.event.comment.user.login)
33f2105f95SJohnnie Birch        || ('cfallin' == github.event.comment.user.login)
348376944bSJamey Sharp        || ('elliottt' == github.event.comment.user.login)
35f2105f95SJohnnie Birch        || ('fitzgen' == github.event.comment.user.login)
368376944bSJamey Sharp        || ('jameysharp' == github.event.comment.user.login)
37f2105f95SJohnnie Birch        || ('jlb6740' == github.event.comment.user.login)
38f2105f95SJohnnie Birch        || ('sparker-arm' == github.event.comment.user.login)
39f2105f95SJohnnie Birch        || ('uweigand' == github.event.comment.user.login))
4027435ae3SJohnnie Birch    steps:
4127435ae3SJohnnie Birch      - run: echo "$GITHUB_CONTEXT"
4227435ae3SJohnnie Birch      - run: |
4327435ae3SJohnnie Birch          # Create and Push Branch
44a434f43dSJohnnie Birch          git clone https://wasmtime-publish:${{secrets.PERSONAL_ACCESS_TOKEN}}@github.com/bytecodealliance/wasmtime-sightglass-benchmarking.git
4527435ae3SJohnnie Birch          cd wasmtime-sightglass-benchmarking
4627435ae3SJohnnie Birch          git remote add wasmtime ${{ github.event.repository.clone_url }}
4727435ae3SJohnnie Birch          git fetch wasmtime refs/pull/*/merge:refs/remotes/wasmtime/pull/*/merge
48f2105f95SJohnnie Birch          export issue_pr_url=${{ github.event.issue.pull_request.url }}
49f2105f95SJohnnie Birch          export issue_commits_url=${{ github.event.issue.comments_url }}
50f2105f95SJohnnie Birch          export issue_ref_name=$(curl -sSL $issue_pr_url | jq -r '.head.ref' | head -n 1)
51f2105f95SJohnnie Birch          export issue_number=$(curl -sSL $issue_pr_url | jq -r '.number' | head -n 1)
52f2105f95SJohnnie Birch          export issue_merge_commit_sha=$(curl -sSL $issue_pr_url | jq -r '.merge_commit_sha' | head -n 1)
5327435ae3SJohnnie Birch          git submodule update --init --recursive
54f2105f95SJohnnie Birch          git checkout wasmtime/pull/${issue_number}/merge -b pull/${issue_number}/merge/${issue_merge_commit_sha}
55f2105f95SJohnnie Birch          git config user.name $(curl -sSL $issue_commits_url | jq -r '.[].commit.committer.name' | tail -n 1)
56f2105f95SJohnnie Birch          git config user.email $(curl -sSL $issue_commits_url | jq -r '.[].commit.committer.email' | tail -n 1)
57f2105f95SJohnnie Birch          git log -n 1
58f2105f95SJohnnie Birch          git commit --allow-empty -m "${issue_commits_url}"
59f2105f95SJohnnie Birch          git push origin --force pull/${issue_number}/merge/${issue_merge_commit_sha}
60f2105f95SJohnnie Birch          git log -n 1
6127435ae3SJohnnie Birch
6227435ae3SJohnnie Birch  Performance_Repo_On_Push:
6327435ae3SJohnnie Birch    name: Benchmark x64 on push Performance repo
6427435ae3SJohnnie Birch    runs-on: [self-hosted, linux, x64]
6527435ae3SJohnnie Birch    if: (github.event_name == 'push') && (github.repository == 'bytecodealliance/wasmtime-sightglass-benchmarking')
6627435ae3SJohnnie Birch    steps:
6727435ae3SJohnnie Birch      - run: echo "$GITHUB_CONTEXT"
6827435ae3SJohnnie Birch      - run: echo "${{ github.event.head_commit.message }}"
6927435ae3SJohnnie Birch      - name: "Build sightglass commit '${{ env.SG_COMMIT }}'"
7027435ae3SJohnnie Birch        run: |
7127435ae3SJohnnie Birch          cd ../ && ls -l && rm -rf ./sightglass
7227435ae3SJohnnie Birch          git clone https://github.com/bytecodealliance/sightglass.git && cd ./sightglass
7327435ae3SJohnnie Birch          git checkout ${{env.SG_COMMIT}}
7427435ae3SJohnnie Birch          cargo build --release
7527435ae3SJohnnie Birch
7627435ae3SJohnnie Birch      - name: Checkout patch from bytecodealliance/wasmtime (pushed and triggering on this perf repo)
77*7cca98e5SAlex Crichton        uses: actions/checkout@v6
7827435ae3SJohnnie Birch        with:
7927435ae3SJohnnie Birch          submodules: true
8027435ae3SJohnnie Birch          path: wasmtime_commit
8127435ae3SJohnnie Birch
827669a961SAlex Crichton      - run: rustup update nightly && rustup default nightly
83f2105f95SJohnnie Birch
8427435ae3SJohnnie Birch      - name: Build patch from bytecodealliance/wasmtime (pushed and triggering on this perf repo)
8527435ae3SJohnnie Birch        working-directory: ./wasmtime_commit
8627435ae3SJohnnie Birch        run: |
87f2105f95SJohnnie Birch          cargo --version
8827435ae3SJohnnie Birch          cargo build --release -p wasmtime-bench-api
8927435ae3SJohnnie Birch          cp target/release/libwasmtime_bench_api.so /tmp/wasmtime_commit.so
9027435ae3SJohnnie Birch
9127435ae3SJohnnie Birch      - name: Checkout main from bytecodealliance/wasmtime
92*7cca98e5SAlex Crichton        uses: actions/checkout@v6
9327435ae3SJohnnie Birch        with:
9427435ae3SJohnnie Birch          ref: 'main'
9527435ae3SJohnnie Birch          repository: 'bytecodealliance/wasmtime'
9627435ae3SJohnnie Birch          submodules: true
9727435ae3SJohnnie Birch          path: wasmtime_main
9827435ae3SJohnnie Birch
9927435ae3SJohnnie Birch      - name: Build main from bytecodealliance/wasmtime
10027435ae3SJohnnie Birch        working-directory: ./wasmtime_main
10127435ae3SJohnnie Birch        run: |
10227435ae3SJohnnie Birch          cargo build --release -p wasmtime-bench-api
10327435ae3SJohnnie Birch          cp target/release/libwasmtime_bench_api.so /tmp/wasmtime_main.so
10427435ae3SJohnnie Birch
10527435ae3SJohnnie Birch      - name: Run performance tests
10627435ae3SJohnnie Birch        working-directory: ../sightglass
10727435ae3SJohnnie Birch        run: |
10827435ae3SJohnnie Birch          cargo run -- \
10927435ae3SJohnnie Birch          benchmark \
1105285ba15SJohnnie Birch          --processes 5 \
1115285ba15SJohnnie Birch          --iterations-per-process 5 \
11227435ae3SJohnnie Birch          --engine /tmp/wasmtime_main.so \
11327435ae3SJohnnie Birch          --engine /tmp/wasmtime_commit.so \
1145285ba15SJohnnie Birch          --output-file /tmp/results.txt
11527435ae3SJohnnie Birch
11627435ae3SJohnnie Birch      - name: Print Results
1175285ba15SJohnnie Birch        run: cat /tmp/results.txt
11827435ae3SJohnnie Birch
11927435ae3SJohnnie Birch      - id: get-comment-body
12027435ae3SJohnnie Birch        name: Create Results Body
12127435ae3SJohnnie Birch        run: |
1225285ba15SJohnnie Birch            body="$(cat /tmp/results.txt)"
12327435ae3SJohnnie Birch            body="${body//'%'/'%25'}"
12427435ae3SJohnnie Birch            body="${body//$'\n'/'%0A'}"
12527435ae3SJohnnie Birch            body="${body//$'\r'/'%0D'}"
1265285ba15SJohnnie Birch            echo "::set-output name=body::$body"
12727435ae3SJohnnie Birch
12827435ae3SJohnnie Birch      - name: Publish Results
12927435ae3SJohnnie Birch        run: |
13027435ae3SJohnnie Birch          curl -X POST -H "Accept: application/vnd.github.v3+json" \
13127435ae3SJohnnie Birch          -H "Authorization: token ${{ secrets.WASMTIME_PUBLISHING_TOKEN }}" \
13227435ae3SJohnnie Birch          ${{ github.event.head_commit.message }} \
13327435ae3SJohnnie Birch          -d '{"body": ${{ toJSON(steps.get-comment-body.outputs.body) }}}'
134