1
0
mirror of https://github.com/j178/prek.git synced 2026-04-03 17:34:03 +02:00
Files
prek/.github/workflows/performance.yml
2026-01-27 07:48:02 +08:00

105 lines
3.1 KiB
YAML

name: Performance
on:
workflow_call:
inputs:
save-rust-cache:
required: false
type: string
default: "true"
permissions: {}
env:
# Cargo env vars
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: 10
jobs:
bloat-check:
runs-on: ubuntu-latest
name: "cargo | bloat check"
timeout-minutes: 10
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
with:
save-if: ${{ inputs.save-rust-cache == 'true' }}
- uses: taiki-e/install-action@542cebaaed782771e619bd5609d97659d109c492 # v2.66.7
with:
tool: cargo-bloat
- name: Build head branch
id: bloat_head
run: |
# Build head branch
cargo bloat --release | tee bloat_head.txt >&1
- name: Checkout base
run: |
git checkout ${{ github.event.pull_request.base.sha }}
- name: Build base branch
id: bloat_base
run: |
# Build base branch
cargo bloat --release | tee bloat_base.txt >&1
- name: Compare bloat results
shell: python
run: |
import re
from pathlib import Path
def parse_size(text):
match = re.search(r'\.text section size.*?([\d.]+)\s*([KMGT]i?B)', text)
if not match:
raise ValueError("Could not find .text section size")
value, unit = float(match.group(1)), match.group(2)
multipliers = {'B': 1, 'KiB': 1024, 'MiB': 1024**2, 'GiB': 1024**3, 'TiB': 1024**4}
size = value * multipliers.get(unit, 1)
return size, f"{value} {unit}"
head_text = Path('bloat_head.txt').read_text()
base_text = Path('bloat_base.txt').read_text()
head_bytes, head_size = parse_size(head_text)
base_bytes, base_size = parse_size(base_text)
pct_change = ((head_bytes - base_bytes) / base_bytes) * 100
pct_display = f"{pct_change:+.2f}%"
comparison = f"""\
### 📦 Cargo Bloat Comparison
**Binary size change:** {pct_display} ({base_size} → {head_size})
<details>
<summary>Expand for cargo-bloat output</summary>
#### Head Branch Results
```
{head_text}
```
#### Base Branch Results
```
{base_text}
```
</details>
"""
Path("bloat-comparison.txt").write_text(comparison)
- name: Upload bloat results
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
# NOTE: prek-ci-bot uses this artifact name to post comments on PRs.
# Make sure to update the bot if you rename the artifact.
name: bloat-check-results
path: bloat-comparison.txt