Files
H100PowerManger/.gitea/workflows/ci.yml
T

147 lines
6.7 KiB
YAML

#=======================================================================
# FILE: .gitea/workflows/ci.yml
# DESC: CI/CD for H100PowerManger
# - build/test on aarch64 (QEMU emulation of arm64 Ubuntu 20.04)
# - deploy the cross-built binary to the RK3588 board
# Self-contained (no external actions). The runner is an Alpine
# container with the host Docker socket mounted; we install the
# docker CLI at runtime.
#=======================================================================
name: build-test-deploy
on:
push:
branches: [main]
tags: ['v*']
pull_request:
env:
CI_IMAGE: h100-power-manager-ci:arm64
GITEA_SERVER: https://gitea2.zhaojingkui.xyz
jobs:
ci:
runs-on: <runner_labels>
steps:
#-------------------------------------------------------------------
# Checkout via git (no external actions/checkout dependency)
#-------------------------------------------------------------------
- name: Checkout
run: |
set -euo pipefail
git init .
git remote add origin "https://zjk:${{ secrets.CI_TOKEN }}@gitea2.zhaojingkui.xyz/zjk/H100PowerManger.git"
git fetch --depth 1 origin "$GITHUB_SHA"
git checkout FETCH_HEAD
#-------------------------------------------------------------------
# Install runtime tooling inside the (Alpine) runner container
#-------------------------------------------------------------------
- name: Install tools
run: |
apk add --no-cache docker-cli docker-cli-buildx rsync openssh-client
- name: Verify docker
run: |
docker version
docker info 2>&1 | grep -Ei 'Architecture|Server Version|Operating System|Storage Driver' || true
#-------------------------------------------------------------------
# Register QEMU so arm64 images can run on the x86 host daemon
#-------------------------------------------------------------------
- name: Register QEMU for arm64
run: |
docker run --rm --privileged tonistiigi/binfmt --install arm64 \
|| docker run --rm --privileged docker.m.daocloud.io/tonistiigi/binfmt --install arm64
#-------------------------------------------------------------------
# Build the aarch64 CI image (MOOS-IvP + jsoncpp)
#-------------------------------------------------------------------
- name: Build arm64 CI image
timeout-minutes: 90
env:
CI_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
docker buildx version
docker buildx build --platform linux/arm64 --load \
--secret id=gitea_token,env=CI_TOKEN \
-t "$CI_IMAGE" -f ci/Dockerfile .
#-------------------------------------------------------------------
# Build project + unit test + startup smoke test (inside arm64)
# NOTE: the runner runs inside a container, so the workspace path is
# not a host path -> `-v` mounts don't work. Use `docker cp`
# (streams files through the docker socket) instead.
#-------------------------------------------------------------------
- name: Build & test inside arm64 container
timeout-minutes: 30
run: |
CID="h100-ci-test"
docker rm -f "$CID" >/dev/null 2>&1 || true
docker create --name "$CID" --platform linux/arm64 "$CI_IMAGE" /bin/sh -c 'sleep 7200' >/dev/null
docker cp "$PWD/." "$CID:/src/"
docker start "$CID" >/dev/null
# Run build + tests (capture exit code, don't fail the step here so
# we can still collect the report on failure)
docker exec "$CID" /src/ci/build-test.sh
TEST_RC=$?
mkdir -p bin reports
docker cp "$CID:/src/bin/pPowerManger" bin/pPowerManger 2>/dev/null || true
docker cp "$CID:/src/bin/pPMtest" bin/pPMtest 2>/dev/null || true
docker cp "$CID:/src/bin/SQLiteTest" bin/SQLiteTest 2>/dev/null || true
docker cp "$CID:/src/reports/." reports/ 2>/dev/null || true
docker rm -f "$CID" >/dev/null 2>&1 || true
echo "--- bin/ ---"; ls -la bin/ 2>/dev/null || true
echo "--- reports/ ---"; ls -la reports/ 2>/dev/null || true
exit "$TEST_RC"
#-------------------------------------------------------------------
# Publish visual test report (runs even if tests failed)
#-------------------------------------------------------------------
- name: Publish test report
if: always()
run: |
SUMMARY_FILE="${GITHUB_STEP_SUMMARY:-/tmp/step_summary.md}"
if [ -f reports/test-report.md ]; then
cat reports/test-report.md >> "$SUMMARY_FILE"
else
echo "## H100PowerManger CI" >> "$SUMMARY_FILE"
echo "测试报告未生成(构建阶段失败)" >> "$SUMMARY_FILE"
fi
# Persist reports to a dedicated branch (main push only)
if [ "${GITHUB_REF:-}" = "refs/heads/main" ] && [ -d reports ]; then
git config user.name "CI Bot"
git config user.email "ci@localhost"
git checkout --orphan test-reports >/dev/null 2>&1 || git checkout test-reports >/dev/null 2>&1 || true
git rm -rf . >/dev/null 2>&1 || true
cp -f reports/test-report.md reports/test-report.html reports/junit.xml . 2>/dev/null || true
git add -A >/dev/null 2>&1 || true
git commit -m "CI test report ${GITHUB_SHA:-}" >/dev/null 2>&1 || true
git push -f origin test-reports >/dev/null 2>&1 || echo "WARN: failed to push test-reports branch"
fi
#-------------------------------------------------------------------
# Deploy the cross-built binary to the RK3588 board (push only)
#-------------------------------------------------------------------
- name: Deploy to board
if: vars.DEPLOY_ENABLED == 'true'
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: |
set -euo pipefail
USER="${DEPLOY_USER:-root}"
HOST="${DEPLOY_HOST:?DEPLOY_HOST secret not set}"
DEST="${DEPLOY_PATH:-/root/work/moos_ws/moos-ivp-extend/bin}"
mkdir -p ~/.ssh && chmod 700 ~/.ssh
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts 2>/dev/null
chmod 755 bin/pPowerManger
rsync -avz bin/pPowerManger "${USER}@${HOST}:${DEST}/pPowerManger"
echo "Deployed pPowerManger -> ${USER}@${HOST}:${DEST}/"