Skip to content

Commit 877c5ed

Browse files
authored
ci: Add code coverage check (#99)
2 parents e8b4fb8 + 850f444 commit 877c5ed

File tree

5 files changed

+49
-127
lines changed

5 files changed

+49
-127
lines changed

.github/workflows/esphome-ci.yaml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ jobs:
1919
FILES=$(ls *.yaml | grep -v "secrets.yaml" | jq -R -s -c 'split("\n")[:-1]')
2020
echo "matrix=$FILES" >> "$GITHUB_OUTPUT"
2121
22-
# Step 2 : Compile files
22+
# Step 2 : Check Coverage
23+
coverage:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: 📥 Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: 🧪 Run Coverage Check
30+
env:
31+
TERM: xterm
32+
run: |
33+
./tools/check_coverage.sh
34+
35+
# Step 3 : Compile files
2336
build:
2437
needs: list-files
2538
runs-on: ubuntu-latest
@@ -35,7 +48,7 @@ jobs:
3548
- name: 🔄 Update ref to current branch
3649
run: |
3750
BRANCH_NAME=${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}
38-
echo "Remplace 'ref: main' by 'ref: $BRANCH_NAME' in ${{ matrix.file }}"
51+
echo "Replace 'ref: main' by 'ref: $BRANCH_NAME' in ${{ matrix.file }}"
3952
sed -i "s@ref: main@ref: ${BRANCH_NAME}@g" "${{ matrix.file }}"
4053
4154
- name: 🤫 Create dummy secrets.yaml
@@ -52,16 +65,24 @@ jobs:
5265
wt32_eth01_ota_password: "/TQQDQvCLeJ1RfoihmoIUjSk+PtvOF9oUCoOGI53ie8="
5366
EOF
5467
55-
- name: 💾 Cache PlatformIO & ESPHome
68+
- name: 🔍 Get ESPHome version
69+
id: esphome-version
70+
run: |
71+
pip install esphome
72+
VERSION=$(esphome version | awk '{print $2}')
73+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
74+
echo "ESPHome version: $VERSION"
75+
76+
- name: 💾 Cache PlatformIO & ESPHome (shared)
5677
uses: actions/cache@v4
5778
with:
5879
path: |
5980
~/.cache/pip
6081
~/.platformio
6182
.esphome
62-
key: ${{ runner.os }}-esphome-${{ matrix.file }}-${{ hashFiles(matrix.file) }}
83+
key: ${{ runner.os }}-esphome-${{ steps.esphome-version.outputs.version }}
6384
restore-keys: |
64-
${{ runner.os }}-esphome-${{ matrix.file }}-
85+
${{ runner.os }}-esphome-${{ steps.esphome-version.outputs.version }}
6586
${{ runner.os }}-esphome-
6687
6788
- name: 🚀 Build ESPHome Binary
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# ----------------------------------------------------------------------------------------------------
22
# ESPHome configuration - This part depends on your hardware target
33
# ----------------------------------------------------------------------------------------------------
4-
54
esphome:
6-
name: solarrouter-r
5+
name: solarrouter-schedule-forced-run
76
friendly_name: SolarRouter
87
min_version: 2026.1.0
98

@@ -54,7 +53,7 @@ http_request:
5453
packages:
5554
solar_router:
5655
url: https://github.com/XavierBerger/Solar-Router-for-ESPHome/
57-
ref: main
56+
ref: ci/code_coverage
5857
refresh: 1d
5958
files:
6059
- path: solar_router/common.yaml
@@ -69,3 +68,9 @@ packages:
6968
vars:
7069
green_led_pin: GPIO19
7170
yellow_led_pin: GPIO18
71+
- path: solar_router/scheduler_forced_run.yaml
72+
# vars:
73+
# scheduler_unique_id: "day"
74+
# - path: solar_router/scheduler_forced_run.yaml
75+
# vars:
76+
# scheduler_unique_id: "night"

solar_router/engine_common.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ sensor:
1313
source_id: real_power
1414
name: "Real Power Internal"
1515
id: real_power_internal
16-
internal : 'True'
17-
on_value:
16+
internal: "True"
17+
on_value:
1818
then:
1919
- logger.log: "Real power updated, run energy_regulation if activated"
2020
- if:
@@ -36,7 +36,6 @@ substitutions:
3636
# If activate switch is ON, yellow led update is performed every secondes
3737
time:
3838
- platform: sntp
39-
id: yellow_led_engine_time_trigger
4039
on_time:
4140
# Trigger action every second
4241
- seconds: /1
@@ -76,13 +75,13 @@ time:
7675
output:
7776
- id: yellow_led_output
7877
platform: gpio
79-
pin:
78+
pin:
8079
number: ${yellow_led_pin}
8180
inverted: ${yellow_led_inverted}
8281

8382
- id: green_led_output
8483
platform: gpio
85-
pin:
84+
pin:
8685
number: ${green_led_pin}
8786
inverted: ${green_led_inverted}
8887

solar_router/power_meter_fronius_with_simulated_load.yaml

Lines changed: 0 additions & 108 deletions
This file was deleted.

tools/check_coverage.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
#!/bin/bash
22

3-
# Utilisation de la commande tput pour les couleurs
3+
EXIT_STATUS=0
4+
5+
# Use the tput command for colors
46
GREEN=$(tput setaf 2)
57
RED=$(tput setaf 1)
68
RESET=$(tput sgr0)
79

810
for iloop in $(ls solar_router/*); do
9-
# Extraction du nom de fichier sans le chemin relatif
11+
# Extract the filename without the relative path
1012
filename=$(basename "$iloop")
1113

1214
echo -n "$iloop -> "
1315

14-
# Première recherche dans les fichiers .yaml
15-
if grep -q "$iloop" *.yaml; then
16+
# First search within .yaml files
17+
if grep "$iloop" *.yaml | grep -v local > /dev/null; then
1618
COUNT=$(grep $iloop *.yaml 2> /dev/null | wc -l)
1719
echo "${GREEN}OK ($COUNT)${RESET}"
1820
else
19-
# Si non trouvé, recherche du nom de fichier dans les fichiers du répertoire solar_router
21+
# If not found, search for the filename within the solar_router directory files
2022
if grep -r "$filename" solar_router/*.yaml > /dev/null; then
2123
echo "${GREEN}OK (include)${RESET}"
2224
else
2325
echo "${RED}KO${RESET}"
26+
EXIT_STATUS=1
2427
fi
2528
fi
26-
done
29+
done
30+
31+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)