name: Memory Benchmark

on:
  pull_request:
    types: [opened, synchronize, reopened]

permissions:
  contents: read
  pull-requests: write
  issues: write

jobs:
  memory-benchmark:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 1

      - uses: actions/setup-python@v6
        with:
          python-version: '3.14'

      - uses: astral-sh/setup-uv@v7

      - run: uv pip install '.' 'memray==1.18.0' --system

      - run: python benches/memory/measure.py

      - uses: actions/upload-artifact@v6
        with:
          name: memory-benchmark-results
          path: memory-benchmark-results/
          retention-days: 30

      - uses: peter-evans/find-comment@v4
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          body-includes: Memory Benchmark Results

      - uses: peter-evans/create-or-update-comment@v5
        with:
          comment-id: ${{ steps.fc.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          body-path: memory-benchmark-results/report.md
          edit-mode: replace
