Skip to content

Commit ef6a91b

Browse files
authored
Merge pull request #23 from end2endzone/feature-issue21
Implement Github Actions compilation pipeline
2 parents d375479 + 9229ed4 commit ef6a91b

40 files changed

+1126
-0
lines changed

.github/workflows/build_linux.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Linux
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
# build Configuration, i.e. Debug, Release, etc.
7+
PRODUCT_BUILD_TYPE: Release
8+
9+
# build Configuration, i.e. Debug, Release, etc.
10+
Configuration: Release
11+
12+
# Required for Github Action. Unit test TestProcess.testKillAndTerminate fails to start /bin/nano with the following error: "Error opening terminal: unknown."
13+
TERM: xterm
14+
15+
jobs:
16+
build:
17+
# For a list of available runner types, refer to
18+
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Configure GIT
26+
working-directory: ${{env.GITHUB_WORKSPACE}}
27+
shell: bash
28+
run: |
29+
git config --local core.autocrlf true
30+
git config --local advice.detachedHead false
31+
git submodule update --init --recursive
32+
33+
- name: Setup python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
37+
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
38+
39+
- name: Create new environment variables
40+
working-directory: ${{env.GITHUB_WORKSPACE}}
41+
shell: bash
42+
run: |
43+
python -c "import os; print('GIT_REPOSITORY=' + os.path.split(os.getenv('GITHUB_REPOSITORY'))[1]);" >> $GITHUB_ENV
44+
python -c "import os; print('GIT_BRANCH=' + os.path.split(os.getenv('GITHUB_REF'))[1]);" >> $GITHUB_ENV
45+
echo GITHUB_WORKFLOW=$GITHUB_WORKFLOW>> $GITHUB_ENV
46+
47+
- name: List environment variables for debugging
48+
working-directory: ${{env.GITHUB_WORKSPACE}}
49+
shell: bash
50+
run: |
51+
env
52+
53+
- name: Configure user profile and directories
54+
working-directory: ${{env.GITHUB_WORKSPACE}}
55+
shell: bash
56+
run: |
57+
mkdir ~/Documents #required for TestUser.testFoldersExisting() because /home/travis/Documents does not exists!
58+
mkdir ~/Desktop #required for TestUser.testFoldersExisting() because /home/travis/Desktop does not exists!
59+
60+
- name: Install yamlpath
61+
working-directory: ${{env.GITHUB_WORKSPACE}}
62+
shell: bash
63+
run: ./ci/github/install_yamlpath.sh
64+
65+
- name: Install pyserial
66+
working-directory: ${{env.GITHUB_WORKSPACE}}
67+
shell: bash
68+
run: ./ci/github/install_pyserial.sh
69+
70+
- name: Install Arduino CLI
71+
working-directory: ${{env.GITHUB_WORKSPACE}}
72+
shell: bash
73+
run: ./ci/github/install_arduinocli.sh
74+
75+
- name: Install Arduino cores
76+
working-directory: ${{env.GITHUB_WORKSPACE}}
77+
shell: bash
78+
run: ./ci/github/install_arduino_cores.sh
79+
80+
- name: Install Arduino library dependencies
81+
working-directory: ${{env.GITHUB_WORKSPACE}}
82+
shell: bash
83+
run: ./ci/github/arduino_install_libraries.sh
84+
85+
- name: Install this arduino library
86+
working-directory: ${{env.GITHUB_WORKSPACE}}
87+
shell: bash
88+
run: ./ci/github/install_this.sh
89+
90+
- name: Build Arduino sketch - rtttl_blocking
91+
working-directory: ${{env.GITHUB_WORKSPACE}}
92+
shell: bash
93+
run: python ci/generic/arduino_build_sketch.py rtttl_blocking
94+
95+
- name: Build Arduino sketch - rtttl_demo
96+
working-directory: ${{env.GITHUB_WORKSPACE}}
97+
shell: bash
98+
run: python ci/generic/arduino_build_sketch.py rtttl_demo
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Windows
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
PlatformToolset: v142
7+
8+
# build platform, i.e. x86, x64, Any CPU. This setting is optional.
9+
Platform: Win32
10+
11+
# build Configuration, i.e. Debug, Release, etc.
12+
Configuration: Release
13+
14+
jobs:
15+
build:
16+
# For a list of available runner types, refer to
17+
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
18+
runs-on: windows-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Configure GIT
25+
working-directory: ${{env.GITHUB_WORKSPACE}}
26+
shell: cmd
27+
run: |
28+
git config --local core.autocrlf true
29+
git config --local advice.detachedHead false
30+
git submodule update --init --recursive
31+
32+
- name: Setup python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
36+
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
37+
38+
- name: Create new environment variables
39+
working-directory: ${{env.GITHUB_WORKSPACE}}
40+
shell: cmd
41+
run: |
42+
python -c "import os; print('GIT_REPOSITORY=' + os.path.split(os.getenv('GITHUB_REPOSITORY'))[1]);" >> %GITHUB_ENV%
43+
python -c "import os; print('GIT_BRANCH=' + os.path.split(os.getenv('GITHUB_REF'))[1]);" >> %GITHUB_ENV%
44+
echo GITHUB_WORKFLOW=%GITHUB_WORKFLOW%>> %GITHUB_ENV%
45+
46+
- name: List environment variables for debugging
47+
working-directory: ${{env.GITHUB_WORKSPACE}}
48+
shell: cmd
49+
run: |
50+
set
51+
52+
- name: Install yamlpath
53+
working-directory: ${{env.GITHUB_WORKSPACE}}
54+
shell: cmd
55+
run: call ci\github\install_yamlpath.bat
56+
57+
- name: Install pyserial
58+
working-directory: ${{env.GITHUB_WORKSPACE}}
59+
shell: cmd
60+
run: call ci\github\install_pyserial.bat
61+
62+
- name: Install Arduino CLI
63+
working-directory: ${{env.GITHUB_WORKSPACE}}
64+
shell: cmd
65+
run: call ci\github\install_arduinocli.bat
66+
67+
- name: Install Arduino cores
68+
working-directory: ${{env.GITHUB_WORKSPACE}}
69+
shell: cmd
70+
run: call ci\github\install_arduino_cores.bat
71+
72+
- name: Install Arduino library dependencies
73+
working-directory: ${{env.GITHUB_WORKSPACE}}
74+
shell: cmd
75+
run: call ci\github\arduino_install_libraries.bat
76+
77+
- name: Install this arduino library
78+
working-directory: ${{env.GITHUB_WORKSPACE}}
79+
shell: cmd
80+
run: call ci\github\install_this.bat
81+
82+
- name: Build Arduino sketch - rtttl_blocking
83+
working-directory: ${{env.GITHUB_WORKSPACE}}
84+
shell: cmd
85+
run: python ci\generic\arduino_build_sketch.py rtttl_blocking
86+
87+
- name: Build Arduino sketch - rtttl_demo
88+
working-directory: ${{env.GITHUB_WORKSPACE}}
89+
shell: cmd
90+
run: python ci\generic\arduino_build_sketch.py rtttl_demo

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Changes for 1.4.0:
22

33
* Fixed issue #13 - ESP32 Core has changed from 2.x to 3.0.
44
* Fixed issue #20 - Deprecate AppVeyor-based compilation pipeline.
5+
* Fixed issue #21 - Implement Github Actions compilation pipeline.
56

67
Changes for 1.3.0:
78

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Build:
2424

2525
| Service | Build | Tests |
2626
|----|-------|-------|
27+
| Windows Server 2019 | [![Build on Windows](https://github.com/end2endzone/NonBlockingRtttl/actions/workflows/build_windows.yml/badge.svg)](https://github.com/end2endzone/NonBlockingRtttl/actions/workflows/build_windows.yml) | N/A |
28+
| Ubuntu 22.04 | [![Build on Linux](https://github.com/end2endzone/NonBlockingRtttl/actions/workflows/build_linux.yml/badge.svg)](https://github.com/end2endzone/NonBlockingRtttl/actions/workflows/build_linux.yml) | N/A |
2729

2830

2931

ci/arduinocli-core-esp32.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
board_manager:
2+
additional_urls:
3+
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
4+
- https://dl.espressif.com/dl/package_esp32_index.json

ci/arduinocli-core-esp8266.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
board_manager:
2+
additional_urls:
3+
- http://arduino.esp8266.com/stable/package_esp8266com_index.json

ci/generic/arduino_build_sketch.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import os
2+
import sys
3+
import subprocess
4+
5+
import functools
6+
print = functools.partial(print, flush=True)
7+
8+
# Boards to compile for
9+
BOARDS = {
10+
"atmega328": "arduino:avr:nano:cpu=atmega328",
11+
"nodemcuv2": "esp8266:esp8266:nodemcuv2",
12+
"esp32": "esp32:esp32:esp32",
13+
"esp32wroverkit": "esp32:esp32:esp32wroverkit"
14+
}
15+
16+
def find_product_source_dir():
17+
env_dir = os.environ.get("PRODUCT_SOURCE_DIR")
18+
if env_dir:
19+
return env_dir
20+
script_dir = os.path.dirname(os.path.abspath(__file__))
21+
return os.path.abspath(os.path.join(script_dir, "..", ".."))
22+
23+
def check_arduino_cli():
24+
cli_path = os.environ.get("ARDUINO_CLI_INSTALL_DIR", "")
25+
if cli_path:
26+
os.environ["PATH"] += os.pathsep + cli_path
27+
try:
28+
subprocess.run(["arduino-cli", "version"],
29+
stdout=sys.stdout,
30+
check=True
31+
)
32+
except FileNotFoundError:
33+
print("arduino-cli not found in PATH.")
34+
sys.exit(1)
35+
36+
def is_board_compatible(board, boards_file):
37+
try:
38+
with open(boards_file, "r") as f:
39+
lines = [line.strip() for line in f.readlines()]
40+
return "all" in lines or board in lines
41+
except FileNotFoundError:
42+
print(f"No boards.txt found at {boards_file}")
43+
return False
44+
45+
def compile_sketch(sketch_name):
46+
product_dir_path = find_product_source_dir()
47+
sketch_dir_path = os.path.join(product_dir_path, "examples", sketch_name)
48+
ino_file_path = os.path.join(sketch_dir_path, f"{sketch_name}.ino")
49+
boards_file_path = os.path.join(sketch_dir_path, "boards.txt")
50+
ino_file_name = os.path.basename(ino_file_path)
51+
52+
if not os.path.isfile(ino_file_path):
53+
print(f"Sketch file not found: {ino_file_path}")
54+
sys.exit(1)
55+
56+
if not os.path.isfile(boards_file_path):
57+
print(f"No boards.txt found at {boards_file_path}")
58+
sys.exit(1)
59+
60+
print(f"Found boards.txt at {boards_file_path}\n")
61+
62+
for board, fqbn in BOARDS.items():
63+
print("=" * 100)
64+
print(f"Compiling {ino_file_name} for ({board})")
65+
print("=" * 100)
66+
67+
if is_board_compatible(board, boards_file_path):
68+
try:
69+
subprocess.run(
70+
["arduino-cli", "compile", "--fqbn", fqbn, ino_file_path],
71+
stdout=sys.stdout,
72+
cwd=sketch_dir_path,
73+
check=True
74+
)
75+
except subprocess.CalledProcessError as e:
76+
print(f"Compilation failed for {board} with error code {e.returncode}")
77+
sys.exit(e.returncode)
78+
else:
79+
print(f"Skipping sketch compilation for {board} which is incompatible according to it's boards.txt file.")
80+
print("\n")
81+
82+
if __name__ == "__main__":
83+
if len(sys.argv) < 2:
84+
print("Usage: python compile_sketch.py <sketch_name>")
85+
sys.exit(1)
86+
87+
check_arduino_cli()
88+
89+
sketch_name = sys.argv[1]
90+
compile_sketch(sketch_name)

ci/github/arduino_build_sketch.bat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
3+
:: Validate GitHub CI's environment
4+
if "%GITHUB_WORKSPACE%"=="" (
5+
echo Please define 'GITHUB_WORKSPACE' environment variable.
6+
exit /B 1
7+
)
8+
9+
:: Call matching script for windows
10+
call "%GITHUB_WORKSPACE%\ci\windows\%~n0.bat" "%~1"
11+
if %errorlevel% neq 0 exit /b %errorlevel%

ci/github/arduino_build_sketch.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Any commands which fail will cause the shell script to exit immediately
2+
set -e
3+
4+
# Validate GitHub CI environment
5+
if [ "$GITHUB_WORKSPACE" = "" ]; then
6+
echo "Please define 'GITHUB_WORKSPACE' environment variable.";
7+
exit 1;
8+
fi
9+
10+
# Call matching script for linux
11+
this_filename=`basename "$0"`
12+
$GITHUB_WORKSPACE/ci/linux/$this_filename "$1"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@echo off
2+
3+
:: Validate GitHub CI's environment
4+
if "%GITHUB_WORKSPACE%"=="" (
5+
echo Please define 'GITHUB_WORKSPACE' environment variable.
6+
exit /B 1
7+
)
8+
9+
:: Call matching script for windows
10+
call "%GITHUB_WORKSPACE%\ci\windows\%~n0.bat" "%~1"
11+
if %errorlevel% neq 0 exit /b %errorlevel%

0 commit comments

Comments
 (0)