Skip to content

Log updates to state.toml #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,21 @@ def full_build(self):
def run(self, http: urllib3.PoolManager) -> bool:
"""Build and publish a Python doc, for a language, and a version."""
start_time = perf_counter()
start_timestamp = dt.now(tz=timezone.utc).replace(microsecond=0)
logging.info("Running.")
try:
self.cpython_repo.switch(self.version.branch_or_tag)
if self.language.tag != "en":
self.clone_translation()
if self.should_rebuild():
if trigger_reason := self.should_rebuild():
self.build_venv()
self.build()
self.copy_build_to_webroot(http)
self.save_state(build_duration=perf_counter() - start_time)
self.save_state(
build_start=start_timestamp,
build_duration=perf_counter() - start_time,
trigger=trigger_reason,
)
except Exception as err:
logging.exception("Badly handled exception, human, please help.")
if sentry_sdk:
Expand Down Expand Up @@ -885,7 +890,7 @@ def should_rebuild(self):
state = self.load_state()
if not state:
logging.info("Should rebuild: no previous state found.")
return True
return "no previous state"
cpython_sha = self.cpython_repo.run("rev-parse", "HEAD").stdout.strip()
if self.language.tag != "en":
translation_sha = self.translation_repo.run(
Expand All @@ -897,7 +902,7 @@ def should_rebuild(self):
state["translation_sha"],
translation_sha,
)
return True
return "new translations"
if cpython_sha != state["cpython_sha"]:
diff = self.cpython_repo.run(
"diff", "--name-only", state["cpython_sha"], cpython_sha
Expand All @@ -908,7 +913,7 @@ def should_rebuild(self):
state["cpython_sha"],
cpython_sha,
)
return True
return "Doc/ has changed"
logging.info("Nothing changed, no rebuild needed.")
return False

Expand All @@ -921,7 +926,7 @@ def load_state(self) -> dict:
except (KeyError, FileNotFoundError):
return {}

def save_state(self, build_duration: float):
def save_state(self, build_start: dt, build_duration: float, trigger: str):
"""Save current CPython sha1 and current translation sha1.

Using this we can deduce if a rebuild is needed or not.
Expand All @@ -932,17 +937,24 @@ def save_state(self, build_duration: float):
except FileNotFoundError:
states = tomlkit.document()

state = {}
state["cpython_sha"] = self.cpython_repo.run("rev-parse", "HEAD").stdout.strip()
key = f"/{self.language.tag}/{self.version.name}/"
state = {
"last_build_start": build_start,
"last_build_duration": round(build_duration, 0),
"triggered_by": trigger,
"cpython_sha": self.cpython_repo.run("rev-parse", "HEAD").stdout.strip(),
}
if self.language.tag != "en":
state["translation_sha"] = self.translation_repo.run(
"rev-parse", "HEAD"
).stdout.strip()
state["last_build"] = dt.now(timezone.utc)
state["last_build_duration"] = build_duration
states[f"/{self.language.tag}/{self.version.name}/"] = state
states[key] = state
state_file.write_text(tomlkit.dumps(states), encoding="UTF-8")

table = tomlkit.inline_table()
table |= state
logging.info("Saved new rebuild state for %s: %s", key, table.as_string())


def symlink(
www_root: Path,
Expand Down