1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 22:53:59 +00:00
Files
esphome/.github/workflows/memory-impact.yml
2025-10-14 13:05:02 -10:00

151 lines
5.8 KiB
YAML

---
name: Memory Impact Analysis
on:
pull_request:
paths:
- "esphome/components/**"
- "esphome/core/**"
permissions:
contents: read
pull-requests: write
env:
DEFAULT_PYTHON: "3.11"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
detect-single-component:
name: Detect single component change
runs-on: ubuntu-24.04
outputs:
should_run: ${{ steps.detect.outputs.should_run }}
component: ${{ steps.detect.outputs.component }}
test_file: ${{ steps.detect.outputs.test_file }}
platform: ${{ steps.detect.outputs.platform }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyYAML
- name: Detect single component change
id: detect
run: |
python script/ci_memory_impact_detector.py
build-target-branch:
name: Build target branch
runs-on: ubuntu-24.04
needs: detect-single-component
if: needs.detect-single-component.outputs.should_run == 'true'
outputs:
ram_usage: ${{ steps.extract.outputs.ram_usage }}
flash_usage: ${{ steps.extract.outputs.flash_usage }}
steps:
- name: Check out target branch
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: ${{ github.base_ref }}
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install ESPHome
run: |
pip install -e .
- name: Cache platformio
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ~/.platformio
key: platformio-memory-${{ needs.detect-single-component.outputs.platform }}-${{ hashFiles('platformio.ini') }}
- name: Compile test configuration and extract memory usage
id: extract
run: |
component="${{ needs.detect-single-component.outputs.component }}"
platform="${{ needs.detect-single-component.outputs.platform }}"
test_file="${{ needs.detect-single-component.outputs.test_file }}"
echo "Compiling $component for $platform using $test_file"
python script/test_build_components.py -e compile -c "$component" -t "$platform" --no-grouping 2>&1 | \
python script/ci_memory_impact_extract.py --output-env
build-pr-branch:
name: Build PR branch
runs-on: ubuntu-24.04
needs: detect-single-component
if: needs.detect-single-component.outputs.should_run == 'true'
outputs:
ram_usage: ${{ steps.extract.outputs.ram_usage }}
flash_usage: ${{ steps.extract.outputs.flash_usage }}
steps:
- name: Check out PR branch
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install ESPHome
run: |
pip install -e .
- name: Cache platformio
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ~/.platformio
key: platformio-memory-${{ needs.detect-single-component.outputs.platform }}-${{ hashFiles('platformio.ini') }}
- name: Compile test configuration and extract memory usage
id: extract
run: |
component="${{ needs.detect-single-component.outputs.component }}"
platform="${{ needs.detect-single-component.outputs.platform }}"
test_file="${{ needs.detect-single-component.outputs.test_file }}"
echo "Compiling $component for $platform using $test_file"
python script/test_build_components.py -e compile -c "$component" -t "$platform" --no-grouping 2>&1 | \
python script/ci_memory_impact_extract.py --output-env
comment-results:
name: Comment memory impact
runs-on: ubuntu-24.04
needs:
- detect-single-component
- build-target-branch
- build-pr-branch
if: needs.detect-single-component.outputs.should_run == 'true'
steps:
- name: Check out code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Post or update PR comment
env:
GH_TOKEN: ${{ github.token }}
COMPONENT: ${{ needs.detect-single-component.outputs.component }}
PLATFORM: ${{ needs.detect-single-component.outputs.platform }}
TARGET_RAM: ${{ needs.build-target-branch.outputs.ram_usage }}
TARGET_FLASH: ${{ needs.build-target-branch.outputs.flash_usage }}
PR_RAM: ${{ needs.build-pr-branch.outputs.ram_usage }}
PR_FLASH: ${{ needs.build-pr-branch.outputs.flash_usage }}
run: |
python script/ci_memory_impact_comment.py \
--pr-number "${{ github.event.pull_request.number }}" \
--component "$COMPONENT" \
--platform "$PLATFORM" \
--target-ram "$TARGET_RAM" \
--target-flash "$TARGET_FLASH" \
--pr-ram "$PR_RAM" \
--pr-flash "$PR_FLASH"