Skip to content

Commit

Permalink
Merge pull request #14 from shadow578/update/ci
Browse files Browse the repository at this point in the history
update CI workflows
  • Loading branch information
shadow578 committed Mar 4, 2024
2 parents 5542136 + 5e121a5 commit ce0067a
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 83 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/build_examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CI - Build examples

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
# generate the build matrix
gen_matrix:
runs-on: ubuntu-latest
outputs:
examples_matrix: ${{ steps.gen_matrix.outputs.matrix }}
steps:
# checkout the repository
- uses: actions/checkout@v4

# generate the build matrix, containing all subdirectories in the 'examples' directory
# that contain a 'platformio.ini' file
- name: Generate build matrix
id: gen_matrix
run: |
# Get all subdirectories containing platformio.ini in the ./example directory
subdirectories=$(find ./examples -type f -name "platformio.ini" -exec dirname {} \; | sort -u)
# Convert subdirectories to JSON array
json_array="["
for subdir in $subdirectories; do
json_array+="\"$subdir\", "
done
json_array="${json_array%, }]"
echo "$json_array"
echo "matrix=$json_array" >> $GITHUB_OUTPUT
# build the CI environment in all examples
build:
runs-on: ubuntu-latest
needs: gen_matrix

# run all examples in a matrix
strategy:
fail-fast: false
matrix:
example: ${{ fromJson(needs.gen_matrix.outputs.examples_matrix) }}

steps:
# checkout the repository
- uses: actions/checkout@v4

# enable caching of pip and platformio
- uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio

# install python
- uses: actions/setup-python@v5
with:
python-version: '3.9'

# install platformio
- name: Install PlatformIO core
run: pip install --upgrade platformio

# print the platformio.ini file path
- name: Print matrix value for 'example'
run: echo ${{ matrix.example }}

# build the 'CI' environment
- name: Build 'ci' environment
run: pio run --project-dir ${{ matrix.example }} --environment ci
43 changes: 7 additions & 36 deletions .github/workflows/ci.yaml → .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI - Unit Tests

on:
push:
Expand All @@ -9,36 +9,7 @@ on:
- main

jobs:
# smoke-test build
build:
runs-on: ubuntu-latest

steps:
# checkout the repository
- uses: actions/checkout@v4

# enable caching of pip and platformio
- uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio

# install python
- uses: actions/setup-python@v5
with:
python-version: '3.9'

# install platformio
- name: Install PlatformIO core
run: pip install --upgrade platformio

# build the 'blink' environment
- name: Build 'blink' environment
run: pio run --environment blink

# unit tests
# run unit tests
test:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -68,17 +39,17 @@ jobs:
- name: Install PlatformIO core
run: pip install --upgrade platformio

# create .pio/test/ folder
- name: Create .pio/test folder
run: mkdir -p .pio/test
# create test/.pio/test/ folder
- name: Create test/.pio/test folder
run: mkdir -p test/.pio/test

# run unit tests using 'test-native' environment
- name: Run Unit Tests (native)
run: pio test --environment test_native --junit-output-path '.pio/test/native.xml'
run: pio test --project-dir ./test --environment native --junit-output-path 'test/.pio/test/native.xml'

# upload test results
- uses: test-summary/action@v2
with:
paths: ".pio/test/*.xml"
paths: "test/.pio/test/*.xml"
show: "all"
if: always()
2 changes: 2 additions & 0 deletions examples/blink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
13 changes: 13 additions & 0 deletions examples/blink/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[env]
platform = https://github.com/shadow578/platform-hc32f46x/archive/1.0.0.zip
framework = arduino
board = generic_hc32f460

[env:default]

# required only for CI
[env:ci]
# override theframework-arduino-hc32f46x package with the local one
board_build.arduino_package_dir = ../../
extra_scripts =
pre:../../tools/ci/patch_get_package_dir.py
File renamed without changes.
43 changes: 0 additions & 43 deletions platformio.ini

This file was deleted.

2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.pio
.vscode
26 changes: 26 additions & 0 deletions test/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# framework-arduino-hc32f46x unit test environment
#
# use the 'test_native' or 'test_win32' environments to run unit tests
#
[env]
test_framework = googletest
test_ignore = # run all tests
build_flags =
-I../cores/arduino # add arduino core to include path
-Itest/stubs # add stubs to include path

# override the framework-arduino-hc32f46x package with the local one
board_build.arduino_package_dir = ../
extra_scripts =
pre:../tools/ci/patch_get_package_dir.py

# run tests on the native platform and toolchain
[env:native]
extends = testenv
platform = native

# run tests on windows, without having to manually install the toolchain
[env:win32]
extends = testenv
platform = windows_x86
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 12 additions & 4 deletions tools/ci/patch_get_package_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@
# does not apply to 'DefaultEnvironment().PioPlatform().get_package_dir()', which is used
# by the hc32f46x build system...
#
# this script is a workaround, patching the 'get_package_dir' method to return the project directory
# for the 'framework-arduino-hc32f46x' package.
# this script is a workaround, patching the 'get_package_dir' method to return the directory
# defined by 'board_build.arduino_package_dir' (relative to $PROJECT_DIR) for the 'framework-arduino-hc32f46x' package.
from SCons.Script import DefaultEnvironment
from os.path import abspath, join

env = DefaultEnvironment()
platform = env.PioPlatform()
original_get_package_dir = platform.get_package_dir

def get_package_dir_override(name):
if name == "framework-arduino-hc32f46x":
return env.subst("$PROJECT_DIR")
project_dir = env.subst("$PROJECT_DIR")
arduino_package_dir = env.BoardConfig().get("build.arduino_package_dir", "")
if arduino_package_dir == "":
raise ValueError("board_build.arduino_package_dir is not defined")

package_dir = abspath(join(project_dir, arduino_package_dir))
print("Using package dir: " + package_dir)
return package_dir
else:
return original_get_package_dir(name)

platform.get_package_dir = get_package_dir_override
platform.get_package_dir = get_package_dir_override

0 comments on commit ce0067a

Please sign in to comment.