124 lines
3.8 KiB
YAML
124 lines
3.8 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ master, main ]
|
|
pull_request:
|
|
branches: [ master, main ]
|
|
workflow_dispatch:
|
|
inputs:
|
|
enable_cross_build:
|
|
description: "Enable RK3588 cross build job"
|
|
required: false
|
|
default: "false"
|
|
|
|
jobs:
|
|
host-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Install dependencies
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y ninja-build clang-format cppcheck
|
|
|
|
- name: Quality gates (clang-format + cppcheck on changed files)
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
python3 - <<'PY'
|
|
import json, os, subprocess, sys
|
|
|
|
def sh(*args):
|
|
return subprocess.check_output(list(args), text=True).strip()
|
|
|
|
event = os.environ.get('GITHUB_EVENT_NAME','')
|
|
event_path = os.environ.get('GITHUB_EVENT_PATH','')
|
|
payload = {}
|
|
if event_path:
|
|
with open(event_path, 'r', encoding='utf-8') as f:
|
|
payload = json.load(f)
|
|
base = None
|
|
head = os.environ.get('GITHUB_SHA','HEAD')
|
|
|
|
if event == 'pull_request':
|
|
base = (((payload.get('pull_request') or {}).get('base') or {}).get('sha'))
|
|
else:
|
|
base = payload.get('before')
|
|
if base and set(base) == {'0'}:
|
|
base = None
|
|
|
|
if not base:
|
|
# Fallback to previous commit if possible.
|
|
try:
|
|
base = sh('git','rev-parse','HEAD~1')
|
|
except Exception:
|
|
base = None
|
|
|
|
if base:
|
|
diff = subprocess.check_output(['git','diff','--name-only',f'{base}...{head}'], text=True)
|
|
paths = [p.strip() for p in diff.splitlines() if p.strip()]
|
|
else:
|
|
paths = [p.strip() for p in sh('git','ls-files').splitlines() if p.strip()]
|
|
|
|
exts = ('.c','.cc','.cpp','.cxx','.h','.hh','.hpp','.hxx')
|
|
files = []
|
|
for p in paths:
|
|
if not p.endswith(exts):
|
|
continue
|
|
if p.startswith(('third_party/','build/','.git/')):
|
|
continue
|
|
files.append(p)
|
|
if not files:
|
|
print('No C/C++ files changed; skipping format/cppcheck.')
|
|
sys.exit(0)
|
|
|
|
# clang-format
|
|
subprocess.check_call(['clang-format','--version'])
|
|
subprocess.check_call(['clang-format','--dry-run','--Werror',*files])
|
|
|
|
# cppcheck
|
|
subprocess.check_call(['cppcheck','--version'])
|
|
subprocess.check_call([
|
|
'cppcheck',
|
|
'--error-exitcode=1',
|
|
'--enable=warning,style,performance,portability',
|
|
'--inline-suppr',
|
|
'--suppress=missingIncludeSystem',
|
|
'--std=c++17',
|
|
'-I','include',
|
|
'-I','third_party',
|
|
*files,
|
|
])
|
|
PY
|
|
|
|
- name: Configure & build (host)
|
|
env:
|
|
CMAKE_ARGS: -DBUILD_TESTS=ON
|
|
run: |
|
|
./scripts/build_host.sh
|
|
|
|
- name: Run unit tests
|
|
run: |
|
|
ctest --test-dir build/host --output-on-failure
|
|
|
|
rk3588-cross-build:
|
|
if: github.event_name == 'workflow_dispatch' && github.event.inputs.enable_cross_build == 'true'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Install toolchain
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y ninja-build gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
|
- name: Build (cross)
|
|
env:
|
|
RK3588_SYSROOT: /opt/rk3588-sysroot
|
|
run: |
|
|
mkdir -p "$RK3588_SYSROOT"
|
|
./scripts/build_board.sh
|