Skip to content

Commit 5329f04

Browse files
committed
feat: ci/cd
1 parent 40c9ba6 commit 5329f04

3 files changed

Lines changed: 574 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
workflow_dispatch:
9+
10+
env:
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build-and-test:
15+
name: Build and Test - ${{ matrix.os }} (${{ matrix.arch }})
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
# Linux x86_64 (主要测试平台)
22+
- os: ubuntu-latest
23+
arch: x86_64
24+
cmake_build_type: Release
25+
use_qemu: false
26+
# Linux x86_64 Debug 构建
27+
- os: ubuntu-latest
28+
arch: x86_64
29+
cmake_build_type: Debug
30+
use_qemu: false
31+
# Linux aarch64 Release 构建 (使用 QEMU 模拟)
32+
- os: ubuntu-latest
33+
arch: aarch64
34+
cmake_build_type: Release
35+
use_qemu: true
36+
37+
steps:
38+
- name: 检出代码
39+
uses: actions/checkout@v4
40+
41+
- name: 设置 QEMU (aarch64)
42+
if: matrix.use_qemu == true
43+
uses: docker/setup-qemu-action@v3
44+
with:
45+
platforms: arm64
46+
47+
- name: 缓存 CMake 构建
48+
uses: actions/cache@v4
49+
with:
50+
path: |
51+
build
52+
~/.cmake
53+
key: ${{ runner.os }}-cmake-${{ matrix.arch }}-${{ matrix.cmake_build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
54+
restore-keys: |
55+
${{ runner.os }}-cmake-${{ matrix.arch }}-${{ matrix.cmake_build_type }}-
56+
57+
- name: 安装构建依赖
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -y \
61+
build-essential \
62+
cmake \
63+
git \
64+
libpthread-stubs0-dev
65+
# 对于 aarch64,安装交叉编译工具链或 QEMU 用户模式
66+
if [ "${{ matrix.arch }}" = "aarch64" ]; then
67+
sudo apt-get install -y \
68+
gcc-aarch64-linux-gnu \
69+
g++-aarch64-linux-gnu \
70+
qemu-user-static \
71+
binfmt-support
72+
fi
73+
74+
- name: 验证工具链版本
75+
run: |
76+
echo "=== CMake 版本 ==="
77+
cmake --version
78+
echo ""
79+
echo "=== 编译器版本 ==="
80+
if [ "${{ matrix.arch }}" = "aarch64" ]; then
81+
aarch64-linux-gnu-gcc --version
82+
aarch64-linux-gnu-g++ --version
83+
else
84+
gcc --version
85+
g++ --version
86+
fi
87+
echo ""
88+
echo "=== 系统信息 ==="
89+
uname -a
90+
echo "目标架构: ${{ matrix.arch }}"
91+
echo "实际架构: $(uname -m)"
92+
93+
- name: 创建构建目录
94+
run: mkdir -p build
95+
96+
- name: 配置 CMake
97+
working-directory: build
98+
run: |
99+
if [ "${{ matrix.arch }}" = "aarch64" ]; then
100+
# 使用交叉编译工具链
101+
cmake .. \
102+
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
103+
-DBUILD_TESTING=ON \
104+
-DCMAKE_SYSTEM_NAME=Linux \
105+
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
106+
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
107+
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
108+
-DCMAKE_FIND_ROOT_PATH=/usr/aarch64-linux-gnu
109+
else
110+
cmake .. \
111+
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \
112+
-DBUILD_TESTING=ON
113+
fi
114+
115+
- name: 构建项目
116+
working-directory: build
117+
run: |
118+
cmake --build . \
119+
--config ${{ matrix.cmake_build_type }} \
120+
--parallel $(nproc) \
121+
--verbose
122+
123+
- name: 运行测试
124+
working-directory: build
125+
run: |
126+
if [ "${{ matrix.arch }}" = "aarch64" ]; then
127+
# 对于 aarch64,使用 QEMU 运行测试
128+
# 设置 QEMU 环境变量
129+
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
130+
# 使用较少的并行任务,因为 QEMU 模拟较慢
131+
ctest --output-on-failure --parallel 2 || ctest --output-on-failure
132+
else
133+
ctest --output-on-failure --parallel $(nproc) || ctest --output-on-failure
134+
fi
135+
continue-on-error: false
136+
137+
- name: 显示测试结果
138+
if: always()
139+
working-directory: build
140+
run: |
141+
echo "=== 测试摘要 ==="
142+
ctest --print-labels || true
143+
echo ""
144+
echo "=== 构建产物 ==="
145+
find . -type f -executable -name "test_*" -exec file {} \; || true
146+
find . -type f -executable -name "*example*" -exec file {} \; || true
147+
148+
build-examples:
149+
name: Build Examples
150+
runs-on: ubuntu-latest
151+
needs: build-and-test
152+
153+
steps:
154+
- name: 检出代码
155+
uses: actions/checkout@v4
156+
157+
- name: 安装构建依赖
158+
run: |
159+
sudo apt-get update
160+
sudo apt-get install -y \
161+
build-essential \
162+
cmake \
163+
git \
164+
libpthread-stubs0-dev
165+
166+
- name: 创建构建目录
167+
run: mkdir -p build
168+
169+
- name: 配置 CMake
170+
working-directory: build
171+
run: |
172+
cmake .. \
173+
-DCMAKE_BUILD_TYPE=Release \
174+
-DBUILD_TESTING=OFF
175+
176+
- name: 构建示例程序
177+
working-directory: build
178+
run: |
179+
cmake --build . \
180+
--config Release \
181+
--parallel $(nproc) \
182+
--target toolset_example action_group_show_l10
183+
184+
- name: 验证示例程序
185+
working-directory: build
186+
run: |
187+
echo "=== 验证构建产物 ==="
188+
if [ -f toolset_example ]; then
189+
echo "✓ toolset_example 构建成功"
190+
file toolset_example
191+
ls -lh toolset_example
192+
else
193+
echo "✗ toolset_example 未找到"
194+
exit 1
195+
fi
196+
if [ -f action_group_show_l10 ]; then
197+
echo "✓ action_group_show_l10 构建成功"
198+
file action_group_show_l10
199+
ls -lh action_group_show_l10
200+
else
201+
echo "✗ action_group_show_l10 未找到"
202+
exit 1
203+
fi
204+
205+
code-quality:
206+
name: Code Quality Checks
207+
runs-on: ubuntu-latest
208+
steps:
209+
- name: 检出代码
210+
uses: actions/checkout@v4
211+
212+
- name: 检查文件编码和换行符
213+
run: |
214+
echo "检查文件编码和换行符..."
215+
# 检查是否有 Windows 换行符
216+
if find . -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.cmake" -o -name "CMakeLists.txt" \) \
217+
-exec file {} \; | grep -q "CRLF"; then
218+
echo "警告: 发现 Windows 换行符 (CRLF)"
219+
exit 1
220+
fi
221+
echo "✓ 文件编码检查通过"
222+
223+
- name: 检查 CMake 语法
224+
run: |
225+
echo "检查 CMake 语法..."
226+
cmake --version
227+
# 尝试解析 CMakeLists.txt
228+
mkdir -p /tmp/cmake-check
229+
cd /tmp/cmake-check
230+
cmake ${{ github.workspace }} -Wno-dev > /dev/null 2>&1 || true
231+
echo "✓ CMake 语法检查完成"
232+
233+
- name: 检查头文件包含
234+
run: |
235+
echo "检查头文件包含..."
236+
# 检查是否有明显的头文件问题
237+
if find ${{ github.workspace }}/include -name "*.h" -exec grep -l "#include.*\.\./" {} \; | head -5; then
238+
echo "警告: 发现相对路径包含"
239+
fi
240+
echo "✓ 头文件检查完成"
241+
242+
summary:
243+
name: CI Summary
244+
runs-on: ubuntu-latest
245+
needs: [build-and-test, build-examples, code-quality]
246+
if: always()
247+
steps:
248+
- name: 生成 CI 摘要
249+
run: |
250+
echo "## CI/CD 构建摘要" >> $GITHUB_STEP_SUMMARY
251+
echo "" >> $GITHUB_STEP_SUMMARY
252+
echo "### 构建状态" >> $GITHUB_STEP_SUMMARY
253+
echo "- 构建和测试: ${{ needs.build-and-test.result }}" >> $GITHUB_STEP_SUMMARY
254+
echo "- 示例构建: ${{ needs.build-examples.result }}" >> $GITHUB_STEP_SUMMARY
255+
echo "- 代码质量: ${{ needs.code-quality.result }}" >> $GITHUB_STEP_SUMMARY
256+
echo "" >> $GITHUB_STEP_SUMMARY
257+
echo "### 详细信息" >> $GITHUB_STEP_SUMMARY
258+
echo "查看上方的作业详情以获取更多信息。" >> $GITHUB_STEP_SUMMARY

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
[![Platform](https://img.shields.io/badge/Platform-Linux-blue.svg)](https://www.linux.org/)
55
[![Architecture](https://img.shields.io/badge/Arch-x86__64%20%7C%20aarch64-lightgrey.svg)]()
6+
[![CI/CD](https://github.com/linker-bot/linkerhand-cpp-sdk/workflows/CI/CD/badge.svg)](https://github.com/linker-bot/linkerhand-cpp-sdk/actions)
67

78
> 用于灵心巧手系列灵巧手的 C++ 软件开发工具包
89
@@ -262,6 +263,7 @@ ctest --output-on-failure
262263

263264
- **测试指南**: [测试文档](docs/TESTING.md)(待创建) - 详细的测试框架安装、编写和运行指南
264265
- **测试说明**: [测试目录 README](tests/README.md) - 测试结构和快速参考
266+
- **CI/CD 文档**: [CI/CD 文档](docs/CI-CD.md) - 持续集成和持续部署配置说明
265267

266268
测试文档包含:
267269
- 测试框架安装和配置(Google Test)

0 commit comments

Comments
 (0)