Compare commits

..

5 Commits

Author SHA1 Message Date
7228083cfb
docs: comments on copy-in-cwd & limit
All checks were successful
build / build (push) Successful in 1m31s
build / trigger-build-image (push) Has been skipped
build / build (pull_request) Successful in 1m35s
build / trigger-build-image (pull_request) Has been skipped
2025-06-30 19:58:43 -04:00
a0f4174bf8
docs: explain empty groups.name
All checks were successful
build / build (pull_request) Successful in 2m5s
build / build (push) Successful in 2m7s
build / trigger-build-image (pull_request) Has been skipped
build / trigger-build-image (push) Has been skipped
2025-06-30 19:43:53 -04:00
a280e205d6
fix: typo
All checks were successful
build / build (pull_request) Successful in 1m51s
build / build (push) Successful in 1m53s
build / trigger-build-image (push) Has been skipped
build / trigger-build-image (pull_request) Has been skipped
2025-06-30 19:31:59 -04:00
3c8c276537
docs: full toml sample with full comments
All checks were successful
build / build (pull_request) Successful in 2m22s
build / build (push) Successful in 2m25s
build / trigger-build-image (pull_request) Has been skipped
build / trigger-build-image (push) Has been skipped
2025-06-30 13:25:10 -04:00
1663ce00cd
docs: full toml sample 2025-06-30 13:25:10 -04:00
4 changed files with 18 additions and 57 deletions

View File

@ -1,10 +1,8 @@
import os
from pathlib import Path
from typing import Any, List
from typing import List
from pydantic import AliasChoices, BaseModel, Field, field_validator, model_validator
from joj3_config_generator.models.common import Memory
from pydantic import AliasChoices, BaseModel, Field, model_validator
class Files(BaseModel):
@ -36,24 +34,6 @@ class Issue(BaseModel):
)
class HealthCheck(BaseModel):
score: int = 0
max_size: int = Field(
Memory("10m"), validation_alias=AliasChoices("max-size", "max_size")
)
immutable_path: Path = Field(
Path("immutable"),
validation_alias=AliasChoices("immutable-path", "immutable_path"),
)
@field_validator("max_size", mode="before")
@classmethod
def ensure_mem_type(cls, v: Any) -> Memory:
if isinstance(v, str):
return Memory(v)
raise ValueError(f'Must be a string, e.g., "256m" or "1g", but got {v}')
class Config(BaseModel):
root: Path = Field(Path("."), exclude=True)
path: Path = Field(Path("repo.toml"), exclude=True)
@ -72,9 +52,9 @@ class Config(BaseModel):
),
exclude=True,
)
grading_repo_name: str = Field(
"",
validation_alias=AliasChoices("grading-repo-name", "grading_repo_name"),
max_size: float = Field(
10, ge=0, validation_alias=AliasChoices("max-size", "max_size")
)
files: Files = Files()
sandbox_token: str = Field(
@ -84,23 +64,18 @@ class Config(BaseModel):
100, validation_alias=AliasChoices("max-total-score", "max_total_score")
)
groups: Groups = Groups()
issue: Issue = Issue()
health_check: HealthCheck = Field(
HealthCheck(), validation_alias=AliasChoices("health-check", "health_check")
)
# TODO: remove max_size, health_check_score, and immutable_path in the future
max_size: float = Field(
10, ge=0, validation_alias=AliasChoices("max-size", "max_size")
)
health_check_score: int = Field(
0, validation_alias=AliasChoices("health-check-score", "health_check_score")
)
issue: Issue = Issue()
immutable_path: Path = Field(
Path("immutable"),
validation_alias=AliasChoices("immutable-path", "immutable_path"),
)
grading_repo_name: str = Field(
"",
validation_alias=AliasChoices("grading-repo-name", "grading_repo_name"),
)
# TODO: remove gitea_token and gitea_org in the future
gitea_token: str = Field(
"", validation_alias=AliasChoices("gitea-token", "gitea_token")
@ -116,14 +91,3 @@ class Config(BaseModel):
else:
self.grading_repo_name = Path.cwd().name
return self
# TODO: remove this validator in the future
@model_validator(mode="after")
def set_health_check(self) -> "Config":
if "health_check_score" in self.model_fields_set:
self.health_check.score = self.health_check_score
if "max_size" in self.model_fields_set:
self.health_check.max_size = Memory(f"{self.max_size}m")
if "immutable_path" in self.model_fields_set:
self.health_check.immutable_path = self.immutable_path
return self

View File

@ -101,9 +101,7 @@ def get_check_lists(repo_conf: repo.Config) -> Tuple[List[str], List[str]]:
immutable_files.append(file_path)
file_sums.append(calc_sha256sum(file_path))
file_names.append(file)
immutable_dir = (
repo_conf.root / repo_conf.path
).parent / repo_conf.health_check.immutable_path
immutable_dir = (repo_conf.root / repo_conf.path).parent / repo_conf.immutable_path
if not immutable_dir.exists():
return file_sums, file_names
file_sums = []
@ -124,7 +122,7 @@ def get_health_check_args(repo_conf: repo.Config) -> List[str]:
return [
"/usr/local/bin/repo-health-checker",
"-root=.",
f"-repoSize={str(repo_conf.health_check.max_size / 1024 / 1024)}", # B -> MB
f"-repoSize={str(repo_conf.max_size)}",
*[f"-meta={meta}" for meta in repo_conf.files.required],
f"-checkFileSumList={','.join(file_sums)}",
f"-checkFileNameList={','.join(file_names)}",
@ -196,7 +194,7 @@ def get_health_check_stage(
parsers=[
result.Parser(
name="healthcheck",
with_=result.ScoreConfig(score=repo_conf.health_check.score),
with_=result.ScoreConfig(score=repo_conf.health_check_score),
),
result.Parser(name="debug"),
],

View File

@ -3,9 +3,9 @@ grading-repo-name = "ece280-joj"
sandbox-token = "test"
# reconfigure later
max-total-score = 1000
max-size = 50.5
health-check.max-size = "50.5m"
health-check.immutable_path = "immutable"
immutable_path = "immutable"
# for tests
[groups]

View File

@ -1,9 +1,8 @@
max-size = 10 # max size of the repository in MB
files.required = ["README.md", "Changelog.md"] # required files name, case insensitive
sandbox-token = "" # sandbox token
health-check.score = 0 # score for health check stage
health-check.max-size = "10m" # max size of the repository
health-check.immutable-path = "immutable" # path for immutable files, relative to the path of repo.toml
health-check-score = 0 # score for health check stage
immutable-path = "immutable" # path for immutable files, relative to the path of repo.toml
issue.label.name = "Kind/Testing" # label for issues
issue.label.color = "#795548" # color for the label