| 1 |
name: Benchmarks |
| 2 |
|
| 3 |
# spell-checker:ignore (people) taiki-e |
| 4 |
# spell-checker:ignore (misc) codspeed sccache |
| 5 |
|
| 6 |
on: |
| 7 |
pull_request: |
| 8 |
paths: &bench_paths |
| 9 |
- 'src/uu/**' |
| 10 |
- 'src/uucore/**' |
| 11 |
- 'src/uucore_procs/**' |
| 12 |
- 'Cargo.toml' |
| 13 |
- 'Cargo.lock' |
| 14 |
push: |
| 15 |
branches: |
| 16 |
- main |
| 17 |
paths: *bench_paths |
| 18 |
|
| 19 |
permissions: |
| 20 |
contents: read # to fetch code (actions/checkout) |
| 21 |
|
| 22 |
# End the current execution if there is a new changeset in the PR. |
| 23 |
concurrency: |
| 24 |
group: ${{ github.workflow }}-${{ github.ref }} |
| 25 |
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 26 |
|
| 27 |
jobs: |
| 28 |
detects-benchmarks: |
| 29 |
name: Detect changes on crates |
| 30 |
runs-on: ubuntu-latest |
| 31 |
outputs: |
| 32 |
package: ${{ steps.detect.outputs.package }} |
| 33 |
steps: |
| 34 |
- uses: actions/[email protected] |
| 35 |
with: |
| 36 |
persist-credentials: false |
| 37 |
fetch-depth: 0 |
| 38 |
|
| 39 |
- id: detect |
| 40 |
shell: bash |
| 41 |
run: | |
| 42 |
if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 43 |
base="${{ github.event.pull_request.base.sha }}" |
| 44 |
else |
| 45 |
# for push diff of the previous |
| 46 |
base="${{ github.event.before }}" |
| 47 |
fi |
| 48 |
|
| 49 |
changed=$(git diff --name-only "$base" "${{ github.sha }}") |
| 50 |
|
| 51 |
if echo "$changed" | grep -qE '^(Cargo\.(toml|lock)|src/(uucore|uucore_procs)/)'; then |
| 52 |
candidates=$(ls src/uu) |
| 53 |
else |
| 54 |
candidates=$(echo "$changed" | awk -F'/' '/^src\/uu\// {print $3}' | sort -u) |
| 55 |
fi |
| 56 |
|
| 57 |
package=$(for pkg in $candidates; |
| 58 |
do |
| 59 |
if [ -d "src/uu/$pkg/benches" ]; then |
| 60 |
echo "uu_$pkg" |
| 61 |
fi |
| 62 |
done | sort -u | jq -R . | jq -sc .) |
| 63 |
|
| 64 |
echo "package=$package" >> "$GITHUB_OUTPUT" |
| 65 |
|
| 66 |
benchmarks: |
| 67 |
needs: detects-benchmarks |
| 68 |
if: needs.detects-benchmarks.outputs.package != '[]' |
| 69 |
name: Run ${{ matrix.type }} benchmarks for ${{ matrix.package }} (CodSpeed) |
| 70 |
runs-on: ubuntu-latest |
| 71 |
timeout-minutes: 90 |
| 72 |
env: |
| 73 |
CARGO_INCREMENTAL: 0 |
| 74 |
strategy: |
| 75 |
# Stagger the jobs: 70 concurrent runners hitting the GitHub cache API |
| 76 |
# (rust-cache + sccache + CodSpeed) at once triggers HTTP 429s. |
| 77 |
max-parallel: 12 |
| 78 |
matrix: |
| 79 |
type: [simulation, memory] |
| 80 |
package: ${{ fromJson(needs.detects-benchmarks.outputs.package) }} |
| 81 |
steps: |
| 82 |
- uses: actions/[email protected] |
| 83 |
with: |
| 84 |
persist-credentials: false |
| 85 |
|
| 86 |
- uses: Swatinem/rust-cache@v2 |
| 87 |
|
| 88 |
- name: Run sccache-cache |
| 89 |
id: sccache-setup |
| 90 |
uses: mozilla-actions/[email protected] |
| 91 |
continue-on-error: true |
| 92 |
- name: Export sccache |
| 93 |
if: steps.sccache-setup.outcome == 'success' |
| 94 |
run: | |
| 95 |
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV |
| 96 |
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV |
| 97 |
|
| 98 |
- name: Install locales |
| 99 |
shell: bash |
| 100 |
run: | |
| 101 |
sudo locale-gen fr_FR.UTF-8 |
| 102 |
sudo update-locale |
| 103 |
|
| 104 |
- name: Install tools |
| 105 |
uses: taiki-e/install-action@v2 |
| 106 |
with: |
| 107 |
tool: cargo-codspeed |
| 108 |
|
| 109 |
- name: Build benchmarks for ${{ matrix.package }} (${{ matrix.type }}) |
| 110 |
shell: bash |
| 111 |
run: | |
| 112 |
echo "Building ${{ matrix.type }} benchmarks for ${{ matrix.package }}" |
| 113 |
cargo codspeed build -m ${{ matrix.type }} -p ${{ matrix.package }} |
| 114 |
|
| 115 |
- name: Run ${{ matrix.type }} benchmarks for ${{ matrix.package }} |
| 116 |
uses: CodSpeedHQ/action@v5 |
| 117 |
env: |
| 118 |
CODSPEED_LOG: debug |
| 119 |
with: |
| 120 |
mode: ${{ matrix.type }} |
| 121 |
run: | |
| 122 |
echo "Running ${{ matrix.type }} benchmarks for ${{ matrix.package }}" |
| 123 |
cargo codspeed run -p ${{ matrix.package }} > /dev/null |
| 124 |
token: ${{ secrets.CODSPEED_TOKEN }} |