Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
erlingrj committed Feb 13, 2025
1 parent af3d45e commit 91c7ee4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 22 deletions.
16 changes: 16 additions & 0 deletions .github/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build and run Pico template tests
description: Build and run tests for the Pico template

inputs:
template-path:
description: "Path to the root of the template"
required: true
default: "."

runs:
using: "composite"
steps:
- name: Build tests
run: ${{inputs.template-path}}/.github/scripts/run-all.sh
shell: bash

41 changes: 41 additions & 0 deletions .github/scripts/run-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -e

run_with_timeout() {
local duration=$1
shift
local command="$@"

# Run the command but disable exit on error (because timeout will cause an error)
set +e
timeout "$duration" $command

# Get the exit status of the command and then re-enable exit on error (after forcing a true return value)
exit_status=$?
true
set -e

# Check the exit status of the timeout command
if [ $exit_status -eq 124 ]; then
echo "Command timed out (success)."
return 0
elif [ $exit_status -eq 0 ]; then
echo "Command completed successfully within $duration."
return 0
else
echo "Command failed."
return 1
fi
}

build_test() {
local program=$1
cmake -Bbuild -DLF_MAIN=$program
cmake --build build -j $(nproc)
rm -rf build
}

build_test Blink
build_test HelloPico
build_test Timer

26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "CI"

on:
pull_request:

jobs:
ci:
name: Build examples and run tests
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: Clone reactor-uc runtime
run: git clone https://github.com/lf-lang/reactor-uc.git --recursive

- name: Install Pico dependencies
uses: ./reactor-uc/.github/actions/pico

- name: Install LFC dependencies
uses: ./reactor-uc/.github/actions/lingua-franca

- name: Run tests
uses: ./.github/actions/run-tests
32 changes: 10 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,17 @@ if (NOT DEFINED LOG_LEVEL)
set(LOG_LEVEL "LF_LOG_LEVEL_WARN")
endif()

# Run LFC
set(LFC_COMMAND $ENV{REACTOR_UC_PATH}/lfc/bin/lfc-dev ${CMAKE_CURRENT_SOURCE_DIR}/src/${LF_MAIN}.lf)
execute_process(COMMAND echo "Running LFC: ${LFC_COMMAND}")
execute_process(
COMMAND ${LFC_COMMAND}
ECHO_OUTPUT_VARIABLE
COMMAND_ERROR_IS_FATAL ANY
)

file(GLOB_RECURSE LF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.lf)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LF_SOURCES})
message(STATUS "Found LF sources: ${LF_SOURCES}")

pico_sdk_init()

include(src-gen/${LF_MAIN}/CMakeLists.txt)
add_subdirectory(${REACTOR_UC_PATH})
target_compile_definitions(reactor-uc PUBLIC LF_LOG_LEVEL_ALL=${LOG_LEVEL})
set(LF_MAIN_TARGET ${LF_MAIN})
add_executable(${LF_MAIN_TARGET})

include($ENV{REACTOR_UC_PATH}/cmake/lfc.cmake)

add_executable(${LF_MAIN} ${LFC_GEN_MAIN} ${LFC_GEN_SOURCES})
target_include_directories(${LF_MAIN} PRIVATE ${LFC_GEN_INCLUDE_DIRS})
target_link_libraries(${LF_MAIN} PUBLIC reactor-uc)
target_link_libraries(${LF_MAIN} PUBLIC pico_stdlib pico_sync)
lf_setup()
lf_run_lfc(${CMAKE_CURRENT_SOURCE_DIR}/src ${LF_MAIN})
lf_build_generated_code(${LF_MAIN_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/src-gen/${LF_MAIN})

pico_enable_stdio_usb(${LF_MAIN} 1)
pico_enable_stdio_uart(${LF_MAIN} 1)
target_link_libraries(${LF_MAIN_TARGET} PUBLIC pico_stdlib pico_sync)
pico_enable_stdio_usb(${LF_MAIN_TARGET} 1)
pico_enable_stdio_uart(${LF_MAIN_TARGET} 1)

0 comments on commit 91c7ee4

Please sign in to comment.