Coverage for /builds/svesch/cikit/src/cikit/status.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-10-09 14:17 +0000

1# SPDX-License-Identifier: GPL-3.0-or-later 

2"""CI run status utilities. 

3 

4This module provides a minimal helper to collect and aggregate status 

5information during a CI run. It is primarily used to track the effective 

6process exit code across multiple sections where recoverable errors may 

7occur. 

8 

9The design is intentionally lightweight and independent of logging, 

10environment handling, or CI provider logic. 

11 

12Author: 

13 Sven Schlender 

14Date: 

15 2026-05-05 

16""" 

17 

18 

19class CiRunStatus: 

20 """Collect and aggregate CI run status information. 

21 

22 The class stores the highest exit code observed during a run. It is 

23 typically updated when recoverable errors are handled locally but 

24 should still influence the final process exit status. 

25 """ 

26 

27 def __init__(self): 

28 """Initialize a new run status container. 

29 

30 The initial exit code is set to 0, indicating a successful run. 

31 """ 

32 self._exit_code = 0 

33 

34 def set_exit_code(self, exit_code: int): 

35 """Update the stored exit code. 

36 

37 The highest exit code seen so far is retained. This ensures that 

38 more severe errors are not overwritten by less severe ones. 

39 

40 Args: 

41 exit_code: Exit code to register. 

42 

43 Returns: 

44 None 

45 """ 

46 self._exit_code = max(self._exit_code, exit_code) 

47 

48 @property 

49 def exit_code(self) -> int: 

50 """Return the aggregated exit code. 

51 

52 Returns: 

53 The highest exit code registered during the run. 

54 """ 

55 return self._exit_code