1name: benchmark23# On every push to main, time the MoonBit harnesses at the pushed commit and4# at its first parent on the same runner, record the comparison on the5# `bench-data` branch and publish the dashboard (bench/xlang/site) to GitHub6# Pages. Pushes that only touch files that cannot change the library's speed7# (documentation, tests, tools) start no run. Pushes that only touch the page8# itself, the snapshot included, republish it without comparing. Run by hand,9# it only republishes the dashboard unless asked to compare as well.1011on:12 push:13 branches:14 - main15 paths:16 - "**"17 - "!**.md"18 - "!**/*_test.mbt"19 - "!**/*_wbtest.mbt"20 - "!docs/**"21 - "!tests/**"22 - "!tools/**"23 - "!.github/**"24 - ".github/workflows/bench.yml"25 workflow_dispatch:26 inputs:27 compare:28 description: Also compare the head of main with its first parent29 type: boolean30 default: false3132permissions:33 contents: write34 pages: write35 id-token: write3637# One run at a time, so that runs do not append to the history at once. By38# default a group keeps a single pending run and cancels it when another39# arrives, which would skip the comparison of a push; `queue: max` keeps up40# to 100 waiting. They may start out of order, so the page sorts the history41# by commit date.42concurrency:43 group: benchmark44 cancel-in-progress: false45 queue: max4647env:48 DATA_BRANCH: bench-data4950jobs:51 compare:52 runs-on: ubuntu-latest53 timeout-minutes: 9054 steps:55 - uses: actions/checkout@v456 with:57 fetch-depth: 25859 - name: decide whether to compare60 id: changes61 run: |62 if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then63 echo "compare=${{ inputs.compare }}" >> "$GITHUB_OUTPUT"64 elif git diff --quiet HEAD^ HEAD -- . ':(exclude)bench/xlang/site'; then65 echo "compare=false" >> "$GITHUB_OUTPUT"66 else67 echo "compare=true" >> "$GITHUB_OUTPUT"68 fi6970 - name: install71 if: steps.changes.outputs.compare == 'true'72 run: |73 curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash74 echo "$HOME/.moon/bin" >> $GITHUB_PATH7576 - uses: actions/setup-node@v477 if: steps.changes.outputs.compare == 'true'78 with:79 node-version: 248081 - name: moon version82 if: steps.changes.outputs.compare == 'true'83 run: |84 moon version --all85 moon update8687 - name: compare with the first parent88 if: steps.changes.outputs.compare == 'true'89 run: moon run --target native bench/xlang -- --base HEAD^ --rounds 29091 - name: summary92 if: steps.changes.outputs.compare == 'true'93 run: cat _build/xlang/compare.md >> "$GITHUB_STEP_SUMMARY"9495 - name: check out the history96 run: |97 if git fetch --depth 1 origin "$DATA_BRANCH"; then98 git worktree add data FETCH_HEAD99 git -C data switch -c "$DATA_BRANCH"100 else101 git worktree add --orphan -b "$DATA_BRANCH" data102 fi103 [ -f data/history.json ] || echo '[]' > data/history.json104105 - name: record the comparison106 if: steps.changes.outputs.compare == 'true'107 run: |108 mkdir -p data/runs109 cp _build/xlang/compare.json "data/runs/$GITHUB_SHA.json"110 # The history keeps the means per operation; the costs of every case111 # stay in runs/<commit>.json.112 jq --slurpfile run _build/xlang/compare.json \113 '[.[] | select(.about.head.commit != $run[0].about.head.commit)] + [$run[0] | del(.cases)]' \114 data/history.json > data/history.json.new115 mv data/history.json.new data/history.json116 cd data117 git config user.name "github-actions[bot]"118 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"119 git add history.json runs120 git commit -m "bench: compare ${GITHUB_SHA::7} with its first parent"121 git push origin "HEAD:$DATA_BRANCH"122123 - name: assemble the site124 run: |125 cp -R bench/xlang/site _site126 cp data/history.json _site/history.json127 if [ -d data/runs ]; then cp -R data/runs _site/runs; fi128129 - uses: actions/upload-pages-artifact@v3130 with:131 path: _site132133 deploy:134 needs: compare135 runs-on: ubuntu-latest136 environment:137 name: github-pages138 url: ${{ steps.deployment.outputs.page_url }}139 steps:140 - id: deployment141 uses: actions/deploy-pages@v4142
name: benchmark
# On every push to main, time the MoonBit harnesses at the pushed commit and
# at its first parent on the same runner, record the comparison on the
# `bench-data` branch and publish the dashboard (bench/xlang/site) to GitHub
# Pages. Pushes that only touch files that cannot change the library's speed
# (documentation, tests, tools) start no run. Pushes that only touch the page
# itself, the snapshot included, republish it without comparing. Run by hand,
# it only republishes the dashboard unless asked to compare as well.
on:
push:
branches:
- main
paths:
- "**"
- "!**.md"
- "!**/*_test.mbt"
- "!**/*_wbtest.mbt"
- "!docs/**"
- "!tests/**"
- "!tools/**"
- "!.github/**"
- ".github/workflows/bench.yml"
workflow_dispatch:
inputs:
compare:
description: Also compare the head of main with its first parent
type: boolean
default: false
permissions:
contents: write
pages: write
id-token: write
# One run at a time, so that runs do not append to the history at once. By
# default a group keeps a single pending run and cancels it when another
# arrives, which would skip the comparison of a push; `queue: max` keeps up
# to 100 waiting. They may start out of order, so the page sorts the history
# by commit date.
concurrency:
group: benchmark
cancel-in-progress: false
queue: max
env:
DATA_BRANCH: bench-data
jobs:
compare:
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: decide whether to compare
id: changes
run: |
if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then
echo "compare=${{ inputs.compare }}" >> "$GITHUB_OUTPUT"
elif git diff --quiet HEAD^ HEAD -- . ':(exclude)bench/xlang/site'; then
echo "compare=false" >> "$GITHUB_OUTPUT"
else
echo "compare=true" >> "$GITHUB_OUTPUT"
fi
- name: install
if: steps.changes.outputs.compare == 'true'
run: |
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
echo "$HOME/.moon/bin" >> $GITHUB_PATH
- uses: actions/setup-node@v4
if: steps.changes.outputs.compare == 'true'
with:
node-version: 24
- name: moon version
if: steps.changes.outputs.compare == 'true'
run: |
moon version --all
moon update
- name: compare with the first parent
if: steps.changes.outputs.compare == 'true'
run: moon run --target native bench/xlang -- --base HEAD^ --rounds 2
- name: summary
if: steps.changes.outputs.compare == 'true'
run: cat _build/xlang/compare.md >> "$GITHUB_STEP_SUMMARY"
- name: check out the history
run: |
if git fetch --depth 1 origin "$DATA_BRANCH"; then
git worktree add data FETCH_HEAD
git -C data switch -c "$DATA_BRANCH"
else
git worktree add --orphan -b "$DATA_BRANCH" data
fi
[ -f data/history.json ] || echo '[]' > data/history.json
- name: record the comparison
if: steps.changes.outputs.compare == 'true'
run: |
mkdir -p data/runs
cp _build/xlang/compare.json "data/runs/$GITHUB_SHA.json"
# The history keeps the means per operation; the costs of every case
# stay in runs/<commit>.json.
jq --slurpfile run _build/xlang/compare.json \
'[.[] | select(.about.head.commit != $run[0].about.head.commit)] + [$run[0] | del(.cases)]' \
data/history.json > data/history.json.new
mv data/history.json.new data/history.json
cd data
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add history.json runs
git commit -m "bench: compare ${GITHUB_SHA::7} with its first parent"
git push origin "HEAD:$DATA_BRANCH"
- name: assemble the site
run: |
cp -R bench/xlang/site _site
cp data/history.json _site/history.json
if [ -d data/runs ]; then cp -R data/runs _site/runs; fi
- uses: actions/upload-pages-artifact@v3
with:
path: _site
deploy:
needs: compare
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4