Coverage for src / mafw / devtools / release / checks.py: 100%

22 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-06-28 13:34 +0000

1# Copyright 2026 European Union 

2# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu) 

3# SPDX-License-Identifier: EUPL-1.2 

4""" 

5Release validation checks for MAFw. 

6 

7This module contains non-git business logic checks used during the release 

8process: tag parsing and missing-release detection. 

9""" 

10 

11from __future__ import annotations 

12 

13from mafw.devtools import DevtoolsError 

14from mafw.devtools.git import get_last_stable_tag 

15from mafw.devtools.release.versioning import ( 

16 STABLE_TAG_PATTERN, 

17 classify_version, 

18 parse_version, 

19) 

20 

21 

22def parse_stable_tag(tag: str) -> tuple[int, int, int]: 

23 """Parse a stable tag in the form ``vX.Y.Z``. 

24 

25 :param tag: Stable tag value. 

26 :type tag: str 

27 :return: Parsed stable version tuple. 

28 :rtype: tuple[int, int, int] 

29 :raises DevtoolsError: If the tag does not match ``vX.Y.Z``. 

30 """ 

31 match = STABLE_TAG_PATTERN.fullmatch(tag) 

32 if match is None: 

33 raise DevtoolsError(f'Unsupported stable tag format "{tag}".') 

34 return ( 

35 int(match.group('major')), 

36 int(match.group('minor')), 

37 int(match.group('micro')), 

38 ) 

39 

40 

41def check_missing_release(current_version: str) -> None: 

42 """Prevent creating a new release when a stable release is already missing a tag. 

43 

44 :param current_version: Current project version. 

45 :type current_version: str 

46 :raises DevtoolsError: If a missing stable release is detected. 

47 """ 

48 current_kind = classify_version(current_version) 

49 if current_kind != 'stable': 

50 return 

51 

52 current_major, current_minor, current_micro, _ = parse_version(current_version) 

53 last_stable_tag = get_last_stable_tag() 

54 if last_stable_tag is None: 

55 return 

56 

57 last_major, last_minor, last_micro = parse_stable_tag(last_stable_tag) 

58 current_tuple = (current_major, current_minor, current_micro) 

59 last_tuple = (last_major, last_minor, last_micro) 

60 if current_tuple > last_tuple: 

61 raise DevtoolsError( 

62 'Missing stable release detected: ' 

63 f'last stable tag is {last_stable_tag}, but current version is v{current_version}. ' 

64 'Tag the current stable version first, or disable this check with ' 

65 '--without-missing-release-check.' 

66 )