Skip to content

Commit d41ebf2

Browse files
committed
Run build example action as matrix on hosted runner
1 parent a4767f4 commit d41ebf2

File tree

7 files changed

+152
-161
lines changed

7 files changed

+152
-161
lines changed

.github/workflows/build-examples.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build Examples
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
jobs:
11+
build-examples:
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
example:
17+
- Async-Server
18+
- Authentication
19+
- HTML-Forms
20+
- HTTPS-and-HTTP
21+
- Middleware
22+
- Parameters
23+
- Parameter-Validation
24+
- Put-Post-Echo
25+
- REST-API
26+
- Self-Signed-Certificate
27+
- Static-Page
28+
- Websocket-Chat
29+
board:
30+
- wrover
31+
- wroom
32+
runs-on: ${{ matrix.os }}
33+
steps:
34+
- name: Checkout codebase
35+
uses: actions/checkout@f90c7b395dac7c5a277c1a6d93d5057c1cddb74e
36+
- name: Set up Python
37+
uses: actions/setup-python@9ac730844c47e52575257e93faf193c4530bc095
38+
with:
39+
python-version: '3.8'
40+
- name: Install PlatformIO
41+
run: |
42+
python -m pip install --upgrade pip
43+
pip install platformio
44+
- name: Build example
45+
run: ./extras/ci/scripts/build-example.sh ${{ matrix.board }} ${{ matrix.example }}

.github/workflows/ci-master.yml

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

.github/workflows/ci-pull.yml

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

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# ESP32 HTTPS Server
22

3-
![Continuous Integration](https://github.com/fhessel/esp32_https_server/workflows/Continuous%20Integration/badge.svg)
4-
53
This repository contains an HTTPS server library that can be used with the [ESP32 Arduino Core](https://github.com/espressif/arduino-esp32). It supports HTTP as well.
64

75
## Features

extras/ci/scripts/build-example.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# This script verifies that every example in the examples directory can be built
4+
5+
# Check that PlatformIO is on the path
6+
if [[ "$(which pio)" == "" ]]; then
7+
echo "::error::PlatformIO executable (pio) not found on PATH. Stop."
8+
echo "::error::PATH=$PATH"
9+
exit 1
10+
fi
11+
12+
# Parse parameters
13+
BOARD="$1"
14+
if [[ "$BOARD" == "" ]]; then
15+
echo "::error::No board specified. Stop."
16+
exit 1
17+
fi
18+
EXAMPLENAME="$2"
19+
if [[ "$EXAMPLENAME" == "" ]]; then
20+
echo "::error::No example specified. Stop."
21+
exit 1
22+
fi
23+
24+
# In general, we want the script to fail if something unexpected happens.
25+
# This flag gets only revoked for the actual build process.
26+
set -e
27+
28+
# Find the script and repository location based on the current script location
29+
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
30+
REPODIR=$(cd "$(dirname $SCRIPTDIR/../../../..)" && pwd)
31+
32+
# Some other directory definitions
33+
TMPDIR="$REPODIR/tmp"
34+
CIDIR="$REPODIR/extras/ci"
35+
EXAMPLEDIR="$REPODIR/examples"
36+
37+
# Re-create build directory
38+
if [ -d "$TMPDIR" ]; then
39+
rm -r "$TMPDIR"
40+
fi
41+
mkdir -p "$TMPDIR"
42+
43+
# Check that an .ino file exists
44+
if [ ! -d "$EXAMPLEDIR/$EXAMPLENAME" ]; then
45+
echo "::error::Example directory does not exist: $EXAMPLENAME"
46+
exit 1
47+
fi
48+
if [ ! -f "$EXAMPLEDIR/$EXAMPLENAME/$EXAMPLENAME.ino" ]; then
49+
echo "::error::Example sketch does not exist: $EXAMPLENAME.ino"
50+
exit 1
51+
fi
52+
53+
# We take the .ino file, rename it as main.cpp and add an Arduino.h include at the top
54+
PROJECTDIR="$TMPDIR/$EXAMPLENAME-$BOARD"
55+
MAINCPP="$PROJECTDIR/src/main.cpp"
56+
INOFILE="$PROJECTDIR/src/$EXAMPLENAME.ino"
57+
58+
# (re-)create the project directory under tmp/
59+
if [ -d "$PROJECTDIR" ] && [ "$PROJECTDIR" != "" ]; then
60+
rm -r "$PROJECTDIR"
61+
fi
62+
63+
# Create the lib folder to link the current version of the library
64+
mkdir -p "$PROJECTDIR/lib"
65+
# Copy the project folder template from ci/templates/example-project
66+
cp -r "$CIDIR/templates/example-project"/* "$PROJECTDIR/"
67+
# Copy the source files
68+
cp -r "$EXAMPLEDIR/$EXAMPLENAME/." "$PROJECTDIR/src"
69+
# Create the library link
70+
ln -s "$REPODIR" "$PROJECTDIR/lib/esp32_https_server"
71+
# Convert .ino to main.cpp
72+
echo "#include <Arduino.h>" > "$MAINCPP"
73+
cat "$INOFILE" >> "$MAINCPP"
74+
rm "$INOFILE"
75+
76+
# If the example has dependencies, rewrite platformio.ini
77+
if [[ -f "$EXAMPLEDIR/$EXAMPLENAME/.ci_lib_deps" ]]; then
78+
LIB_DEPS=$(head -n1 "$EXAMPLEDIR/$EXAMPLENAME/.ci_lib_deps")
79+
sed "s#\\#lib_deps#lib_deps = $LIB_DEPS#" "$PROJECTDIR/platformio.ini" > "$PROJECTDIR/platformio.ini.tmp"
80+
mv "$PROJECTDIR/platformio.ini.tmp" "$PROJECTDIR/platformio.ini"
81+
fi
82+
83+
# Try building the application (+e as we want to test every example and get a
84+
# summary on what is working)
85+
set +e
86+
pio --no-ansi run -d "$PROJECTDIR" -e "$BOARD" 2>&1 | "$CIDIR/scripts/pio-to-gh-log.py"
87+
RC=${PIPESTATUS[0]}
88+
if [[ "$RC" != "0" ]]; then
89+
echo "::error::pio returned with RC=$RC"
90+
fi
91+
exit $RC

extras/ci/scripts/build-examples.sh

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

extras/ci/scripts/pio-to-gh-log.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import re
4+
5+
# Simple Python script that takes PlatformIO's compiler errors and maps them to
6+
# output that can be understood by the Actions runner.
7+
8+
re_err = re.compile(r"^([^:]+):([0-9]+):([0-9]+): error: (.*)$")
9+
10+
for line in sys.stdin:
11+
print(line, end="")
12+
m = re_err.match(line.strip())
13+
if m is not None:
14+
print("::error file={name},line={line},col={col}::{message}".format(
15+
name=m.group(1), line=m.group(2), col=m.group(3), message=m.group(4)
16+
))

0 commit comments

Comments
 (0)