|
4 | 4 | push: |
5 | 5 | branches: [main] |
6 | 6 | paths: |
7 | | - - cpp-linter/src/ |
8 | | - - cpp-linter/benches/ |
| 7 | + - cpp-linter/src/** |
9 | 8 | - cpp-linter/Cargo.toml |
10 | 9 | - Cargo.toml |
11 | 10 | - Cargo.lock |
12 | 11 | - .github/workflows/benchmark.yml |
13 | | - tags-ignore: ['*'] |
14 | 12 | pull_request: |
15 | 13 | branches: [main] |
16 | 14 | paths: |
17 | | - - cpp-linter/src/ |
18 | | - - cpp-linter/benches/ |
| 15 | + - cpp-linter/src/** |
19 | 16 | - cpp-linter/Cargo.toml |
20 | 17 | - Cargo.toml |
21 | 18 | - Cargo.lock |
22 | 19 | - .github/workflows/benchmark.yml |
23 | | - # `workflow_dispatch` allows CodSpeed to trigger back-test |
24 | | - # performance analysis in order to generate initial data. |
25 | | - workflow_dispatch: |
26 | 20 |
|
27 | | -# This CI workflow can take up to 2 hours. |
28 | | -# This setting will auto-cancel a old run if a new run is started. |
| 21 | +permissions: {} |
| 22 | + |
29 | 23 | concurrency: |
30 | 24 | group: ${{ github.workflow }}-${{ github.ref }} |
31 | | - cancel-in-progress: true |
| 25 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
32 | 26 |
|
33 | 27 | jobs: |
| 28 | + build-bin: |
| 29 | + name: Build ${{ matrix.name }} binary |
| 30 | + runs-on: ubuntu-latest |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + include: |
| 34 | + - commit: ${{ github.sha }} |
| 35 | + name: current |
| 36 | + - commit: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} |
| 37 | + name: previous |
| 38 | + env: |
| 39 | + BIN: target/release/cpp-linter |
| 40 | + steps: |
| 41 | + - name: Checkout ${{ matrix.name }} |
| 42 | + uses: actions/checkout@v5 |
| 43 | + with: |
| 44 | + ref: ${{ matrix.commit }} |
| 45 | + persist-credentials: false |
| 46 | + - name: Cache base ref build |
| 47 | + uses: actions/cache@v4 |
| 48 | + id: cache |
| 49 | + with: |
| 50 | + key: bin-cache-${{ hashFiles('cpp-linter/src/**', 'Cargo.toml', 'Cargo.lock', 'cpp-linter/Cargo.toml') }} |
| 51 | + path: ${{ env.BIN }} |
| 52 | + - name: Validate cached binary |
| 53 | + if: steps.cache.outputs.cache-hit == 'true' |
| 54 | + id: validate |
| 55 | + run: | |
| 56 | + chmod +x ${{ env.BIN }} |
| 57 | + if ! ${{ env.BIN }} version; then |
| 58 | + echo "Cached binary is invalid, rebuilding..." |
| 59 | + echo "cache-valid=false" >> "$GITHUB_OUTPUT" |
| 60 | + fi |
| 61 | + - run: rustup update --no-self-update |
| 62 | + if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false' |
| 63 | + - run: cargo build --bin cpp-linter --release |
| 64 | + if: steps.cache.outputs.cache-hit != 'true' || steps.validate.outputs.cache-valid == 'false' |
| 65 | + - name: Upload build artifact |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: ${{ matrix.name }} |
| 69 | + path: ${{ env.BIN }} |
| 70 | + |
| 71 | + build-py-binding: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v5 |
| 75 | + with: |
| 76 | + persist-credentials: false |
| 77 | + - name: Set up Python |
| 78 | + uses: actions/setup-python@v4 |
| 79 | + id: setup-python |
| 80 | + with: |
| 81 | + python-version: '3.x' |
| 82 | + - name: Build wheels |
| 83 | + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 |
| 84 | + with: |
| 85 | + target: x86_64 |
| 86 | + args: --release --out dist --find-interpreter |
| 87 | + manylinux: auto |
| 88 | + before-script-linux: | |
| 89 | + # NOTE: rust-cross/manylinux docker images are CentOS based |
| 90 | + yum update -y |
| 91 | + yum install -y openssl openssl-devel |
| 92 | + - name: Upload wheels |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: wheel |
| 96 | + path: dist/* |
| 97 | + |
34 | 98 | benchmark: |
| 99 | + name: Measure Performance Difference |
| 100 | + needs: [build-bin, build-py-binding] |
35 | 101 | runs-on: ubuntu-latest |
36 | 102 | steps: |
37 | 103 | - uses: actions/checkout@v5 |
38 | | - # using the generated compilation database, |
39 | | - # we will use cpp-linter to scan libgit2 src/libgit2/**.c files. |
| 104 | + with: |
| 105 | + persist-credentials: false |
40 | 106 | - name: Checkout libgit2 |
41 | 107 | uses: actions/checkout@v5 |
42 | 108 | with: |
43 | 109 | repository: libgit2/libgit2 |
44 | 110 | ref: v1.8.1 |
45 | | - path: cpp-linter/benches/libgit2 |
46 | | - - name: Generate compilation database |
47 | | - working-directory: cpp-linter/benches/libgit2 |
48 | | - run: | |
49 | | - mkdir build && cd build |
50 | | - cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. |
| 111 | + path: benchmark/libgit2 |
| 112 | + persist-credentials: false |
| 113 | + |
| 114 | + - name: Download built binaries |
| 115 | + uses: actions/download-artifact@v5 |
| 116 | + |
51 | 117 | - name: Install cargo-binstall |
52 | | - uses: cargo-bins/cargo-binstall@main |
53 | | - - name: Install cargo-codspeed |
54 | | - run: cargo binstall -y cargo-codspeed |
55 | | - - name: Build the benchmark target(s) |
56 | | - run: cargo codspeed build |
57 | | - - name: Run benchmarks |
58 | | - uses: CodSpeedHQ/action@v4 |
59 | | - with: |
60 | | - mode: instrumentation |
61 | | - run: cargo codspeed run |
62 | | - token: ${{ secrets.CODSPEED_TOKEN }} |
| 118 | + uses: cargo-bins/cargo-binstall@38e8f5e4c386b611d51e8aa997b9a06a3c8eb67a # v1.15.6 |
| 119 | + env: |
| 120 | + GITHUB_TOKEN: ${{ github.token }} |
| 121 | + - name: Install hyperfine |
| 122 | + env: |
| 123 | + GITHUB_TOKEN: ${{ github.token }} |
| 124 | + run: cargo binstall -y hyperfine |
| 125 | + - name: Install nushell |
| 126 | + uses: hustcer/setup-nu@985d59ec83ae3e3418f9d36471cda38b9d8b9879 # v3.20 |
| 127 | + - name: Install uv |
| 128 | + uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0 |
| 129 | + |
| 130 | + - name: Run benchmark script |
| 131 | + working-directory: benchmark |
| 132 | + shell: nu {0} |
| 133 | + run: |- |
| 134 | + let new_py = ( |
| 135 | + glob "../wheel/cpp_linter-*.whl" |
| 136 | + | first |
| 137 | + | path expand |
| 138 | + ) |
| 139 | + let prev_bin = "../previous/cpp-linter" | path expand |
| 140 | + let curr_bin = "../current/cpp-linter" | path expand |
| 141 | + nu benchmark.nu --new-py $new_py --rust-bin $curr_bin --prev-rust-bin $prev_bin |
0 commit comments