mirror of
https://github.com/esphome/esphome.git
synced 2024-12-18 19:44:53 +01:00
312799babf
Some checks are pending
CI / Test split components (push) Blocked by required conditions
CI / Create common environment (push) Waiting to run
CI / Check black (push) Blocked by required conditions
CI / Check flake8 (push) Blocked by required conditions
CI / Check pylint (push) Blocked by required conditions
CI / Check pyupgrade (push) Blocked by required conditions
CI / Run script/ci-custom (push) Blocked by required conditions
CI / Run pytest (push) Blocked by required conditions
CI / Check clang-format (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 IDF (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP8266 (push) Blocked by required conditions
CI / list-components (push) Blocked by required conditions
CI / Component test (push) Blocked by required conditions
CI / Split components for testing into 20 groups maximum (push) Blocked by required conditions
CI / CI Status (push) Blocked by required conditions
Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
106 lines
4.2 KiB
Bash
Executable file
106 lines
4.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
help() {
|
|
echo "Usage: $0 [-e <config|compile|clean>] [-c <string>] [-t <string>]" 1>&2
|
|
echo 1>&2
|
|
echo " - e - Parameter for esphome command. Default compile. Common alternative is config." 1>&2
|
|
echo " - c - Component folder name to test. Default *. E.g. '-c logger'." 1>&2
|
|
echo " - t - Target name to test. Put '-t list' to display all possibilities. E.g. '-t esp32-s2-idf-51'." 1>&2
|
|
exit 1
|
|
}
|
|
|
|
# Parse parameter:
|
|
# - `e` - Parameter for `esphome` command. Default `compile`. Common alternative is `config`.
|
|
# - `c` - Component folder name to test. Default `*`.
|
|
esphome_command="compile"
|
|
target_component="*"
|
|
while getopts e:c:t: flag
|
|
do
|
|
case $flag in
|
|
e) esphome_command=${OPTARG};;
|
|
c) target_component=${OPTARG};;
|
|
t) requested_target_platform=${OPTARG};;
|
|
\?) help;;
|
|
esac
|
|
done
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
if ! [ -d "./tests/test_build_components/build" ]; then
|
|
mkdir ./tests/test_build_components/build
|
|
fi
|
|
|
|
start_esphome() {
|
|
if [ -n "$requested_target_platform" ] && [ "$requested_target_platform" != "$target_platform_with_version" ]; then
|
|
echo "Skipping $target_platform_with_version"
|
|
return
|
|
fi
|
|
# create dynamic yaml file in `build` folder.
|
|
# `./tests/test_build_components/build/[target_component].[test_name].[target_platform_with_version].yaml`
|
|
component_test_file="./tests/test_build_components/build/$target_component.$test_name.$target_platform_with_version.yaml"
|
|
|
|
cp $target_platform_file $component_test_file
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
# macOS sed is...different
|
|
sed -i '' "s!\$component_test_file!../../.$f!g" $component_test_file
|
|
else
|
|
sed -i "s!\$component_test_file!../../.$f!g" $component_test_file
|
|
fi
|
|
|
|
# Start esphome process
|
|
echo "> [$target_component] [$test_name] [$target_platform_with_version]"
|
|
set -x
|
|
# TODO: Validate escape of Command line substitution value
|
|
python -m esphome -s component_name $target_component -s component_dir ../../components/$target_component -s test_name $test_name -s target_platform $target_platform $esphome_command $component_test_file
|
|
{ set +x; } 2>/dev/null
|
|
}
|
|
|
|
# Find all test yaml files.
|
|
# - `./tests/components/[target_component]/[test_name].[target_platform].yaml`
|
|
# - `./tests/components/[target_component]/[test_name].all.yaml`
|
|
for f in ./tests/components/$target_component/*.*.yaml; do
|
|
[ -f "$f" ] || continue
|
|
IFS='/' read -r -a folder_name <<< "$f"
|
|
target_component="${folder_name[3]}"
|
|
|
|
IFS='.' read -r -a file_name <<< "${folder_name[4]}"
|
|
test_name="${file_name[0]}"
|
|
target_platform="${file_name[1]}"
|
|
file_name_parts=${#file_name[@]}
|
|
|
|
if [ "$target_platform" = "all" ] || [ $file_name_parts = 2 ]; then
|
|
# Test has *not* defined a specific target platform. Need to run tests for all possible target platforms.
|
|
|
|
for target_platform_file in ./tests/test_build_components/build_components_base.*.yaml; do
|
|
IFS='/' read -r -a folder_name <<< "$target_platform_file"
|
|
IFS='.' read -r -a file_name <<< "${folder_name[3]}"
|
|
target_platform="${file_name[1]}"
|
|
|
|
start_esphome
|
|
done
|
|
|
|
else
|
|
# Test has defined a specific target platform.
|
|
|
|
# Validate we have a base test yaml for selected platform.
|
|
# The target_platform is sourced from the following location.
|
|
# 1. `./tests/test_build_components/build_components_base.[target_platform].yaml`
|
|
# 2. `./tests/test_build_components/build_components_base.[target_platform]-ard.yaml`
|
|
target_platform_file="./tests/test_build_components/build_components_base.$target_platform.yaml"
|
|
if ! [ -f "$target_platform_file" ]; then
|
|
echo "No base test file [./tests/test_build_components/build_components_base.$target_platform.yaml] for component test [$f] found."
|
|
exit 1
|
|
fi
|
|
|
|
for target_platform_file in ./tests/test_build_components/build_components_base.$target_platform*.yaml; do
|
|
# trim off "./tests/test_build_components/build_components_base." prefix
|
|
target_platform_with_version=${target_platform_file:52}
|
|
# ...now remove suffix starting with "." leaving just the test target hardware and software platform (possibly with version)
|
|
# For example: "esp32-s3-idf-50"
|
|
target_platform_with_version=${target_platform_with_version%.*}
|
|
start_esphome
|
|
done
|
|
fi
|
|
done
|