build: 커밋 id·build-logic 시험·python 바이트코드 때문에 시험이 다시 돌지 않는다 #55

Merged
donghyeon.kang merged 3 commits from claude/be6-cache-keys into main 2026-11-19 20:47:30 +00:00
6 changed files with 98 additions and 5 deletions
+1
View File
@@ -38,3 +38,4 @@ registry, settings, build-logic, 루트 라이프사이클이 정하는 것을
## 테스트
- `./gradlew -p build-logic test --console=plain`(저장소 루트에서). build-logic은 Spotless 대상이 아니다. 편집 훅도 이 폴더의 Java를 포맷하지 않는다.
- `-p build-logic`으로 돌면 저장소 루트 `gradle.properties`가 걸리지 않는다. 빌드 캐시는 `build-logic/gradle.properties`가 켠다. 그래서 시험은 입력이 같으면 캐시에서 온다. 시험의 fixture는 모두 `@TempDir`에 쓴다. 시험이 저장소 파일을 읽게 되면 그 파일을 `test` 입력으로 선언한다.
+5
View File
@@ -0,0 +1,5 @@
# Read only when build-logic is the build being run (`./gradlew -p build-logic test`, main.yml's
# `build-logic` job). Then the repository root's gradle.properties is not, and without this line the
# TestKit tests ran from scratch on every push. When the main build includes build-logic, the root's
# settings apply and they enable the same cache.
org.gradle.caching=true
@@ -115,9 +115,10 @@ public final class JavaConventionsPlugin implements Plugin<Project> {
"Implementation-Version", project.getVersion().toString(),
"Build-Revision", buildRevision)));
// Both attributes change on every commit, and every test and SpotBugs task has this jar on its
// runtime classpath: without the normalization a CI build never reuses a cached test result
// (review O-4c). They describe the build, not the classes, so a runtime classpath ignores them.
// Build-Revision changes on every commit, and Implementation-Version whenever a build has a
// commit id or not (`-SNAPSHOT`). Every test and SpotBugs task has this jar on its runtime
// classpath: without the normalization a CI build never reuses a cached test result (review
// O-4c). They describe the build, not the classes, so a runtime classpath ignores them.
project
.getNormalization()
.getRuntimeClasspath()
@@ -126,6 +127,16 @@ public final class JavaConventionsPlugin implements Plugin<Project> {
metaInf.ignoreAttribute("Implementation-Version");
metaInf.ignoreAttribute("Build-Revision");
});
// The same commit id is `build.revision` in the build-info.properties that Spring Boot's
// bootBuildInfo writes into app-bootstrap's main resources, and that leaf's test, architecture
// and Checkstyle tasks have those resources on their classpath: without this every commit reran
// them. It is ignored only as an input; bootJar and /actuator/info still carry the value.
project
.getNormalization()
.getRuntimeClasspath()
.properties(
"META-INF/build-info.properties",
buildInfo -> buildInfo.ignoreProperty("build.revision"));
project
.getTasks()
@@ -1,11 +1,14 @@
package dev.caskeleton.buildlogic.convention;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Files;
import java.nio.file.Path;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.BuildTask;
import org.gradle.testkit.runner.GradleRunner;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -145,6 +148,67 @@ class PlatformModuleConventionTest {
assertTrue(result.getOutput().contains("pinned=2.0.1 unpinned=null"), result.getOutput());
}
@Test
void aNewCommitIdInBuildInfoLeavesARuntimeClasspathReaderUpToDate() throws Exception {
// given: the reader has run once against one commit's build-info.properties.
runtimeClasspathReaderBuild();
writeBuildInfo("111111111111", "0.0.1");
runner("readRuntimeClasspath").build();
writeBuildInfo("222222222222", "0.0.1");
// when
BuildResult result = runner("readRuntimeClasspath").build();
// then
assertEquals(
TaskOutcome.UP_TO_DATE, outcome(result, ":readRuntimeClasspath"), result.getOutput());
}
@Test
void anotherBuildInfoPropertyStillMakesARuntimeClasspathReaderRunAgain() throws Exception {
// given: the reader has run once; then the version changes and the commit id does not.
runtimeClasspathReaderBuild();
writeBuildInfo("111111111111", "0.0.1");
runner("readRuntimeClasspath").build();
writeBuildInfo("111111111111", "0.0.2");
// when
BuildResult result = runner("readRuntimeClasspath").build();
// then
assertEquals(TaskOutcome.SUCCESS, outcome(result, ":readRuntimeClasspath"), result.getOutput());
}
/**
* A task that takes the main resources as a runtime classpath, the way a Test or Checkstyle task
* takes app-bootstrap's main output, which holds the build-info.properties bootBuildInfo writes.
*/
private void runtimeClasspathReaderBuild() throws Exception {
buildFile(
"""
plugins { id 'ca.platform-module' }
def marker = layout.buildDirectory.file('runtime-classpath-read.txt')
tasks.register('readRuntimeClasspath') {
inputs.files(tasks.named('processResources'))
.withNormalizer(ClasspathNormalizer)
.withPropertyName('classpath')
outputs.file(marker).withPropertyName('marker')
doLast { marker.get().asFile.text = 'read' }
}
""");
}
private void writeBuildInfo(String revision, String version) throws Exception {
Path file = projectDir.resolve("src/main/resources/META-INF/build-info.properties");
Files.createDirectories(file.getParent());
Files.writeString(file, "build.revision=" + revision + "\nbuild.version=" + version + "\n");
}
private static TaskOutcome outcome(BuildResult result, String path) {
BuildTask task = result.task(path);
return task == null ? null : task.getOutcome();
}
private void writeCatalog() throws Exception {
Files.writeString(
projectDir.resolve("gradle/libs.versions.toml"),
+6
View File
@@ -66,6 +66,12 @@ env 계약이고 `.env`는 로컬 실행 입력이다. `verifyEnvKeys`는 exampl
`META-INF/build-info.properties`(`build.revision`)에 남긴다. 예전에는 version이
`<MAJOR>.<MINOR>.<PATCH>+<sha>`라 커밋마다 새 jar 이름이 생겼고 그 잔여물을 `ca.archive-hygiene`이
치웠는데, 둘 다 없앴다(리뷰 BUILD-O3-5).
- runtime classpath 입력에서는 빌드를 설명하는 값을 뺀다(`ca.java-conventions`의 정규화).
manifest의 `Build-Revision`(커밋 id)과 `Implementation-Version`(revision이 없으면 `-SNAPSHOT`이
붙는 버전), `build-info.properties`의 `build.revision`이다. 그래서 캐시를 쓰는 태스크(TEST·
ARCHITECTURE lane 등)는 커밋 id만 다른 빌드에서 캐시의 결과를 받는다. 매번 다시 도는 lane은
`build-logic/AGENTS.md` 「lane 캐시와 성능 lane」이 정한다. jar와 실행 중 `/actuator/info`의 값은
그대로다.
- `releaseCheck`가 실행하는 `verifyReleaseProvenance`(루트 `build.gradle`, revision 판정은
`ca.java-conventions`와 같은 함수)는 source revision이 없으면 실패하므로 추적 불가능한 산출물을
release로 취급할 수 없다. 예전 `ca.release-provenance` 플러그인은 없앴다(리뷰 BUILD-O3-5).
+8 -2
View File
@@ -342,7 +342,11 @@ dependencies {
// capture ban — that must stop a merge, not be found after one.
def repositoryRootForContractTests = rootProject.projectDir
// Other checkouts of this repository that a developer machine keeps under .claude/worktrees are not inputs.
def repositoryContractExcludes = ['**/build/**', '**/.gradle/**', '**/node_modules/**', '.claude/worktrees/**']
// Nor is the Python bytecode Git ignores: the root testDocumentChecks writes it under scripts/ in the
// same build, so with it the lane's fingerprint changed between two runs of one tree and on every
// fresh checkout (the files carry their source's modification time).
def repositoryContractExcludes = ['**/build/**', '**/.gradle/**', '**/node_modules/**', '.claude/worktrees/**',
'**/__pycache__/**', '**/*.pyc']
def repositoryContractInputs = files(
fileTree(repositoryRootForContractTests) {
// docs/registries/** are machine contracts, not prose: a malformed registry must fail
@@ -435,7 +439,9 @@ bootJar {
// The deployable artifact names the release and the commit it was built from in
// META-INF/build-info.properties (review BUILD-O3-5: provenance through Spring Boot's build info
// rather than a revision in every leaf's jar name). `time` is excluded so an unchanged commit still
// produces an unchanged resource and cached tasks stay cached.
// produces an unchanged resource. The revision does change it on every commit; ca.java-conventions
// leaves `build.revision` out of every runtime classpath input, so the tests and checks that have
// these resources on their classpath stay cached.
springBoot {
buildInfo {
excludes = ['time']