name: Benchmarks # spell-checker:ignore (people) taiki-e # spell-checker:ignore (misc) codspeed sccache on: pull_request: paths: &bench_paths - 'src/uu/**' - 'src/uucore/**' - 'src/uucore_procs/**' - 'Cargo.toml' - 'Cargo.lock' push: branches: - main paths: *bench_paths permissions: contents: read # to fetch code (actions/checkout) # End the current execution if there is a new changeset in the PR. concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: detects-benchmarks: name: Detect changes on crates runs-on: ubuntu-latest outputs: package: ${{ steps.detect.outputs.package }} steps: - uses: actions/checkout@v7.0.1 with: persist-credentials: false fetch-depth: 0 - id: detect shell: bash run: | if [ "${{ github.event_name }}" = "pull_request" ]; then base="${{ github.event.pull_request.base.sha }}" else # for push diff of the previous base="${{ github.event.before }}" fi changed=$(git diff --name-only "$base" "${{ github.sha }}") if echo "$changed" | grep -qE '^(Cargo\.(toml|lock)|src/(uucore|uucore_procs)/)'; then candidates=$(ls src/uu) else candidates=$(echo "$changed" | awk -F'/' '/^src\/uu\// {print $3}' | sort -u) fi package=$(for pkg in $candidates; do if [ -d "src/uu/$pkg/benches" ]; then echo "uu_$pkg" fi done | sort -u | jq -R . | jq -sc .) echo "package=$package" >> "$GITHUB_OUTPUT" benchmarks: needs: detects-benchmarks if: needs.detects-benchmarks.outputs.package != '[]' name: Run ${{ matrix.type }} benchmarks for ${{ matrix.package }} (CodSpeed) runs-on: ubuntu-latest timeout-minutes: 90 env: CARGO_INCREMENTAL: 0 strategy: # Stagger the jobs: 70 concurrent runners hitting the GitHub cache API # (rust-cache + sccache + CodSpeed) at once triggers HTTP 429s. max-parallel: 12 matrix: type: [simulation, memory] package: ${{ fromJson(needs.detects-benchmarks.outputs.package) }} steps: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - uses: Swatinem/rust-cache@v2 - name: Run sccache-cache id: sccache-setup uses: mozilla-actions/sccache-action@v0.0.11 continue-on-error: true - name: Export sccache if: steps.sccache-setup.outcome == 'success' run: | echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV - name: Install locales shell: bash run: | sudo locale-gen fr_FR.UTF-8 sudo update-locale - name: Install tools uses: taiki-e/install-action@v2 with: tool: cargo-codspeed - name: Build benchmarks for ${{ matrix.package }} (${{ matrix.type }}) shell: bash run: | echo "Building ${{ matrix.type }} benchmarks for ${{ matrix.package }}" cargo codspeed build -m ${{ matrix.type }} -p ${{ matrix.package }} - name: Run ${{ matrix.type }} benchmarks for ${{ matrix.package }} uses: CodSpeedHQ/action@v5 env: CODSPEED_LOG: debug with: mode: ${{ matrix.type }} run: | echo "Running ${{ matrix.type }} benchmarks for ${{ matrix.package }}" cargo codspeed run -p ${{ matrix.package }} > /dev/null token: ${{ secrets.CODSPEED_TOKEN }}