Skip to content

CI

CI #1976

Workflow file for this run

name: CI
on: # yamllint disable-line rule:truthy
push:
branches:
- main
pull_request:
schedule:
- cron: 0 12 * * *
workflow_dispatch:
permissions:
contents: read
env:
FORCE_COLOR: 1
DEFAULT_PYTHON: "3.11"
PYUPGRADE_TARGET: "--py311-plus"
concurrency:
# yamllint disable-line rule:line-length
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
yamllint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Run yamllint
uses: frenck/action-yamllint@34b4bbcaeabedcfefad6adea8c5bbc42af0e2d47 # v1.5.0
with:
config: .yamllint
bundle:
name: Bundle external component and ESPHome
runs-on: ubuntu-24.04
outputs:
repo-hash: ${{ github.sha }}
steps:
- name: Check out this project
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check out code from ESPHome project
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: esphome/esphome
ref: dev
path: esphome
- name: Copy external component and tests into the esphome project
run: |
cd esphome
cp -r ../components/* esphome/components/
mkdir -p tests/components
cp -r ../tests/components/* tests/components/
git config user.name "ci"
git config user.email "ci@github.com"
git add .
git commit -a -m "Add external component"
ln -sf ../venv venv
- name: Archive prepared repository
uses: pyTooling/upload-artifact@a59f191f676112c140f4330026bbb6ac19b7a44d # v7
with:
name: bundle
path: .
include-hidden-files: true
retention-days: 1
common:
name: Create common environment
runs-on: ubuntu-24.04
needs: bundle
outputs:
cache-key: ${{ steps.cache-key.outputs.key }}
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Generate cache-key
id: cache-key
run: echo key="${{ hashFiles('esphome/requirements.txt', 'esphome/requirements_test.txt') }}" >> $GITHUB_OUTPUT
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: venv
# yamllint disable-line rule:line-length
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ steps.cache-key.outputs.key }}
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
python --version
cd esphome
pip install -r requirements.txt -r requirements_test.txt
pip install -e .
ruff:
name: Check ruff
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Run Ruff
run: |
. venv/bin/activate
ruff format esphome tests
- name: Suggested changes
run: script/ci-suggest-changes
if: always()
flake8:
name: Check flake8
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Run flake8
run: |
. venv/bin/activate
flake8 esphome
- name: Suggested changes
run: script/ci-suggest-changes
if: always()
pylint:
name: Check pylint
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Run pylint
run: |
. venv/bin/activate
pylint -f parseable --persistent=n esphome
- name: Suggested changes
run: script/ci-suggest-changes
if: always()
pyupgrade:
name: Check pyupgrade
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Run pyupgrade
run: |
. venv/bin/activate
pyupgrade ${{ env.PYUPGRADE_TARGET }} `find esphome -name "*.py" -type f`
- name: Suggested changes
run: script/ci-suggest-changes
if: always()
ci-custom:
name: Run script/ci-custom
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Register matcher
run: echo "::add-matcher::.github/workflows/matchers/ci-custom.json"
- name: Do not suggest to move consts
run: |
sed -i 's#if len(uses) < 3:#if len(uses) < 8:#' script/ci-custom.py
git update-index --assume-unchanged script/ci-custom.py
- name: Run script/ci-custom
run: |
. ../venv/bin/activate
script/ci-custom.py
clang-format:
name: Check clang-format
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Install clang-format
run: |
. venv/bin/activate
pip install clang-format -c requirements_dev.txt
- name: Run clang-format
run: |
. venv/bin/activate
script/clang-format -i
- name: Suggested changes
run: script/ci-suggest-changes
if: always()
clang-tidy:
name: ${{ matrix.name }}
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
strategy:
fail-fast: false
max-parallel: 2
matrix:
include:
- id: clang-tidy
name: Run script/clang-tidy for ESP8266
options: --environment esp8266-arduino-tidy --grep USE_ESP8266
pio_cache_key: tidyesp8266
- id: clang-tidy
name: Run script/clang-tidy for ESP32 Arduino
options: --environment esp32-arduino-tidy
pio_cache_key: tidyesp32
- id: clang-tidy
name: Run script/clang-tidy for ESP32 IDF
options: --environment esp32-idf-tidy --grep USE_ESP_IDF
pio_cache_key: tidyesp32-idf
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Cache platformio
if: github.ref == 'refs/heads/main'
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.platformio
key: platformio-${{ matrix.pio_cache_key }}-${{ hashFiles('esphome/platformio.ini') }}
restore-keys: platformio-${{ matrix.pio_cache_key }}-
- name: Cache platformio
if: github.ref != 'refs/heads/main'
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.platformio
key: platformio-${{ matrix.pio_cache_key }}-${{ hashFiles('esphome/platformio.ini') }}
restore-keys: platformio-${{ matrix.pio_cache_key }}-
- name: Register problem matchers
run: |
echo "::add-matcher::.github/workflows/matchers/gcc.json"
echo "::add-matcher::.github/workflows/matchers/clang-tidy.json"
- name: Run 'pio run --list-targets -e esp32-idf-tidy'
if: matrix.name == 'Run script/clang-tidy for ESP32 IDF'
run: |
. venv/bin/activate
mkdir -p .temp
pio run --list-targets -e esp32-idf-tidy
- name: Install clang-tidy
run: |
. venv/bin/activate
pip install clang-tidy -c requirements_dev.txt
- name: Run clang-tidy
run: |
. venv/bin/activate
script/clang-tidy --all-headers --fix ${{ matrix.options }} $(ls ../components/)
env:
# Also cache libdeps, store them in a ~/.platformio subfolder
PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps
- name: Suggested changes
run: script/ci-suggest-changes
# yamllint disable-line rule:line-length
if: always()
pytest:
name: Run pytest
runs-on: ubuntu-24.04
needs:
- bundle
- common
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Run pytest
run: |
. venv/bin/activate
pytest tests/ -v
cpp-unit-tests:
name: Run C++ unit tests
runs-on: ubuntu-24.04
needs:
- bundle
- common
defaults:
run:
working-directory: esphome
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Update index to make "git diff-index" happy
run: git update-index -q --really-refresh
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Cache platformio
if: github.ref == 'refs/heads/main'
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.platformio
key: platformio-host-${{ hashFiles('esphome/platformio.ini') }}
restore-keys: platformio-host-
- name: Cache platformio
if: github.ref != 'refs/heads/main'
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.platformio
key: platformio-host-${{ hashFiles('esphome/platformio.ini') }}
restore-keys: platformio-host-
- name: Run C++ unit tests
run: |
. venv/bin/activate
script/cpp_unit_test.py atorch_dl24
env:
PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps
ASAN_OPTIONS: detect_leaks=0
esphome-config:
name: Validate example configurations
runs-on: ubuntu-24.04
needs:
- bundle
- common
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Register matcher
run: echo "::add-matcher::.github/workflows/matchers/esphome-config.json"
- name: Validate example configurations
run: |
. venv/bin/activate
echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password\ndl24_mac_address: FF:FF:FF:FF:FF:FF\ndl24_mac_address0: FF:FF:FF:FF:FF:F0\ndl24_mac_address1: FF:FF:FF:FF:FF:F1\n" > secrets.yaml
for YAML in esp*.yaml; do
esphome -s external_components_source components config $YAML
done
- name: Validate test configurations
run: |
. venv/bin/activate
echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password\ndl24_mac_address: FF:FF:FF:FF:FF:FF\ndl24_mac_address0: FF:FF:FF:FF:FF:F0\ndl24_mac_address1: FF:FF:FF:FF:FF:F1\n" > tests/secrets.yaml
for YAML in tests/esp*.yaml; do
esphome -s external_components_source ../components config $YAML
done
esphome-compile:
name: Build example configurations
runs-on: ubuntu-24.04
needs:
- bundle
- common
steps:
- name: Download prepared repository
uses: pyTooling/download-artifact@dc575e4e9df4b6e3580712285f1c90f579bb8712 # v8
with:
name: bundle
path: .
- name: Restore Python
uses: ./.github/actions/restore-python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
cache-key: ${{ needs.common.outputs.cache-key }}
- name: Cache platformio
if: github.ref == 'refs/heads/main'
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.platformio
key: platformio-compile-${{ hashFiles('esphome/platformio.ini') }}
restore-keys: platformio-compile-
- name: Cache platformio
if: github.ref != 'refs/heads/main'
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.platformio
key: platformio-compile-${{ hashFiles('esphome/platformio.ini') }}
restore-keys: platformio-compile-
- name: Compile example configurations
run: |
. venv/bin/activate
echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password\ndl24_mac_address: FF:FF:FF:FF:FF:FF\ndl24_mac_address0: FF:FF:FF:FF:FF:F0\ndl24_mac_address1: FF:FF:FF:FF:FF:F1\n" > secrets.yaml
for YAML in esp*faker.yaml esp32-dc-meter-example-advanced-multiple-devices.yaml; do
esphome -s external_components_source components compile $YAML
done
env:
PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps
- name: Compile test configurations
run: |
. venv/bin/activate
echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password\ndl24_mac_address: FF:FF:FF:FF:FF:FF\ndl24_mac_address0: FF:FF:FF:FF:FF:F0\ndl24_mac_address1: FF:FF:FF:FF:FF:F1\n" > tests/secrets.yaml
esphome -s external_components_source ../components compile tests/esp32c6-compatibility-test.yaml
env:
PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps