Files
grpc-library/scripts/buf.sh
DongHyeonka 414666cfc7 build: 템플릿 밖에서 혼자 빌드·배포되는 Gradle 루트를 만든다
옮겨 온 gRPC 모듈은 템플릿의 두 번째 빌드(optional build)였다. 그 빌드는
템플릿 build-logic·카탈로그·registry·config를 상대 경로로 읽었고,
grpc-operation-ledger-jpa는 템플릿 persistence-jpa의 testFixtures 파일
셋을 빌드 때 복사해 왔다. 별도 repo에는 그 경로가 없다.

repo 루트를 Gradle 루트로 둔다.
- build-logic: 템플릿 22df3525의 src/build-logic을 복사하고 쓰지 않는
  플러그인(bootrun-dotenv, redis topology, config contract,
  spring-library, optional registry, purity 태스크)을 뺐다. 출처와 고친
  곳은 build-logic/UPSTREAM.md에 적었다(설계 10.3절 L1).
- registry config/architecture/modules.json: 템플릿의 optional-grpc 9행,
  source_path는 Gradle 루트 기준.
- 카탈로그·config: 이 repo가 쓰는 항목만. SpotBugs 제외는 이 repo
  클래스와 일반 규칙만 남겼다.
- group은 gradle.properties의 libraryGroup(com.hyeonworks.grpc)에서
  읽는다. 버전은 -PreleaseVersion 말고 RELEASE_TAG(vX.Y.Z)에서도 읽고,
  다른 모양의 태그는 빌드 전에 거부한다.
- 배포: 새 ca.library-publishing이 모듈마다 Maven publication(sources·
  javadoc jar, versionMapping으로 해석된 버전)과 저장소 gitea·staging,
  SIGNING_KEY가 있으면 PGP 서명을 단다. 루트는 SBOM artifact
  grpc-library와 단계 태스크 ci·mainCheck·releaseCheck·release·
  releaseRehearsal을 가진다. Trivy·Buf는 scripts/tool.sh가 SHA-256으로
  고정해 받는다.
- testFixtures 결합(설계 4.6절 2번)은 integrationTest 안 사본으로 끊었다.
- Buf lint·breaking은 Gradle 태스크(scripts/buf.sh)로 ci에 넣었다.

버린 대안: build-logic을 템플릿이 배포(L2, 순환), 공통 repo(L3, repo가
하나 더), 표준 플러그인만으로 새로 쓰기(L4, strict lane과 방향 검사를
잃음). SBOM은 CycloneDX Gradle 플러그인 대신 이미 고정해 쓰는 Trivy로
만든다(도구를 늘리지 않는다).

위험: strictlane 단계 검사는 included build 태스크를 따라가다 실패해서
그 태스크를 건너뛰게 고쳤다(UPSTREAM.md). Gitea에 실제로 올리는 경로는
비밀 값이 없어 이 커밋에서는 시험하지 못했다.

검증(desktop, 이 트리): ./gradlew ci rc=0, 테스트 739개(build-logic
포함) 중 첫 실행 실패 1개(템플릿 경로를 찾던 GrpcPackageOwnershipTest)를
고친 뒤 통과. ./gradlew verifyStrictLaneStages --dry-run rc=0.

Refs: design-docs repo-structure/05-library-repos.md 4.6·7·10절
2026-11-08 11:10:21 +09:00

65 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Buf lint and breaking-change policy for the Stable gRPC schema (grpc/grpc-contract, buf.yaml there).
#
# scripts/buf.sh lint
# scripts/buf.sh breaking
#
# protoc (the Gradle protobuf plugin) compiles the schema; Buf owns lint and breaking policy. The
# root `ci` stage runs both through :grpc:grpc-contract:bufLint and :bufBreaking.
#
# breaking compares the working tree with a baseline commit:
# BUF_AGAINST set → that ref
# a pull request (GITHUB_BASE_REF) → the merge base with origin/<base>
# otherwise → the merge base with origin/main, or HEAD^ when HEAD is on it
# (or when a local clone has no origin/main)
# A baseline without grpc/grpc-contract/buf.yaml has nothing to be compatible with, and the check
# says so and passes. A baseline Git cannot find fails: a shallow clone cannot answer the question.
set -euo pipefail
root=$(git rev-parse --show-toplevel)
module=grpc/grpc-contract
buf=$("$root/scripts/tool.sh" buf)
cd "$root/$module"
case "${1:-}" in
lint)
"$buf" lint
;;
breaking)
if [ -n "${BUF_AGAINST:-}" ]; then
baseline=$BUF_AGAINST
else
base_branch="origin/${GITHUB_BASE_REF:-main}"
if git rev-parse --verify --quiet "$base_branch^{commit}" >/dev/null; then
baseline=$(git merge-base HEAD "$base_branch")
elif [ "${GITHUB_ACTIONS:-}" = true ]; then
# In CI the base branch must be there; a missing one means a shallow checkout, and comparing
# with something else would answer a different question.
echo "buf.sh: $base_branch is not in this clone; fetch it (actions/checkout fetch-depth: 0)." >&2
exit 1
else
echo "buf.sh: no $base_branch here; comparing with HEAD^ (set BUF_AGAINST to choose)."
baseline=$(git rev-parse HEAD)
fi
if [ -z "${GITHUB_BASE_REF:-}" ] && [ "$baseline" = "$(git rev-parse HEAD)" ]; then
baseline=$(git rev-parse --verify --quiet 'HEAD^' || true)
fi
fi
commit=$(git rev-parse --verify --quiet "${baseline}^{commit}" || true)
if [ -z "$commit" ]; then
echo "buf.sh: no baseline commit for '${baseline:-HEAD^}'; nothing to compare (first commit)." >&2
[ -z "${baseline:-}" ] && exit 0 || exit 1
fi
if ! git cat-file -e "$commit:$module/buf.yaml" 2>/dev/null; then
echo "buf.sh: baseline ${commit:0:12} has no $module/buf.yaml; breaking check skipped."
exit 0
fi
echo "buf.sh: breaking against ${commit:0:12}"
"$buf" breaking --against "$root/.git#ref=$commit,subdir=$module"
;;
*)
echo "usage: scripts/buf.sh lint|breaking" >&2
exit 2
;;
esac