Skip to content

Commit e3e44a4

Browse files
committed
fix: Separate AVR and ESP platforms from the test pipeline. Reintroduce ESP-Webserver to the test compilation
1 parent eb995ea commit e3e44a4

File tree

4 files changed

+238
-86
lines changed

4 files changed

+238
-86
lines changed

.github/workflows/README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# 📂 GitHub Workflows for Arduino Temperature Control Library
2+
3+
[![Workflow Status](https://github.com/your-username/your-repo/actions/workflows/arduino-ci.yml/badge.svg)](https://github.com/your-username/your-repo/actions/workflows/arduino-ci.yml)
4+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/your-username/your-repo/blob/main/LICENSE)
5+
[![GitHub Releases](https://img.shields.io/github/release/your-username/your-repo.svg?maxAge=3600)](https://github.com/your-username/your-repo/releases)
6+
7+
Automate testing, compilation, and validation of the Arduino Temperature Control Library across multiple platforms using GitHub Actions.
8+
9+
## 🛠️ Workflows Overview
10+
11+
### 1. 📦 Arduino CI Workflow
12+
13+
**Purpose:**
14+
Compiles the library and its examples for both AVR and ESP8266 platforms.
15+
16+
**Trigger:**
17+
Runs on every `push` and `pull_request`.
18+
19+
**Key Features:**
20+
- **AVR Compilation:** Compiles all examples for the AVR platform (e.g., Arduino Uno).
21+
- **ESP8266 Compilation:** Compiles all examples for the ESP8266 platform (e.g., NodeMCU v2).
22+
- **Selective Compilation:** Skips ESP-specific examples (e.g., ESP-WebServer) when compiling for AVR.
23+
- **Unit Testing:** Executes unit tests using the `arduino_ci` framework.
24+
25+
### 2. 🔄 Why Separate AVR and ESP Platforms?
26+
27+
The library supports both AVR-based boards (e.g., Arduino Uno) and ESP8266-based boards (e.g., NodeMCU). Some examples utilize ESP-specific libraries like `ESP8266WiFi.h`, which are incompatible with AVR platforms. Separating the compilation ensures:
28+
29+
- **AVR Compatibility:** Skips ESP-specific examples to prevent compilation errors.
30+
- **ESP Compatibility:** Compiles all examples, including ESP-specific ones, for the ESP8266 platform.
31+
32+
### 3. ⚙️ Workflow Steps
33+
34+
The workflow follows these steps:
35+
36+
1. **Setup Environment:**
37+
- Installs dependencies (e.g., `gcc-avr`, `avr-libc`).
38+
- Configures the Arduino CLI and installs required cores (`arduino:avr` and `esp8266:esp8266`).
39+
40+
2. **Install Libraries:**
41+
- Installs the OneWire library.
42+
- Applies a custom CRC implementation.
43+
44+
3. **Run Unit Tests:**
45+
- Executes unit tests using the `arduino_ci` framework for the AVR platform.
46+
47+
4. **Compile Examples for AVR:**
48+
- Compiles all examples (excluding ESP-specific ones) for the AVR platform.
49+
50+
5. **Compile Examples for ESP8266:**
51+
- Compiles all examples (including ESP-specific ones) for the ESP8266 platform.
52+
53+
### 4. 📁 File Structure
54+
55+
Understanding the project’s file structure is crucial for effective navigation and contribution. Below is an overview of the key files and directories:
56+
57+
- **`Gemfile`**
58+
- **Description:**
59+
Manages Ruby dependencies required for the project. It ensures that the correct versions of gems (like `arduino_ci`) are used.
60+
- **Usage:**
61+
Run `bundle install` to install the necessary gems.
62+
63+
- **`.arduino-ci.yml`**
64+
- **Description:**
65+
Configuration file for the `arduino_ci` tool. It defines how the Arduino CI should run tests and compile sketches.
66+
- **Key Configurations:**
67+
- Specifies which boards to target.
68+
- Defines libraries and dependencies needed for testing.
69+
- Sets up compilation and testing parameters.
70+
71+
- **`.arduino_ci/`**
72+
- **Description:**
73+
Contains supporting files and configurations for the `arduino_ci.rb` tool.
74+
- **Contents:**
75+
- **`config.rb`:**
76+
Custom configuration settings for the Arduino CI.
77+
- **`helpers.rb`:**
78+
Helper methods and utilities used by the CI scripts.
79+
- **Other supporting scripts and assets.**
80+
81+
- **`arduino-ci.yml`**
82+
- **Description:**
83+
GitHub Actions workflow file that defines the CI pipeline for the project.
84+
- **Key Sections:**
85+
- **Jobs:**
86+
Defines the sequence of steps for setting up the environment, installing dependencies, running tests, and compiling examples.
87+
- **Triggers:**
88+
Specifies when the workflow should run (e.g., on push or pull request).
89+
90+
- **`examples/`**
91+
- **Description:**
92+
Contains example sketches demonstrating how to use the Arduino Temperature Control Library.
93+
- **Structure:**
94+
- **`ESP-WebServer/`**
95+
ESP-specific examples that utilize libraries like `ESP8266WiFi.h`.
96+
97+
- **`LICENSE`**
98+
- **Description:**
99+
Contains the MIT License under which the project is released.
100+
101+
- **Other Files and Directories:**
102+
- **`.github/`**
103+
- Contains GitHub-specific configurations, issues templates, and additional workflows.
104+
- **`src/`**
105+
- Contains the source code of the Arduino Temperature Control Library.
106+
107+
### 5. 🔧 Workflow Configuration
108+
109+
The workflow is defined in the `arduino-ci.yml` file. Key configurations include:
110+
111+
- **Cores Installed:**
112+
```yaml
113+
arduino-cli core install arduino:avr
114+
arduino-cli core install esp8266:esp8266
115+
```
116+
117+
- **Skipping ESP-Specific Examples:**
118+
```yaml
119+
export ARDUINO_CI_SKIP_EXAMPLES="ESP-WebServer"
120+
```
121+
122+
- **Compiling for AVR and ESP Platforms:**
123+
```yaml
124+
arduino-cli compile --fqbn arduino:avr:uno "$sketch"
125+
arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 "$sketch"
126+
```
127+
128+
### 6. 🤝 Contributing
129+
130+
If you’re contributing to the workflows, please ensure that:
131+
132+
- **Compatibility:** New examples are compatible with both AVR and ESP platforms (if applicable).
133+
- **Organization:** ESP-specific examples are placed in a clearly labeled directory (e.g., `examples/ESP-WebServer`).
134+
- **Testing:** Unit tests are added or updated as needed.
135+
136+
### 7. 🐞 Troubleshooting
137+
138+
If the workflow fails:
139+
140+
1. **Check Logs:** Navigate to the Actions tab in GitHub for detailed logs.
141+
2. **Local Replication:** Try to replicate the issue locally using the dev container.
142+
3. **Dependencies:** Ensure all dependencies are installed correctly.
143+
144+
## 📄 License
145+
146+
This workflow configuration and scripts are released under the [MIT License](LICENSE).

.github/workflows/arduino-ci.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,22 @@ jobs:
7272
run: |
7373
ls -R
7474
75-
- name: Remove Blacklisted Example Sketches
75+
- name: Run tests (skip example compilation)
7676
run: |
77-
echo "Removing blacklisted example sketches..."
78-
rm -f examples/ESP-WebServer/ESP-WebServer.ino
77+
# Run arduino_ci for unit tests only (skip example compilation)
78+
export ARDUINO_CI_SELECTED_BOARD="arduino:avr:uno"
79+
bundle exec arduino_ci.rb --skip-examples-compilation
7980
80-
- name: Run tests
81+
- name: Compile all sketches for AVR platform
8182
run: |
82-
bundle exec arduino_ci.rb
83+
# Compile all sketches for AVR platform (Arduino Uno), excluding ESP-WebServer
84+
for sketch in $(find examples -name "*.ino" ! -path "*/ESP-WebServer/*"); do
85+
arduino-cli compile --fqbn arduino:avr:uno $sketch
86+
done
87+
88+
- name: Compile all sketches for ESP8266 platform
89+
run: |
90+
# Compile all sketches for ESP8266 platform (NodeMCU v2)
91+
for sketch in $(find examples -name "*.ino"); do
92+
arduino-cli compile --fqbn esp8266:esp8266:nodemcuv2 $sketch
93+
done

test/unit_test_001.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// FILE: unit_test_001.cpp
2+
// AUTHOR: Miles Burton / Rob Tillaart
3+
// DATE: 2021-01-10
4+
// PURPOSE: unit tests for the Arduino-Temperature-Control-Library
5+
// https://github.com/MilesBurton/Arduino-Temperature-Control-Library
6+
7+
8+
#include <ArduinoUnitTests.h>
9+
#include <Arduino.h>
10+
#include <OneWire.h>
11+
#include <DallasTemperature.h>
12+
13+
// Mock pin for testing
14+
#define ONE_WIRE_BUS 2
15+
16+
unittest_setup() {
17+
fprintf(stderr, "VERSION: %s\n", DALLASTEMPLIBVERSION);
18+
}
19+
20+
unittest_teardown() {
21+
fprintf(stderr, "\n");
22+
}
23+
24+
// Test constants defined in the library
25+
unittest(test_models) {
26+
assertEqual(0x10, DS18S20MODEL);
27+
assertEqual(0x28, DS18B20MODEL);
28+
assertEqual(0x22, DS1822MODEL);
29+
assertEqual(0x3B, DS1825MODEL);
30+
assertEqual(0x42, DS28EA00MODEL);
31+
}
32+
33+
// Test error codes defined in the library
34+
unittest(test_error_code) {
35+
assertEqual(DEVICE_DISCONNECTED_C, -127);
36+
assertEqual(DEVICE_DISCONNECTED_F, -196.6);
37+
assertEqual(DEVICE_DISCONNECTED_RAW, -7040);
38+
39+
assertEqual(DEVICE_FAULT_OPEN_C, -254);
40+
assertEqualFloat(DEVICE_FAULT_OPEN_F, -425.2, 0.1);
41+
assertEqual(DEVICE_FAULT_OPEN_RAW, -32512);
42+
43+
assertEqual(DEVICE_FAULT_SHORTGND_C, -253);
44+
assertEqualFloat(DEVICE_FAULT_SHORTGND_F, -423.4, 0.1);
45+
assertEqual(DEVICE_FAULT_SHORTGND_RAW, -32384);
46+
47+
assertEqual(DEVICE_FAULT_SHORTVDD_C, -252);
48+
assertEqualFloat(DEVICE_FAULT_SHORTVDD_F, -421.6, 0.1);
49+
assertEqual(DEVICE_FAULT_SHORTVDD_RAW, -32256);
50+
}
51+
52+
// Test basic initialization and functionality of the DallasTemperature library
53+
unittest(test_initialization) {
54+
OneWire oneWire(ONE_WIRE_BUS);
55+
DallasTemperature sensors(&oneWire);
56+
57+
sensors.begin();
58+
59+
// Initially, there should be no devices detected
60+
assertEqual(0, sensors.getDeviceCount());
61+
assertFalse(sensors.isParasitePowerMode());
62+
}
63+
64+
// Simulate a basic temperature read (mocked)
65+
unittest(test_temperature_read) {
66+
OneWire oneWire(ONE_WIRE_BUS);
67+
DallasTemperature sensors(&oneWire);
68+
69+
sensors.begin();
70+
71+
// Mock reading temperature
72+
float tempC = sensors.getTempCByIndex(0);
73+
assertEqual(DEVICE_DISCONNECTED_C, tempC); // Simulated no device connected
74+
}
75+
76+
unittest_main()

test/unit_test_001.cpp.disabled

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

0 commit comments

Comments
 (0)