diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..91d8939 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +# eip4-platform CI:编译+单测+ArchUnit+对拍冒烟(公司自建 Git 服务可换 Jenkins,步骤同 scripts/ci.sh) +name: ci +on: + push: + branches: [main] + pull_request: + +jobs: + build-test-parity: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: ci + POSTGRES_HOST_AUTH_METHOD: trust + ports: ["5433:5432"] + options: >- + --health-cmd "pg_isready -U ci" --health-interval 5s + --health-timeout 5s --health-retries 20 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "17" + cache: maven + - name: 编译+单测+对拍冒烟 + env: + CI_PG_HOST: localhost + CI_PG_PORT: "5433" + CI_PG_USER: ci + CI_DB: eip4ci + CI_PORT: "8090" + run: bash scripts/ci.sh diff --git a/scripts/ci.sh b/scripts/ci.sh new file mode 100755 index 0000000..abcce82 --- /dev/null +++ b/scripts/ci.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# eip4-platform CI:编译 + 单测(含 ArchUnit)+ 对拍冒烟(决策会治理条款:移植代码门禁=对拍,新代码门禁=单测) +# 用法:scripts/ci.sh [--skip-parity] +# 环境变量:CI_PORT(默认 8090) CI_PG_HOST(默认 localhost) CI_PG_PORT(默认 5433) CI_DB(默认 eip4ci) CI_PG_USER(默认 zhengwr) +set -euo pipefail +cd "$(dirname "$0")/.." + +CI_PORT="${CI_PORT:-8090}" +CI_PG_HOST="${CI_PG_HOST:-localhost}" +CI_PG_PORT="${CI_PG_PORT:-5433}" +CI_DB="${CI_DB:-eip4ci}" +CI_PG_USER="${CI_PG_USER:-zhengwr}" +SKIP_PARITY="${1:-}" + +echo "==[1/4] 编译 + 单测(全模块,含 ArchUnit 边界纪律)==" +mvn -q -T1C clean install + +if [ "$SKIP_PARITY" = "--skip-parity" ]; then + echo "==[跳过对拍冒烟]=="; exit 0 +fi + +echo "==[2/4] 准备冒烟库 ${CI_DB}(重建 + 自举)==" +psql -h "$CI_PG_HOST" -p "$CI_PG_PORT" -U "$CI_PG_USER" -d postgres -q \ + -c "DROP DATABASE IF EXISTS ${CI_DB}" -c "CREATE DATABASE ${CI_DB}" +psql -h "$CI_PG_HOST" -p "$CI_PG_PORT" -U "$CI_PG_USER" -d "$CI_DB" -q \ + -f platform-parity/src/main/resources/bootstrap/bootstrap-sys.sql +psql -h "$CI_PG_HOST" -p "$CI_PG_PORT" -U "$CI_PG_USER" -d "$CI_DB" -q \ + -f platform-parity/src/main/resources/bootstrap/bootstrap-privilege.sql + +JDBC="jdbc:postgresql://${CI_PG_HOST}:${CI_PG_PORT}/${CI_DB}" +echo "==[3/4] 起服务(:${CI_PORT} → ${JDBC})==" +java -jar platform-app/target/platform-app-*.jar \ + --server.port="$CI_PORT" \ + --spring.datasource.url="$JDBC" \ + --spring.datasource.username="$CI_PG_USER" \ + --spring.datasource.password= \ + --logging.level.com.dsasp=WARN > /tmp/eip4-ci-app.log 2>&1 & +APP_PID=$! +trap 'kill $APP_PID 2>/dev/null || true' EXIT +for i in $(seq 1 60); do + curl -s -m 2 "http://localhost:${CI_PORT}/api/entity/SYS_USERGROUP/list?page=1&perPage=1" >/dev/null 2>&1 && break + [ "$i" = 60 ] && { echo "服务启动超时"; tail -30 /tmp/eip4-ci-app.log; exit 1; } + sleep 2 +done + +echo "==[4/4] 对拍冒烟(种子 21 实体全量 + C2 权限样本)==" +CP="platform-parity/target/classes:$(mvn -q org.apache.maven.plugins:maven-dependency-plugin:build-classpath \ + -pl platform-parity -Dmdep.outputFile=/dev/stdout -o | tail -1)" +java -cp "$CP" com.eip4.platform.parity.selfcheck.ParityCli \ + --engine="http://localhost:${CI_PORT}" --jdbc="$JDBC" --user="$CI_PG_USER" --pass= --seed --all +java -cp "$CP" com.eip4.platform.parity.selfcheck.ParityCli \ + --engine="http://localhost:${CI_PORT}" --jdbc="$JDBC" --user="$CI_PG_USER" --pass= --privilege + +echo "== CI 全绿 =="