103 lines
4.2 KiB
YAML
103 lines
4.2 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)
|
|
#-------------------------------------------------------------------
|
|
- name: Build & test inside arm64 container
|
|
timeout-minutes: 30
|
|
run: |
|
|
docker run --rm \
|
|
-v "$GITHUB_WORKSPACE:/src" \
|
|
"$CI_IMAGE" /src/ci/build-test.sh
|
|
|
|
#-------------------------------------------------------------------
|
|
# 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}/"
|