Files
grpc-library/scripts/verify.sh
T
DongHyeonka 76a9244d09 chore(harness): claude-harness 뼈대를 깐다
템플릿에서 옮긴 gRPC 이력 위에 새 repo의 작업 환경을 먼저 깐다.
claude-harness main 72078ca의 scripts/new-project.sh가 만든 파일을
그대로 복사했다: AGENTS.md·CLAUDE.md 양식, .claude/settings.json
(.env deny, 하네스 플러그인 harness@claude-harness 켜기),
scripts/verify.sh 뼈대, docs/vision.md·problem-statement.md·
adr/0000-template.md 양식, docs/ledger/ 빈 장부, .gitattributes,
.gitignore.

채울 자리(「(채울 것」)는 뒤 커밋에서 이 repo의 내용으로 채운다.
이 커밋 자체는 아직 빌드되지 않는다(Gradle 루트가 없다).

검증: new-project.sh 종료 코드 0, 남은 {{…}} 없음.

Refs: design-docs repo-structure/05-library-repos.md 14.2절
2026-11-08 10:55:15 +09:00

129 lines
4.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# 검증 진입점. 사람·CI·에이전트가 같은 명령을 쓴다.
#
# scripts/verify.sh <단계> [--on here|<호스트>] [--log <이름>]
#
# 단계 무엇 채우는 곳
# docs 루트 지침·장부 검사 run_docs(뼈대에 기본 검사가 있다)
# unit 빠른 단위 시험 run_unit
# pr PR 전에 통과해야 하는 게이트 묶음 run_pr
# app 앱을 띄워 health와 기본 기능을 직접 확인 run_app
#
# --on <호스트>: 지금 작업 트리(커밋 안 된 변경 포함)를 패치로 그 호스트에 옮긴다. 기준 커밋에서 새 worktree를
# 만들어 패치를 적용하고, 트리 해시가 여기와 같은지 본 뒤 잠금 아래에서 같은 단계를 돌리고 worktree를 지운다.
# push하지 않는다. 기준 커밋은 원격 checkout이 fetch로 받을 수 있어야 한다(기본: origin/main과 갈라진 곳).
# 환경 변수: VERIFY_HOST(--on 기본값, 없으면 here), VERIFY_REMOTE_REPO(원격 checkout, 기본 ~/workspace/<repo 이름>),
# VERIFY_BASE_REF(기본 origin/main), VERIFY_LOCK(기본 /tmp/claude-gates/heavy.lock), VERIFY_SSH(기본 ssh).
# 종료 코드: 단계의 종료 코드. 2 = 사용법, 3 = 아직 채우지 않은 단계, 4 = 원격 준비 실패.
set -euo pipefail
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT"
TMP_FILES=()
trap '[ ${#TMP_FILES[@]} -eq 0 ] || rm -f "${TMP_FILES[@]}"' EXIT # 빈 배열 + set -u는 옛 bash에서 오류다
usage() {
sed -n '2,19p' "$0" | sed 's/^# \{0,1\}//' >&2
exit 2
}
todo() {
echo "verify: '$1' 단계는 아직 정하지 않았다. scripts/verify.sh의 run_$1을 채운다." >&2
return 3
}
# ---------------------------------------------------------------- 단계 본문(프로젝트가 채운다)
run_docs() {
local rc=0 lines
lines=$(wc -l < AGENTS.md)
if [ "$lines" -gt 40 ]; then
echo "AGENTS.md가 ${lines}줄이다(40줄 이하). 나머지는 하위 폴더 AGENTS.md·.claude/rules·스킬로 옮긴다." >&2
rc=1
fi
if grep -rn --include='*.md' '(채울 것' AGENTS.md docs >&2; then
echo "verify docs: 위 자리를 아직 채우지 않았다(실패로 치지 않는다)." >&2
fi
if [ -s docs/ledger/estimates.jsonl ] && ! python3 -c '
import json, sys
for n, line in enumerate(open(sys.argv[1], encoding="utf-8"), 1):
if line.strip():
json.loads(line)
' docs/ledger/estimates.jsonl; then
echo "docs/ledger/estimates.jsonl에 JSON이 아닌 줄이 있다." >&2
rc=1
fi
return "$rc"
}
run_unit() { todo unit; }
run_pr() { run_docs && run_unit && todo pr; }
run_app() { todo app; }
# ---------------------------------------------------------------- 실행 위치
run_here() {
case "$1" in
docs | unit | pr | app) "run_$1" ;;
*) usage ;;
esac
}
run_remote() {
local stage=$1 host=$2 log=$3 ssh=${VERIFY_SSH:-ssh}
local name base tree tmp_index patch id remote_repo lock
name=$(basename "$(dirname "$(git rev-parse --path-format=absolute --git-common-dir)")")
remote_repo=${VERIFY_REMOTE_REPO:-"~/workspace/$name"}
lock=${VERIFY_LOCK:-/tmp/claude-gates/heavy.lock}
base=$(git merge-base HEAD "${VERIFY_BASE_REF:-origin/main}")
tmp_index=$(mktemp)
patch=$(mktemp)
TMP_FILES+=("$tmp_index" "$patch")
cp "$(git rev-parse --git-path index)" "$tmp_index"
GIT_INDEX_FILE=$tmp_index git add -A
tree=$(GIT_INDEX_FILE=$tmp_index git write-tree)
git diff --binary "$base" "$tree" > "$patch"
id="verify-$(date +%s)-$$"
echo "verify: $host에서 '$stage' (기준 ${base:0:12}, 트리 ${tree:0:12}, 로그 ~/$log-logs/$stage.log)" >&2
$ssh "$host" "cat > /tmp/$id.patch" < "$patch"
$ssh "$host" bash -s <<EOF
set -u
cd $remote_repo || exit 4
git fetch -q origin || exit 4
wt=\$(mktemp -d /tmp/$id.XXXXXX)
git worktree add -q --detach "\$wt" $base || exit 4
cleanup() { cd $remote_repo && git worktree remove --force "\$wt"; rm -f /tmp/$id.patch; }
trap cleanup EXIT
cd "\$wt"
if [ -s /tmp/$id.patch ]; then git apply --binary --index /tmp/$id.patch || exit 4; fi
got=\$(git write-tree)
if [ "\$got" != "$tree" ]; then echo "트리 해시가 다르다: 원격 \$got, 여기 $tree" >&2; exit 4; fi
mkdir -p "\$(dirname $lock)" ~/$log-logs
flock $lock ./scripts/verify.sh $stage --on here 2>&1 | tee ~/$log-logs/$stage.log
exit \${PIPESTATUS[0]}
EOF
}
main() {
local stage=${1:-} on=${VERIFY_HOST:-here} log=""
[ -n "$stage" ] || usage
shift
while [ $# -gt 0 ]; do
case "$1" in
--on) on=${2:?--on 뒤에 호스트}; shift 2 ;;
--log) log=${2:?--log 뒤에 이름}; shift 2 ;;
*) usage ;;
esac
done
if [ "$on" = here ]; then
run_here "$stage"
else
log=${log:-$(git branch --show-current | tr '/' '-')}
run_remote "$stage" "$on" "${log:-detached}"
fi
}
main "$@"