Compare commits
5 Commits
852bac8653
...
7228083cfb
Author | SHA1 | Date | |
---|---|---|---|
7228083cfb | |||
a0f4174bf8 | |||
a280e205d6 | |||
3c8c276537 | |||
1663ce00cd |
|
@ -1,10 +1,8 @@
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, List
|
from typing import List
|
||||||
|
|
||||||
from pydantic import AliasChoices, BaseModel, Field, field_validator, model_validator
|
from pydantic import AliasChoices, BaseModel, Field, model_validator
|
||||||
|
|
||||||
from joj3_config_generator.models.common import Memory
|
|
||||||
|
|
||||||
|
|
||||||
class Files(BaseModel):
|
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):
|
class Config(BaseModel):
|
||||||
root: Path = Field(Path("."), exclude=True)
|
root: Path = Field(Path("."), exclude=True)
|
||||||
path: Path = Field(Path("repo.toml"), exclude=True)
|
path: Path = Field(Path("repo.toml"), exclude=True)
|
||||||
|
@ -72,9 +52,9 @@ class Config(BaseModel):
|
||||||
),
|
),
|
||||||
exclude=True,
|
exclude=True,
|
||||||
)
|
)
|
||||||
grading_repo_name: str = Field(
|
|
||||||
"",
|
max_size: float = Field(
|
||||||
validation_alias=AliasChoices("grading-repo-name", "grading_repo_name"),
|
10, ge=0, validation_alias=AliasChoices("max-size", "max_size")
|
||||||
)
|
)
|
||||||
files: Files = Files()
|
files: Files = Files()
|
||||||
sandbox_token: str = Field(
|
sandbox_token: str = Field(
|
||||||
|
@ -84,23 +64,18 @@ class Config(BaseModel):
|
||||||
100, validation_alias=AliasChoices("max-total-score", "max_total_score")
|
100, validation_alias=AliasChoices("max-total-score", "max_total_score")
|
||||||
)
|
)
|
||||||
groups: Groups = Groups()
|
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(
|
health_check_score: int = Field(
|
||||||
0, validation_alias=AliasChoices("health-check-score", "health_check_score")
|
0, validation_alias=AliasChoices("health-check-score", "health_check_score")
|
||||||
)
|
)
|
||||||
|
issue: Issue = Issue()
|
||||||
immutable_path: Path = Field(
|
immutable_path: Path = Field(
|
||||||
Path("immutable"),
|
Path("immutable"),
|
||||||
validation_alias=AliasChoices("immutable-path", "immutable_path"),
|
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
|
# TODO: remove gitea_token and gitea_org in the future
|
||||||
gitea_token: str = Field(
|
gitea_token: str = Field(
|
||||||
"", validation_alias=AliasChoices("gitea-token", "gitea_token")
|
"", validation_alias=AliasChoices("gitea-token", "gitea_token")
|
||||||
|
@ -116,14 +91,3 @@ class Config(BaseModel):
|
||||||
else:
|
else:
|
||||||
self.grading_repo_name = Path.cwd().name
|
self.grading_repo_name = Path.cwd().name
|
||||||
return self
|
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
|
|
||||||
|
|
|
@ -101,9 +101,7 @@ def get_check_lists(repo_conf: repo.Config) -> Tuple[List[str], List[str]]:
|
||||||
immutable_files.append(file_path)
|
immutable_files.append(file_path)
|
||||||
file_sums.append(calc_sha256sum(file_path))
|
file_sums.append(calc_sha256sum(file_path))
|
||||||
file_names.append(file)
|
file_names.append(file)
|
||||||
immutable_dir = (
|
immutable_dir = (repo_conf.root / repo_conf.path).parent / repo_conf.immutable_path
|
||||||
repo_conf.root / repo_conf.path
|
|
||||||
).parent / repo_conf.health_check.immutable_path
|
|
||||||
if not immutable_dir.exists():
|
if not immutable_dir.exists():
|
||||||
return file_sums, file_names
|
return file_sums, file_names
|
||||||
file_sums = []
|
file_sums = []
|
||||||
|
@ -124,7 +122,7 @@ def get_health_check_args(repo_conf: repo.Config) -> List[str]:
|
||||||
return [
|
return [
|
||||||
"/usr/local/bin/repo-health-checker",
|
"/usr/local/bin/repo-health-checker",
|
||||||
"-root=.",
|
"-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"-meta={meta}" for meta in repo_conf.files.required],
|
||||||
f"-checkFileSumList={','.join(file_sums)}",
|
f"-checkFileSumList={','.join(file_sums)}",
|
||||||
f"-checkFileNameList={','.join(file_names)}",
|
f"-checkFileNameList={','.join(file_names)}",
|
||||||
|
@ -196,7 +194,7 @@ def get_health_check_stage(
|
||||||
parsers=[
|
parsers=[
|
||||||
result.Parser(
|
result.Parser(
|
||||||
name="healthcheck",
|
name="healthcheck",
|
||||||
with_=result.ScoreConfig(score=repo_conf.health_check.score),
|
with_=result.ScoreConfig(score=repo_conf.health_check_score),
|
||||||
),
|
),
|
||||||
result.Parser(name="debug"),
|
result.Parser(name="debug"),
|
||||||
],
|
],
|
||||||
|
|
|
@ -3,9 +3,9 @@ grading-repo-name = "ece280-joj"
|
||||||
sandbox-token = "test"
|
sandbox-token = "test"
|
||||||
# reconfigure later
|
# reconfigure later
|
||||||
max-total-score = 1000
|
max-total-score = 1000
|
||||||
|
max-size = 50.5
|
||||||
|
|
||||||
health-check.max-size = "50.5m"
|
immutable_path = "immutable"
|
||||||
health-check.immutable_path = "immutable"
|
|
||||||
|
|
||||||
# for tests
|
# for tests
|
||||||
[groups]
|
[groups]
|
||||||
|
|
|
@ -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
|
files.required = ["README.md", "Changelog.md"] # required files name, case insensitive
|
||||||
sandbox-token = "" # sandbox token
|
sandbox-token = "" # sandbox token
|
||||||
|
health-check-score = 0 # score for health check stage
|
||||||
health-check.score = 0 # score for health check stage
|
immutable-path = "immutable" # path for immutable files, relative to the path of repo.toml
|
||||||
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
|
|
||||||
|
|
||||||
issue.label.name = "Kind/Testing" # label for issues
|
issue.label.name = "Kind/Testing" # label for issues
|
||||||
issue.label.color = "#795548" # color for the label
|
issue.label.color = "#795548" # color for the label
|
||||||
|
|
Loading…
Reference in New Issue
Block a user