CI:移除自动部署,改为发布二进制到 Gitea Releases(v* tag 建版本号 Release,main push 更新 latest 预发布),README 记录发布流程
build-test-deploy / ci (push) Successful in 8m59s

This commit is contained in:
zjk
2026-08-14 17:59:25 +08:00
parent 10944c0587
commit f51a3ac750
2 changed files with 118 additions and 19 deletions
+89 -19
View File
@@ -2,7 +2,9 @@
# 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
# - publish compiled binary to Gitea Releases (manual deploy)
# * tag push v* -> versioned Release
# * main push -> rolling "latest" Release (pre-release / test)
# Self-contained (no external actions). The runner is an Alpine
# container with the host Docker socket mounted; we install the
# docker CLI at runtime.
@@ -40,7 +42,7 @@ jobs:
#-------------------------------------------------------------------
- name: Install tools
run: |
apk add --no-cache docker-cli docker-cli-buildx rsync openssh-client
apk add --no-cache docker-cli docker-cli-buildx rsync openssh-client curl jq
- name: Verify docker
run: |
@@ -127,24 +129,92 @@ jobs:
fi
#-------------------------------------------------------------------
# Deploy the cross-built binary to the RK3588 board (push only)
# Publish the aarch64 binary to Gitea Releases (manual deployment)
# * tag push (v*) -> versioned Release (e.g. v1.0.0, stable)
# * main push -> rolling "latest" Release (pre-release/test)
# Only runs when build + tests succeeded.
#-------------------------------------------------------------------
- name: Deploy to board
if: vars.DEPLOY_ENABLED == 'true'
- name: Publish release
if: success() && startsWith(github.ref, 'refs/tags/v')
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ vars.DEPLOY_USER }}
DEPLOY_PATH: ${{ vars.DEPLOY_PATH }}
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
RELEASE_TOKEN: ${{ secrets.CI_TOKEN }}
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}/"
REPO="${{ github.repository }}"
API="https://gitea2.zhaojingkui.xyz/api/v1/repos/${REPO}"
TAG="${GITHUB_REF#refs/tags/}"
COMMIT_SHORT="$(git rev-parse --short HEAD)"
REPORT_URL="https://gitea2.zhaojingkui.xyz/${REPO}/src/branch/test-reports/test-report.md"
BODY="pPowerManger (aarch64 / RK3588 / Ubuntu 20.04)
- Commit: \`${COMMIT_SHORT}\`
- 时间: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
- 测试报告: [${REPORT_URL}](${REPORT_URL})
手动部署: 下载后 scp/rsync 到板卡:
\`\`\`
rsync -avz pPowerManger root@192.168.0.223:/root/work/moos_ws/moos-ivp-extend/bin/pPowerManger
\`\`\`"
echo ">>> 创建版本号 Release: ${TAG}"
RELEASE_JSON=$(curl -sS -X POST -H "Authorization: token ${RELEASE_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":$(jq -Rn --arg b "${BODY}" '$b'),\"prerelease\":false}" \
"${API}/releases")
echo "${RELEASE_JSON}" | jq -e .id >/dev/null || { echo "创建 Release 失败:"; echo "${RELEASE_JSON}"; exit 1; }
RELEASE_ID=$(echo "${RELEASE_JSON}" | jq -r .id)
echo ">>> 上传 pPowerManger (release id=${RELEASE_ID})"
curl -sS -X POST -H "Authorization: token ${RELEASE_TOKEN}" \
-F "attachment=@bin/pPowerManger" \
"${API}/releases/${RELEASE_ID}/assets?name=pPowerManger" \
| jq -e .id >/dev/null || { echo "上传失败"; exit 1; }
echo ">>> 发布完成: https://gitea2.zhaojingkui.xyz/${REPO}/releases/tag/${TAG}"
- name: Publish latest release
if: success() && github.ref == 'refs/heads/main'
env:
RELEASE_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
set -euo pipefail
REPO="${{ github.repository }}"
API="https://gitea2.zhaojingkui.xyz/api/v1/repos/${REPO}"
TAG="latest"
COMMIT_SHORT="$(git rev-parse --short HEAD)"
REPORT_URL="https://gitea2.zhaojingkui.xyz/${REPO}/src/branch/test-reports/test-report.md"
BODY="pPowerManger (aarch64 / RK3588 / Ubuntu 20.04) — 测试用最新构建
- Commit: \`${COMMIT_SHORT}\`
- 时间: $(date -u +'%Y-%m-%d %H:%M:%S UTC')
- 测试报告: [${REPORT_URL}](${REPORT_URL})
手动部署: 下载后 scp/rsync 到板卡:
\`\`\`
rsync -avz pPowerManger root@192.168.0.223:/root/work/moos_ws/moos-ivp-extend/bin/pPowerManger
\`\`\`"
# 1. move the "latest" tag to current commit
echo ">>> 移动 latest tag 到 ${COMMIT_SHORT}"
git tag -f "${TAG}" HEAD
git push -f origin "${TAG}" || true
# 2. delete old "latest" release (by tag), ignore if none
echo ">>> 删除旧的 latest Release (如有)"
curl -sS -X DELETE -H "Authorization: token ${RELEASE_TOKEN}" \
"${API}/releases/tags/${TAG}" || true
# 3. create new "latest" release (pre-release)
echo ">>> 创建 latest Release (pre-release)"
RELEASE_JSON=$(curl -sS -X POST -H "Authorization: token ${RELEASE_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"latest (测试)\",\"body\":$(jq -Rn --arg b "${BODY}" '$b'),\"prerelease\":true}" \
"${API}/releases")
echo "${RELEASE_JSON}" | jq -e .id >/dev/null || { echo "创建 latest Release 失败:"; echo "${RELEASE_JSON}"; exit 1; }
RELEASE_ID=$(echo "${RELEASE_JSON}" | jq -r .id)
# 4. upload pPowerManger
echo ">>> 上传 pPowerManger (release id=${RELEASE_ID})"
curl -sS -X POST -H "Authorization: token ${RELEASE_TOKEN}" \
-F "attachment=@bin/pPowerManger" \
"${API}/releases/${RELEASE_ID}/assets?name=pPowerManger" \
| jq -e .id >/dev/null || { echo "上传失败"; exit 1; }
echo ">>> 发布完成: https://gitea2.zhaojingkui.xyz/${REPO}/releases/tag/${TAG}"