Skip to content
Closed

Dev #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 142 additions & 93 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,93 +1,142 @@
name: XRobot Module Build Test

on:
push:
pull_request:
schedule:
- cron: '0 3 1 * *' # 每月1日凌晨3点(UTC)自动触发

jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/xrobot-org/docker-image-stm32:main
options: --user 0

env:
XR_MODULE_NAME: ${{ github.event.repository.name }}

steps:
- name: install pip packages
run: pip install libxr xrobot

- name: Checkout bsp-dev-c
uses: actions/checkout@v4
with:
repository: QDU-Robomaster/bsp-dev-c
path: bsp-dev-c

- name: config libxr
run: cd bsp-dev-c && xr_cubemx_cfg -d ./ --xrobot

- name: Checkout current module repo to bsp-dev-c/Modules/${{ env.XR_MODULE_NAME }}
uses: actions/checkout@v4
with:
path: bsp-dev-c/Modules/${{ env.XR_MODULE_NAME }}

- name: Checkout SuperPower module
uses: actions/checkout@v4
with:
repository: QDU-Robomaster/SuperPower
path: bsp-dev-c/Modules/SuperPower

- name: Checkout Matrix module
uses: actions/checkout@v4
with:
repository: QDU-Robomaster/Matrix
path: bsp-dev-c/Modules/Matrix

- name: Add modules
run: |
cd bsp-dev-c
rm -rf ./User/xrobot.yaml
xrobot_add_mod SuperPower --instance-id super_power
xrobot_add_mod PowerControl --instance-id power_control
cat ./User/xrobot.yaml

- name: xrobot generate code
run: cd bsp-dev-c && xrobot_gen_main && cat ./User/xrobot_main.hpp


- name: config cmake
run: cd bsp-dev-c && export GCC_TOOLCHAIN_ROOT=/opt/arm-gnu-toolchain-14.2.rel1-x86_64-arm-none-eabi/bin && export CLANG_GCC_CMSIS_COMPILER=/opt/st-arm-clang && cmake . -DCMAKE_TOOLCHAIN_FILE:STRING=cmake/starm-clang.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Bbuild -G Ninja
- name: build
run: cd bsp-dev-c && cmake --build build

- name: Create Tag via GitHub API
if: ${{ success() && github.event_name != 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const moduleTag = process.env.XR_MODULE_NAME;
const date = new Date();
const yyyy = date.getUTCFullYear();
const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
const dd = String(date.getUTCDate()).padStart(2, '0');
const HH = String(date.getUTCHours()).padStart(2, '0');
const MM = String(date.getUTCMinutes()).padStart(2, '0');
const SS = String(date.getUTCSeconds()).padStart(2, '0');
const tagName = `${moduleTag}-${yyyy}${mm}${dd}-${HH}${MM}${SS}`;

// 获取当前 commit sha
const sha = process.env.GITHUB_SHA;

// 创建 tag reference
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: sha
});
console.log(`Created tag: ${tagName} on sha: ${sha}`);

name: XRobot Module Build Test

on:
push:
pull_request:
schedule:
- cron: '0 3 1 * *' # 每月1日凌晨3点(UTC)自动触发

jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/xrobot-org/docker-image-linux:main
options: --user 0

env:
XR_MODULE_NAME: ${{ github.event.repository.name }}

steps:
- name: Checkout current module repo to ./Modules/${{ env.XR_MODULE_NAME }}
uses: actions/checkout@v4
with:
path: Modules/${{ env.XR_MODULE_NAME }}

- name: Create main.cpp
run: |
cat > main.cpp <<'EOF'
#include <iostream>
#include "xrobot_main.hpp"
#include "libxr.hpp"

int main() {
LibXR::PlatformInit();
LibXR::STDIO::Printf("This is XRobot Module Template Test\n");
LibXR::HardwareContainer hw;
XRobotMain(hw);
return 0;
}
EOF

- name: Create minimal CMakeLists.txt
run: |
cat > CMakeLists.txt <<'EOF'
project(xrobot_mod_test CXX)
set(CMAKE_CXX_STANDARD 17)
add_executable(xr_test main.cpp)
set(XROBOT_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Modules/)
add_subdirectory(libxr)
target_include_directories(xr_test PUBLIC $<TARGET_PROPERTY:xr,INTERFACE_INCLUDE_DIRECTORIES> ${CMAKE_SOURCE_DIR}/User)
target_link_libraries(xr_test PUBLIC xr)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using xrobot_setup || true may hide real failures in the toolchain setup.

Because later steps rely on a valid XRobot setup, swallowing non-zero exit codes here can turn a clear setup failure into harder-to-debug downstream errors. If there are specific, expected failure modes, handle those explicitly; otherwise, let the step fail so setup issues surface immediately.

EOF

- name: Pull libxr to ./libxr
run: git clone --depth=1 https://github.com/Jiu-xiao/libxr ./libxr

- name: Checkout Referee module
uses: actions/checkout@v4
with:
repository: QDU-Robomaster/Referee
path: Modules/Referee

- name: Checkout CMD module
uses: actions/checkout@v4
with:
repository: QDU-Robomaster/CMD
path: Modules/CMD

- name: Checkout SuperPower module
uses: actions/checkout@v4
with:
repository: QDU-Robomaster/SuperPower
path: Modules/SuperPower

- name: Setup Python & Install deps
run: |
python3 -m pip install --upgrade pip
pip3 install pyyaml requests

- name: Add XRobot tools to PATH
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Install xrobot toolchain
run: |
pip3 install xrobot libxr

- name: Run xrobot_setup
run: |
xrobot_setup || true

- name: Run xrobot_init_mod
run: |
xrobot_init_mod

- name: Add module
run: |
xrobot_add_mod BlinkLED --instance-id BlinkLED_0
xrobot_add_mod Referee --instance-id referee
xrobot_add_mod CMD --instance-id cmd
xrobot_add_mod SuperPower --instance-id superpower
- name: Add this repo module
run: |
xrobot_add_mod ${{ env.XR_MODULE_NAME }} && cat User/xrobot.yaml

- name: Generate main again
run: |
xrobot_setup

- name: Build
run: |
mkdir -p build
cd build
cmake ..
make

- name: Create Tag via GitHub API
if: ${{ success() && github.event_name != 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const moduleTag = process.env.XR_MODULE_NAME;
const date = new Date();
const yyyy = date.getUTCFullYear();
const mm = String(date.getUTCMonth() + 1).padStart(2, '0');
const dd = String(date.getUTCDate()).padStart(2, '0');
const HH = String(date.getUTCHours()).padStart(2, '0');
const MM = String(date.getUTCMinutes()).padStart(2, '0');
const SS = String(date.getUTCSeconds()).padStart(2, '0');
const tagName = `${moduleTag}-${yyyy}${mm}${dd}-${HH}${MM}${SS}`;

// 获取当前 commit sha
const sha = process.env.GITHUB_SHA;

// 创建 tag reference
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: sha
});
console.log(`Created tag: ${tagName} on sha: ${sha}`);
72 changes: 36 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# CMakeLists.txt for PowerControl

# Add module to include path
target_include_directories(xr PUBLIC ${CMAKE_CURRENT_LIST_DIR})

# Auto-include source files
file(GLOB MODULE_POWERCONTROL_SRC CONFIGURE_DEPENDS
"${CMAKE_CURRENT_LIST_DIR}/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/*.cxx"
"${CMAKE_CURRENT_LIST_DIR}/*.cc"
"${CMAKE_CURRENT_LIST_DIR}/*.c"
)

target_sources(xr PRIVATE ${MODULE_POWERCONTROL_SRC})

# INTERFACE deps shell
get_filename_component(_MODULE_DIRNAME ${CMAKE_CURRENT_LIST_DIR} NAME)
set(_DEPS_TARGET "${_MODULE_DIRNAME}_deps")
add_library(${_DEPS_TARGET} INTERFACE)

# find_package(YourPkg REQUIRED COMPONENTS a b c)

# target_link_libraries(${_DEPS_TARGET} INTERFACE
# # YourLibA
# # YourLibB
# )

# target_compile_definitions(${_DEPS_TARGET} INTERFACE
# # FOO=1
# )
# target_compile_options(${_DEPS_TARGET} INTERFACE
# # -Wall
# )

# Register to global
set_property(GLOBAL APPEND PROPERTY XR_MODULE_DEPS ${_DEPS_TARGET})
# CMakeLists.txt for PowerControl
# Add module to include path
target_include_directories(xr PUBLIC ${CMAKE_CURRENT_LIST_DIR})
# Auto-include source files
file(GLOB MODULE_POWERCONTROL_SRC CONFIGURE_DEPENDS
"${CMAKE_CURRENT_LIST_DIR}/*.cpp"
"${CMAKE_CURRENT_LIST_DIR}/*.cxx"
"${CMAKE_CURRENT_LIST_DIR}/*.cc"
"${CMAKE_CURRENT_LIST_DIR}/*.c"
)
target_sources(xr PRIVATE ${MODULE_POWERCONTROL_SRC})
# INTERFACE deps shell
get_filename_component(_MODULE_DIRNAME ${CMAKE_CURRENT_LIST_DIR} NAME)
set(_DEPS_TARGET "${_MODULE_DIRNAME}_deps")
add_library(${_DEPS_TARGET} INTERFACE)
# find_package(YourPkg REQUIRED COMPONENTS a b c)
# target_link_libraries(${_DEPS_TARGET} INTERFACE
# # YourLibA
# # YourLibB
# )
# target_compile_definitions(${_DEPS_TARGET} INTERFACE
# # FOO=1
# )
# target_compile_options(${_DEPS_TARGET} INTERFACE
# # -Wall
# )
# Register to global
set_property(GLOBAL APPEND PROPERTY XR_MODULE_DEPS ${_DEPS_TARGET})
Loading
Loading