#!/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 # P4-4 平台表 SYS_PAGE_SCHEMA(页面 schema 服务化);幂等建表,数据由 SchemaImportCli 按需导入 psql -h "$CI_PG_HOST" -p "$CI_PG_PORT" -U "$CI_PG_USER" -d "$CI_DB" -q \ -f platform-metadata/src/main/resources/bootstrap/bootstrap-page-schema.sql JDBC="jdbc:postgresql://${CI_PG_HOST}:${CI_PG_PORT}/${CI_DB}" echo "==[3/4] 起服务(:${CI_PORT} → ${JDBC})==" # profile=ci:对拍冒烟依赖免令牌 permitAll + asUser/roles 旁路(见 SecurityProfiles)。 # P0 fail-safe 修复后默认严格链(无 profile=强制认证),故 CI 必须显式声明 ci profile, # 否则健康检查 /api/entity/... 被拒 401、ParityCli 免令牌重放失效。 java -jar platform-app/target/platform-app-*.jar \ --spring.profiles.active=ci \ --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 # 权限规则按表名动态绑定实体 ID,必须在种子实体创建后重放(脚本幂等); # 否则 INSERT...SELECT 在空 sys_entity 上静默插 0 条规则 → 负例不拒、正例 0 行 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 java -cp "$CP" com.eip4.platform.parity.selfcheck.ParityCli \ --engine="http://localhost:${CI_PORT}" --jdbc="$JDBC" --user="$CI_PG_USER" --pass= --privilege echo "== CI 全绿 =="