fromtruthound.checkpoint.ciimport(detect_ci_platform,is_ci_environment,get_ci_environment,CIPlatform,)# Detect current platformplatform=detect_ci_platform()print(f"Platform: {platform}")# CIPlatform.GITHUB_ACTIONS# Check if running in CIifis_ci_environment():print("Running in CI")# Check if running locallyifplatform==CIPlatform.LOCAL:print("Running locally")
fromtruthound.checkpoint.ciimportCIPlatformclassCIPlatform(str,Enum):GITHUB_ACTIONS="github_actions"GITLAB_CI="gitlab_ci"JENKINS="jenkins"CIRCLECI="circleci"TRAVIS_CI="travis_ci"AZURE_DEVOPS="azure_devops"BITBUCKET_PIPELINES="bitbucket_pipelines"TEAMCITY="teamcity"BUILDKITE="buildkite"DRONE="drone"AWS_CODEBUILD="aws_codebuild"GOOGLE_CLOUD_BUILD="google_cloud_build"LOCAL="local"# Local environmentUNKNOWN="unknown"# CI but unsupported platform
@dataclassclassCIEnvironment:platform:CIPlatform=CIPlatform.LOCALis_ci:bool=Falseis_pr:bool=Falsebranch:str=""commit_sha:str=""commit_message:str=""pr_number:int|None=Nonepr_target_branch:str=""repository:str=""run_id:str=""run_url:str=""actor:str=""job_name:str=""workflow_name:str=""environment_vars:dict[str,str]=field(default_factory=dict)defto_dict(self)->dict[str,Any]:"""Convert to dictionary."""...
fromtruthound.checkpoint.ciimportget_ci_environmentenv=get_ci_environment()ifenv.is_pr:# Run only on PR buildsresult=checkpoint.run()ifresult.status.value=="failure":# Post comment on PRpost_pr_comment(pr_number=env.pr_number,message=f"Validation failed: {result.summary()}",)
fromtruthound.checkpoint.routingimportActionRouter,Route,TagRuleenv=get_ci_environment()router=ActionRouter()# Main branch: Slack + PagerDutyifenv.branchin("main","master"):router.add_route(Route(name="prod_alerts",rule=StatusRule(statuses=["failure"]),actions=[slack_action,pagerduty_action],))else:# Other branches: Slack onlyrouter.add_route(Route(name="dev_alerts",rule=StatusRule(statuses=["failure"]),actions=[slack_action],))
importsysfromtruthound.checkpointimportCheckpointfromtruthound.checkpoint.ciimportis_ci_environmentcheckpoint=Checkpoint(name="ci_check",data_source="data.csv",validators=["null"],)result=checkpoint.run()# Exit code 1 on failure in CIifis_ci_environment():ifresult.status.valuein("failure","error"):print(f"Validation failed: {result.summary()}")sys.exit(1)