ci(main): main push도 PR용 빌드 캐시를 채우고 문서만 바꾼 push는 건너뛴다 #54
+51
-19
@@ -2,10 +2,12 @@
|
||||
# happened — but it fails loudly, after the change it reports on (owner decision 2026-09-16).
|
||||
#
|
||||
# On every push to main: the main stage, the container lanes, the build-logic tests, configuration
|
||||
# cache, links and the dependency scan. Nightly (and on a manual run) also the jobs that need a matrix
|
||||
# or an environment the stage tasks do not have, and last the performance lanes, which need a
|
||||
# machine nothing else is using: the runner takes one job at a time, and the performance job is the
|
||||
# last one in this file (owner decision 2026-11-07; the job says why not `needs`).
|
||||
# cache, links, the dependency scan, and the pull-request stage once more to fill the build cache
|
||||
# (`done`, not a gate; it stops early when only documentation changed since the last one that got
|
||||
# through). Nightly (and on a manual run) also the jobs that need a matrix or an environment the
|
||||
# stage tasks do not have, and last the performance lanes, which need a machine nothing else is
|
||||
# using: the runner takes one job at a time, and the performance job is the last one in this file
|
||||
# (owner decision 2026-11-07; the job says why not `needs`).
|
||||
#
|
||||
# Which lanes a stage means is decided by its Gradle task (build.gradle). The stage jobs (`main`
|
||||
# for the main and integration stages, `performance`) run them as one line;
|
||||
@@ -131,6 +133,51 @@ jobs:
|
||||
- uses: ./.gitea/actions/setup-java-gradle
|
||||
- run: ./gradlew :adapter:outbound:httpclient:test -Phttp3.tests.enabled=true
|
||||
|
||||
# Not a gate: the pull-request stage once more, on main, so that a pull request finds main's
|
||||
# results in the build cache and runs only what its change touches. setup-gradle keys its cache by
|
||||
# job name and a job first restores the newest entry of its own name, so this job is named after
|
||||
# pr.yml's one job. Main saves, a pull request only reads (.gitea/actions/setup-java-gradle).
|
||||
#
|
||||
# On every push, not only nightly. With one save a night, a pull request reran what the day's
|
||||
# merges had changed until the next night, and nearly everything after a build-logic change
|
||||
# (2026-11-19: 69 tasks from cache and 9 to 12 minutes of :prCheck, against 266 and under 2 right
|
||||
# after the nightly). This job restores the newest entry, so it reruns only what changed since.
|
||||
#
|
||||
# A push stops after checkout with one `건너뜀:` line when its build inputs (every file but the
|
||||
# documentation; scripts/ci/done-build-inputs.py says which) have the key the newest marker holds,
|
||||
# and runs otherwise. A marker is a small entry holding the inputs' key of a `done` job on main
|
||||
# that succeeded; actions/cache saves it at the end of that job, after setup-gradle's save when
|
||||
# Gradle ran, so the newest marker and the newest Gradle entry come from the same job. After a run
|
||||
# that changed the build inputs and did not get through, or after a revert of a change whose run
|
||||
# did, the newest marker holds other inputs and the push runs, documentation only or not; so does
|
||||
# an answer that is missing. The marker cannot tell whether that Gradle entry is still there
|
||||
# (setup-gradle only warns when it cannot save, and the cache limit can push the large entry out
|
||||
# first): then pull requests miss until the next code push or the nightly. Nightly and manual runs
|
||||
# always run; on main they leave a marker too.
|
||||
done:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 75
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # actions/checkout@v4.2.2
|
||||
# A key of its own each run: a saved key is never written again, so the restore falls back by
|
||||
# prefix to the newest marker, and a rerun of a run that got through finds its own. The
|
||||
# repository is in the key, ended by a `/` no repository name has, in case the runner's cache
|
||||
# is shared with other repositories.
|
||||
- if: ${{ github.ref == 'refs/heads/main' }}
|
||||
uses: https://github.com/actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # actions/cache@v4.3.0
|
||||
with:
|
||||
path: build/done-cache-marker
|
||||
key: done-marker-${{ github.repository }}/${{ github.run_id }}
|
||||
restore-keys: done-marker-${{ github.repository }}/
|
||||
- id: inputs
|
||||
env:
|
||||
EVENT: ${{ github.event_name }}
|
||||
run: python3 scripts/ci/done-build-inputs.py
|
||||
- if: ${{ steps.inputs.outputs.run != 'false' }}
|
||||
uses: ./.gitea/actions/setup-java-gradle
|
||||
- if: ${{ steps.inputs.outputs.run != 'false' }}
|
||||
run: ./gradlew :prCheck
|
||||
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
# Nightly and manual runs only.
|
||||
|
||||
@@ -329,21 +376,6 @@ jobs:
|
||||
- uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # actions/checkout@v4.2.2
|
||||
- run: bash scripts/run-compose-runtime-smoke.sh --matrix src/bootstrap/app/compose-lanes/compose-profile-contracts.json
|
||||
|
||||
# Not a gate: the pull-request stage once more, on main, so that a pull request finds main's
|
||||
# results in the build cache and runs only what its change touches. setup-gradle keys its cache by
|
||||
# job name and a job first restores the newest entry of its own name, so this job is named after
|
||||
# pr.yml's one job. Main saves, a pull request only reads (.gitea/actions/setup-java-gradle).
|
||||
# Nightly and manual runs only: a push does not wait for it, and a pull request after a day's
|
||||
# merges reruns the modules those changed.
|
||||
done:
|
||||
if: ${{ github.event_name != 'push' }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 75
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # actions/checkout@v4.2.2
|
||||
- uses: ./.gitea/actions/setup-java-gradle
|
||||
- run: ./gradlew :prCheck
|
||||
|
||||
# Load, slow-client, shutdown, pool and resource bounds. Last, after every other heavy job of the
|
||||
# run, so the bounds are measured on a runner that is not building something else.
|
||||
#
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
{"date": "2026-11-13", "test": "MinioS3ManagedObjectProviderContractTest#initializationError", "category": "fixed-time", "first_run": "304", "verdict": "재현 안 됨(desktop 1코어 기아 3회 통과, 첫 createBucket 최대 1.94초/acquire 2초)", "quarantined_until": "", "fixed_by": "백엔드 #49"}
|
||||
{"date": "2026-11-13", "test": "MinioManagedObjectFaultTest#connectionCutProducesABoundedFailureAndRecoveryWithoutMutationReplay", "category": "fixed-time", "first_run": "310", "verdict": "desktop 1코어 기아 3회 중 3회 실패(첫 createBucket 3.2~3.8초/apiCallTimeout 2초)", "quarantined_until": "", "fixed_by": "백엔드 #49"}
|
||||
{"date": "2026-11-18", "test": "InboxRedeliveryIntegrationTest#initializationError", "category": "concurrency-order", "first_run": "330", "verdict": "runner 같은 날 3회 중 1회 실패(nightly 324·main 327 통과). Kafka 기동 반복문이 복사가 끝나기 전의 스크립트를 실행해 exit 126(testcontainers-java #11682). lane 반복은 돌리지 않았다. docker CLI 탐침으로 부하 아래 원래 반복문 100회 중 0회 실패, sleep 뺀 반복문 50회 중 42회 실패(모두 exit 126, Text file busy)", "quarantined_until": "", "fixed_by": "백엔드 #50"}
|
||||
{"date": "2026-11-19", "test": "main.yml links (lychee) — man7.org openat2.2, jdbc.postgresql.org documentation/ssl·use", "category": "external", "first_run": "362", "verdict": "외부 사이트 시간 초과 3건, 오류 0건(기본 재시도 3회를 다 씀). 다음 run 367은 시간 초과 0. 노트북 curl 9회 모두 200(0.4~1.3초)으로 재현 안 됨. 링크는 살아 있다", "quarantined_until": "", "fixed_by": ""}
|
||||
{"date": "2026-11-19", "test": "main.yml links (lychee) — man7.org openat2.2, jdbc.postgresql.org documentation/ssl·use", "category": "external", "first_run": "362", "verdict": "외부 사이트 시간 초과 3건, 오류 0건(기본 재시도 3회를 다 씀). 다음 run 367은 시간 초과 0. 노트북 curl 9회 모두 200(0.4~1.3초)으로 재현 안 됨. 링크는 살아 있다", "quarantined_until": "", "fixed_by": "백엔드 #52"}
|
||||
|
||||
@@ -23,7 +23,7 @@ Gradle 명령과 `scripts/verify.sh`는 모두 저장소 루트(Gradle 루트)
|
||||
| `app` | `scripts/bootstrap-local.sh`(앱을 띄워 health와 기본 endpoint 확인) | — |
|
||||
| `round` | `pr` → `main` → `nightly` → `release`, 첫 실패에서 멈춘다 | — |
|
||||
|
||||
workflow에만 있는 job: `pr.yml` `done`의 마지막 step과 `main.yml`의 `vulnerabilities`(trivy, `scripts/ci/trivy-scan.sh`), `main.yml`의 `links`(lychee), nightly job(`jpa-postgresql`·`httpclient-transport`·`redis-topology`·`fileserver-nfs-ambiguity`·`notification-chaos`·`jpa-next`), `release.yml`의 release lane과 이미지 job. `main.yml`의 `done`은 게이트가 아니다: nightly에 main에서 `:prCheck`를 한 번 더 돌려 빌드 캐시를 채우고, 같은 이름의 PR job이 그 캐시를 읽는다(setup-gradle이 job 이름으로 캐시를 찾는다). 도구를 내려받거나 runner 환경이 필요해 `verify.sh`에 넣지 않았다. 손으로 돌리는 법은 3절 (다)다.
|
||||
workflow에만 있는 job: `pr.yml` `done`의 마지막 step과 `main.yml`의 `vulnerabilities`(trivy, `scripts/ci/trivy-scan.sh`), `main.yml`의 `links`(lychee), nightly job(`jpa-postgresql`·`httpclient-transport`·`redis-topology`·`fileserver-nfs-ambiguity`·`notification-chaos`·`jpa-next`), `release.yml`의 release lane과 이미지 job. `main.yml`의 `done`은 게이트가 아니다: main push와 nightly마다 main에서 `:prCheck`를 한 번 더 돌려 빌드 캐시를 채우고, 같은 이름의 PR job이 그 캐시를 읽는다(setup-gradle이 job 이름으로 캐시를 찾는다). 그래서 PR은 main이 마지막으로 채운 결과와 입력이 다른 태스크만 다시 돈다. push의 빌드 입력(문서를 뺀 모든 추적 파일. 문서는 `docs/`·`.claude/` 아래와 소스 세트 밖 `*.md`)이 가장 최근에 성공한 `done` job과 같으면 checkout 뒤 `건너뜀: done — …` 한 줄을 남기고 `:prCheck`를 돌지 않는다. 성공한 job은 끝에 자기 빌드 입력 키를 담은 작은 표식 캐시 항목을 남기고, 다음 job은 가장 최근 표식과 지금 키가 같을 때만 건너뛴다(`scripts/ci/done-build-inputs.py`). 빌드 입력을 바꾼 run이 끝까지 가지 못했으면 다음 push는 문서만 바꿨어도 돈다. 끝까지 간 변경을 되돌린 push도 돈다(가장 최근 표식은 되돌리기 전 입력이다). 표식은 그 job의 Gradle 캐시 항목이 아직 남았는지는 모른다: 저장이 실패했거나 캐시 상한에 밀려났으면 다음 코드 push나 nightly까지 PR이 캐시를 못 받는다. nightly·수동 run은 늘 돈다. 도구를 내려받거나 runner 환경이 필요해 `verify.sh`에 넣지 않았다. 손으로 돌리는 법은 3절 (다)다.
|
||||
|
||||
게이트 하나씩:
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
"""Says whether main.yml's `done` job would put anything new in the build cache on this run.
|
||||
|
||||
Called by the `done` job of .gitea/workflows/main.yml, after checkout and the marker restore, before
|
||||
Java and Gradle are set up. That job is not a gate: it runs the pull-request stage on main so that a
|
||||
pull request finds main's results in the build cache (docs/work/reference/gates.md). The marker is a
|
||||
small cache entry that every job on main that gets through saves at its end, after the Gradle cache
|
||||
when it ran Gradle, holding the key of the build inputs it had. The restore brings back the newest.
|
||||
|
||||
The build inputs are every tracked file but the documentation: paths under docs/ or .claude/, and
|
||||
Markdown files outside a source set (`<project>/src/<set>/`, where a Markdown file is a resource or
|
||||
test fixture). Their key is a digest of their paths, modes and blob ids at HEAD. A push skips, with
|
||||
one `건너뜀:` line, exactly when the newest marker holds the same key; anything else runs, and so
|
||||
does a run that is not a push. After a run that changed the build inputs and did not get through,
|
||||
the next push runs even if it changed documentation only. A push that reverts a change whose run got
|
||||
through runs too: the newest marker holds the inputs from before the revert. Running is the safe side.
|
||||
|
||||
What the marker cannot tell: whether that job's Gradle entry is still in the cache (setup-gradle only
|
||||
warns when it cannot save, and the cache limit can push the large entry out first). Then pull
|
||||
requests miss until the next code push or the nightly, which always runs. A few pull-request tests
|
||||
declare documents under docs/ as inputs (registries, runbooks, ADRs, API surface baselines;
|
||||
`git grep -n docs/ -- '*.gradle'` shows where); after a push that changed only those, the next pull
|
||||
request reruns those tests. The cache changes how long a run takes, never what it decides.
|
||||
|
||||
Writes `run=true` or `run=false` to $GITHUB_OUTPUT, prints one line, and writes this run's key to the
|
||||
marker file for the cache step to save. Fails when $GITHUB_OUTPUT is not set or Git cannot list HEAD,
|
||||
so the job stops with an error instead of deciding without a key.
|
||||
|
||||
EVENT=<github.event_name> GITHUB_OUTPUT=<file> python3 scripts/ci/done-build-inputs.py
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
JOB = "done"
|
||||
# The path main.yml's marker step restores and saves. Relative to the checkout, so the cache version,
|
||||
# which hashes the path as written, is the same in every run; build/ is ignored, so no check sees it.
|
||||
MARKER = Path("build/done-cache-marker")
|
||||
|
||||
|
||||
def is_documentation(path: str) -> bool:
|
||||
if path.startswith(("docs/", ".claude/")):
|
||||
return True
|
||||
if "/src/" in path:
|
||||
return False
|
||||
return path.endswith(".md")
|
||||
|
||||
|
||||
def tracked_entries() -> list[tuple[str, str]]:
|
||||
"""(path, `mode type id`) for every tracked file at HEAD."""
|
||||
listing = subprocess.run(["git", "ls-tree", "-r", "-z", "--full-tree", "HEAD"], capture_output=True, check=True)
|
||||
entries = []
|
||||
for line in listing.stdout.decode("utf-8", "surrogateescape").split("\0"):
|
||||
if line:
|
||||
meta, path = line.split("\t", 1)
|
||||
entries.append((path, meta))
|
||||
return entries
|
||||
|
||||
|
||||
def build_inputs_key() -> str:
|
||||
inputs = [f"{meta}\t{path}" for path, meta in tracked_entries() if not is_documentation(path)]
|
||||
digest = hashlib.sha256("\0".join(inputs).encode("utf-8", "surrogateescape")).hexdigest()
|
||||
return f"{JOB}-build-inputs-{digest}"
|
||||
|
||||
|
||||
def newest_marker() -> str:
|
||||
"""The key the newest marker holds, or '' when the restore found none."""
|
||||
try:
|
||||
return MARKER.read_text(encoding="utf-8").strip()
|
||||
except FileNotFoundError:
|
||||
return ""
|
||||
|
||||
|
||||
def decide(event: str, key: str, marker: str) -> tuple[bool, str]:
|
||||
"""(run, the line to print)."""
|
||||
if event != "push":
|
||||
return True, f"{JOB}: {event or '이벤트 없음'} run이라 :prCheck를 돈다 (빌드 입력 {key})"
|
||||
if marker == key:
|
||||
return False, f"건너뜀: {JOB} — 가장 최근에 끝까지 간 {JOB} job과 빌드 입력(문서를 뺀 파일)이 같다 ({key})"
|
||||
return True, f"{JOB}: 빌드 입력 {key}가 가장 최근 표식 {marker or '(없음)'}과 달라 :prCheck를 돈다"
|
||||
|
||||
|
||||
def main() -> int:
|
||||
output = os.environ.get("GITHUB_OUTPUT")
|
||||
if not output:
|
||||
print(f"{JOB}: GITHUB_OUTPUT가 없어 판정을 넘길 수 없다", file=sys.stderr)
|
||||
return 1
|
||||
key = build_inputs_key()
|
||||
run, line = decide(os.environ.get("EVENT", ""), key, newest_marker())
|
||||
MARKER.parent.mkdir(parents=True, exist_ok=True)
|
||||
MARKER.write_text(f"{key}\n", encoding="utf-8")
|
||||
with open(output, "a", encoding="utf-8") as stream:
|
||||
stream.write(f"run={'true' if run else 'false'}\n")
|
||||
print(line)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,259 @@
|
||||
"""scripts/ci/done-build-inputs.py의 시험. 키가 문서를 뺀 파일만 따르는지, 가장 최근 표식과 같은 push만 건너뛰는지,
|
||||
main.yml `done`이 그 판정·표식 파일을 그대로 쓰는지 본다.
|
||||
|
||||
workflow는 checkout을 기본 깊이 1로 하므로, 그 깊이로 clone한 사본에서도 같은 키인지 본다.
|
||||
|
||||
python3 -m unittest discover -s scripts/tests
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPT = ROOT / "scripts/ci/done-build-inputs.py"
|
||||
WORKFLOW = ROOT / ".gitea/workflows/main.yml"
|
||||
_spec = importlib.util.spec_from_file_location("done_build_inputs", SCRIPT)
|
||||
done_build_inputs = importlib.util.module_from_spec(_spec)
|
||||
sys.modules["done_build_inputs"] = done_build_inputs
|
||||
_spec.loader.exec_module(done_build_inputs)
|
||||
|
||||
# The developer's global git settings (hooks, signing) must not reach the throwaway repositories.
|
||||
GIT_ENV = {
|
||||
**os.environ,
|
||||
"GIT_CONFIG_GLOBAL": os.devnull,
|
||||
"GIT_CONFIG_NOSYSTEM": "1",
|
||||
"GIT_AUTHOR_NAME": "test",
|
||||
"GIT_AUTHOR_EMAIL": "test@example.invalid",
|
||||
"GIT_COMMITTER_NAME": "test",
|
||||
"GIT_COMMITTER_EMAIL": "test@example.invalid",
|
||||
}
|
||||
|
||||
|
||||
class Repository:
|
||||
"""A throwaway repository with a source file, a script and a document on main, ignoring build/ as this one does."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._directory = tempfile.TemporaryDirectory()
|
||||
self.root = Path(self._directory.name) / "origin"
|
||||
self.git("init", "-q", "-b", "main", str(self.root), cwd=Path(self._directory.name))
|
||||
self.write("src/adapter/inbound/web/src/main/java/Web.java", "class Web {}\n")
|
||||
self.write("scripts/check.sh", "true\n")
|
||||
self.write("docs/guide.md", "# guide\n")
|
||||
self.write(".gitignore", "build/\n")
|
||||
self.commit("first")
|
||||
|
||||
def git(self, *args: str, cwd: Path | None = None) -> str:
|
||||
return subprocess.run(["git", *args], cwd=cwd or self.root, env=GIT_ENV, check=True,
|
||||
capture_output=True, text=True).stdout.strip()
|
||||
|
||||
def write(self, path: str, text: str) -> None:
|
||||
target = self.root / path
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(text, encoding="utf-8")
|
||||
|
||||
def commit(self, message: str) -> None:
|
||||
self.git("add", "-A")
|
||||
self.git("commit", "-q", "--allow-empty", "-m", message)
|
||||
|
||||
def shallow_clone(self) -> Path:
|
||||
target = Path(self._directory.name) / "depth-1"
|
||||
self.git("clone", "-q", "--depth=1", "--branch", "main", self.root.as_uri(), str(target),
|
||||
cwd=Path(self._directory.name))
|
||||
return target
|
||||
|
||||
def run_script(self, event: str = "push", marker: str | None = None, cwd: Path | None = None,
|
||||
output: bool = True) -> subprocess.CompletedProcess[str]:
|
||||
"""Runs the script as the job does: `marker` is what the restore brought back, None for nothing."""
|
||||
where = cwd or self.root
|
||||
marker_file = where / done_build_inputs.MARKER
|
||||
if marker is None:
|
||||
marker_file.unlink(missing_ok=True)
|
||||
else:
|
||||
marker_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
marker_file.write_text(f"{marker}\n", encoding="utf-8")
|
||||
env = {key: value for key, value in GIT_ENV.items() if key not in ("GITHUB_OUTPUT", "EVENT")}
|
||||
env["EVENT"] = event
|
||||
if output:
|
||||
self.output_file.write_text("", encoding="utf-8")
|
||||
env["GITHUB_OUTPUT"] = str(self.output_file)
|
||||
return subprocess.run([sys.executable, str(SCRIPT)], cwd=where, env=env, capture_output=True, text=True)
|
||||
|
||||
@property
|
||||
def output_file(self) -> Path:
|
||||
return Path(self._directory.name) / "github-output"
|
||||
|
||||
def decide(self, event: str = "push", marker: str | None = None) -> tuple[str, list[str]]:
|
||||
"""(the GITHUB_OUTPUT text, the printed lines)."""
|
||||
result = self.run_script(event, marker)
|
||||
if result.returncode != 0:
|
||||
raise AssertionError(result.stderr)
|
||||
return self.output_file.read_text(encoding="utf-8"), result.stdout.splitlines()
|
||||
|
||||
def key(self, cwd: Path | None = None) -> str:
|
||||
"""The key this run writes to the marker file for the save."""
|
||||
result = self.run_script(cwd=cwd)
|
||||
if result.returncode != 0:
|
||||
raise AssertionError(result.stderr)
|
||||
return ((cwd or self.root) / done_build_inputs.MARKER).read_text(encoding="utf-8").strip()
|
||||
|
||||
def close(self) -> None:
|
||||
self._directory.cleanup()
|
||||
|
||||
|
||||
class DocumentationPathTest(unittest.TestCase):
|
||||
def test_documents_and_guidance_are_documentation(self) -> None:
|
||||
for path in ("docs/guide.md", "docs/registries/env-keys.yaml", "docs/ledger/estimates.jsonl",
|
||||
".claude/settings.json", ".claude/skills/desktop-gates/SKILL.md", "README.md", "AGENTS.md",
|
||||
"src/adapter/inbound/web/README.md", "src/adapter/inbound/web/AGENTS.md",
|
||||
"build-logic/AGENTS.md", ".github/dependency-vulnerability-policy.md"):
|
||||
with self.subTest(path=path):
|
||||
self.assertTrue(done_build_inputs.is_documentation(path))
|
||||
|
||||
def test_everything_the_build_or_a_workflow_reads_is_not(self) -> None:
|
||||
for path in ("src/adapter/inbound/web/src/main/java/Web.java",
|
||||
"src/bootstrap/app/src/test/resources/developer-experience/broken-readme.md",
|
||||
"build-logic/src/main/resources/notes.md", "build.gradle", "settings.gradle",
|
||||
"gradle/libs.versions.toml", "gradle/modules.json", "config/checkstyle/checkstyle.xml",
|
||||
".gitea/workflows/main.yml", "scripts/ci/done-build-inputs.py", "Dockerfile", "compose/app.yml",
|
||||
".tool-versions"):
|
||||
with self.subTest(path=path):
|
||||
self.assertFalse(done_build_inputs.is_documentation(path))
|
||||
|
||||
|
||||
class KeyTest(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.repo = Repository()
|
||||
self.addCleanup(self.repo.close)
|
||||
self.first = self.repo.key()
|
||||
|
||||
def test_a_change_to_documents_only_keeps_the_key(self) -> None:
|
||||
self.repo.write("docs/guide.md", "# guide, again\n")
|
||||
self.repo.write(".claude/rules/docs.md", "# rule\n")
|
||||
self.repo.write("src/adapter/inbound/web/README.md", "# web\n")
|
||||
self.repo.commit("docs")
|
||||
|
||||
self.assertEqual(self.first, self.repo.key())
|
||||
|
||||
def test_a_change_to_any_build_input_changes_the_key(self) -> None:
|
||||
changes = {
|
||||
"source": lambda: self.repo.write("src/adapter/inbound/web/src/main/java/Web.java", "final class Web {}\n"),
|
||||
"new file": lambda: self.repo.write("gradle/libs.versions.toml", "[versions]\n"),
|
||||
"source-set document": lambda: self.repo.write(
|
||||
"src/bootstrap/app/src/test/resources/developer-experience/broken-readme.md", "# fixture\n"),
|
||||
"mode": lambda: (self.repo.root / "scripts/check.sh").chmod(0o755),
|
||||
"moved into docs": lambda: self.repo.git("mv", "scripts/check.sh", "docs/check.sh"),
|
||||
}
|
||||
for name, change in changes.items():
|
||||
with self.subTest(change=name):
|
||||
before = self.repo.key()
|
||||
change()
|
||||
self.repo.commit(name)
|
||||
self.assertNotEqual(before, self.repo.key())
|
||||
|
||||
def test_a_clone_one_commit_deep_has_the_same_key(self) -> None:
|
||||
self.repo.write("src/adapter/inbound/web/src/main/java/Web.java", "final class Web {}\n")
|
||||
self.repo.commit("code")
|
||||
|
||||
self.assertEqual(self.repo.key(), self.repo.key(cwd=self.repo.shallow_clone()))
|
||||
|
||||
def test_the_key_has_its_name_and_a_sha256_digest(self) -> None:
|
||||
self.assertRegex(self.first, r"^done-build-inputs-[0-9a-f]{64}$")
|
||||
|
||||
|
||||
class DecisionTest(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.repo = Repository()
|
||||
self.addCleanup(self.repo.close)
|
||||
self.first = self.repo.key()
|
||||
|
||||
def test_a_push_with_the_newest_markers_inputs_skips_with_one_skip_line(self) -> None:
|
||||
self.repo.write("docs/guide.md", "# guide, again\n")
|
||||
self.repo.commit("docs")
|
||||
|
||||
output, printed = self.repo.decide(marker=self.first)
|
||||
|
||||
self.assertEqual("run=false\n", output)
|
||||
self.assertEqual([f"건너뜀: done — 가장 최근에 끝까지 간 done job과 빌드 입력(문서를 뺀 파일)이 같다 ({self.first})"],
|
||||
printed)
|
||||
|
||||
def test_a_push_with_other_inputs_or_no_marker_runs(self) -> None:
|
||||
self.repo.write("src/adapter/inbound/web/src/main/java/Web.java", "final class Web {}\n")
|
||||
self.repo.commit("code")
|
||||
for marker in (self.first, None, ""):
|
||||
with self.subTest(marker=marker):
|
||||
output, printed = self.repo.decide(marker=marker)
|
||||
self.assertEqual("run=true\n", output)
|
||||
self.assertEqual(1, len(printed))
|
||||
self.assertIn(":prCheck를 돈다", printed[0])
|
||||
|
||||
def test_a_revert_runs_because_the_newest_marker_is_the_reverted_change(self) -> None:
|
||||
self.repo.write("src/adapter/inbound/web/src/main/java/Web.java", "final class Web {}\n")
|
||||
self.repo.commit("code")
|
||||
reverted = self.repo.key()
|
||||
self.repo.git("revert", "--no-edit", "HEAD")
|
||||
|
||||
self.assertEqual(self.first, self.repo.key())
|
||||
self.assertEqual("run=true\n", self.repo.decide(marker=reverted)[0])
|
||||
|
||||
def test_a_scheduled_or_manual_run_always_runs(self) -> None:
|
||||
for event in ("schedule", "workflow_dispatch", ""):
|
||||
with self.subTest(event=event):
|
||||
self.assertEqual("run=true\n", self.repo.decide(event=event, marker=self.first)[0])
|
||||
|
||||
def test_it_leaves_its_own_key_in_the_marker_file_for_the_save(self) -> None:
|
||||
self.repo.write("src/adapter/inbound/web/src/main/java/Web.java", "final class Web {}\n")
|
||||
self.repo.commit("code")
|
||||
|
||||
self.repo.decide(marker=self.first)
|
||||
|
||||
marker = (self.repo.root / done_build_inputs.MARKER).read_text(encoding="utf-8")
|
||||
self.assertNotEqual(f"{self.first}\n", marker)
|
||||
self.assertRegex(marker, r"^done-build-inputs-[0-9a-f]{64}\n$")
|
||||
|
||||
def test_without_an_output_file_or_a_repository_it_fails(self) -> None:
|
||||
self.assertNotEqual(0, self.repo.run_script(output=False).returncode)
|
||||
with tempfile.TemporaryDirectory() as elsewhere:
|
||||
self.assertNotEqual(0, self.repo.run_script(cwd=Path(elsewhere)).returncode)
|
||||
|
||||
|
||||
class WorkflowWiringTest(unittest.TestCase):
|
||||
"""main.yml's `done` restores the newest marker where the script reads it, and runs unless the script says skip."""
|
||||
|
||||
def setUp(self) -> None:
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
match = re.search(r"^ done:\n(?P<body>(?: .*\n|\n)+)", text, re.MULTILINE)
|
||||
self.assertIsNotNone(match, "main.yml has no `done` job")
|
||||
self.job = match.group("body")
|
||||
|
||||
def test_the_marker_is_restored_on_main_before_the_script_at_the_path_it_reads(self) -> None:
|
||||
marker = (" - if: ${{ github.ref == 'refs/heads/main' }}\n"
|
||||
" uses: https://github.com/actions/cache@")
|
||||
script = (" - id: inputs\n env:\n EVENT: ${{ github.event_name }}\n"
|
||||
" run: python3 scripts/ci/done-build-inputs.py\n")
|
||||
self.assertIn(marker, self.job)
|
||||
self.assertIn(script, self.job)
|
||||
self.assertLess(self.job.index(marker), self.job.index(script))
|
||||
self.assertIn(f" path: {done_build_inputs.MARKER.as_posix()}\n", self.job)
|
||||
# A key per run, so the save is never refused and the restore takes the newest marker by prefix.
|
||||
# `/` ends the repository name, so another repository whose name starts with this one never matches.
|
||||
self.assertIn(" key: done-marker-${{ github.repository }}/${{ github.run_id }}\n", self.job)
|
||||
self.assertIn(" restore-keys: done-marker-${{ github.repository }}/\n", self.job)
|
||||
|
||||
def test_gradle_runs_unless_the_script_said_skip(self) -> None:
|
||||
run = "${{ steps.inputs.outputs.run != 'false' }}"
|
||||
self.assertEqual([run, run], re.findall(r"^ - if: (\$\{\{ steps\..*)$", self.job, re.MULTILINE))
|
||||
self.assertIn(f" - if: {run}\n uses: ./.gitea/actions/setup-java-gradle\n", self.job)
|
||||
self.assertIn(f" - if: {run}\n run: ./gradlew :prCheck\n", self.job)
|
||||
self.assertNotRegex(self.job, r"(?m)^ if:", "a job-level condition would skip the whole job quietly")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user