semantic-tag-increment 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- semantic_tag_increment/__init__.py +169 -0
- semantic_tag_increment/__main__.py +14 -0
- semantic_tag_increment/app_context.py +143 -0
- semantic_tag_increment/cli.py +31 -0
- semantic_tag_increment/cli_interface.py +434 -0
- semantic_tag_increment/config.py +169 -0
- semantic_tag_increment/exceptions.py +377 -0
- semantic_tag_increment/git_operations.py +226 -0
- semantic_tag_increment/github_actions.py +291 -0
- semantic_tag_increment/incrementer.py +753 -0
- semantic_tag_increment/io_operations.py +73 -0
- semantic_tag_increment/logging_config.py +205 -0
- semantic_tag_increment/main.py +36 -0
- semantic_tag_increment/modes.py +204 -0
- semantic_tag_increment/parser.py +334 -0
- semantic_tag_increment-0.1.1.dist-info/METADATA +533 -0
- semantic_tag_increment-0.1.1.dist-info/RECORD +20 -0
- semantic_tag_increment-0.1.1.dist-info/WHEEL +4 -0
- semantic_tag_increment-0.1.1.dist-info/entry_points.txt +2 -0
- semantic_tag_increment-0.1.1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2025 The Linux Foundation
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Semantic Tag Increment - A Python tool for incrementing semantic version tags.
|
|
6
|
+
|
|
7
|
+
This package provides both a CLI tool (using Typer) and a GitHub Action interface
|
|
8
|
+
for incrementing semantic version tags following the semantic versioning specification.
|
|
9
|
+
It supports complex pre-release and metadata patterns beyond basic major.minor.patch.
|
|
10
|
+
|
|
11
|
+
## CLI Usage Examples
|
|
12
|
+
|
|
13
|
+
Basic version incrementing:
|
|
14
|
+
$ semantic-tag-increment increment --tag "v1.2.3" --increment "patch"
|
|
15
|
+
v1.2.4
|
|
16
|
+
|
|
17
|
+
$ semantic-tag-increment increment --tag "1.0.0" --increment "minor"
|
|
18
|
+
1.1.0
|
|
19
|
+
|
|
20
|
+
$ semantic-tag-increment increment --tag "2.1.0" --increment "major"
|
|
21
|
+
3.0.0
|
|
22
|
+
|
|
23
|
+
Pre-release incrementing:
|
|
24
|
+
$ semantic-tag-increment increment --tag "v1.2.3" --increment "prerelease"
|
|
25
|
+
v1.2.4-dev.1
|
|
26
|
+
|
|
27
|
+
$ semantic-tag-increment increment --tag "1.0.0" --increment "prerelease" --prerelease-type "alpha"
|
|
28
|
+
1.0.1-alpha.1
|
|
29
|
+
|
|
30
|
+
$ semantic-tag-increment increment --tag "1.0.0-alpha.1" --increment "prerelease"
|
|
31
|
+
1.0.0-alpha.2
|
|
32
|
+
|
|
33
|
+
Version validation:
|
|
34
|
+
$ semantic-tag-increment validate --tag "v1.2.3-alpha.1+build.123"
|
|
35
|
+
✅ Valid semantic version: v1.2.3-alpha.1+build.123
|
|
36
|
+
|
|
37
|
+
Version suggestions:
|
|
38
|
+
$ semantic-tag-increment suggest --tag "v1.2.3" --increment "prerelease"
|
|
39
|
+
Suggestions for prerelease increment of v1.2.3:
|
|
40
|
+
1. v1.2.4-dev.1
|
|
41
|
+
2. v1.2.4-alpha.1
|
|
42
|
+
3. v1.2.4-beta.1
|
|
43
|
+
|
|
44
|
+
## Python API Usage Examples
|
|
45
|
+
|
|
46
|
+
Basic usage:
|
|
47
|
+
>>> from semantic_tag_increment import SemanticVersion, VersionIncrementer
|
|
48
|
+
>>> from semantic_tag_increment.incrementer import IncrementType
|
|
49
|
+
|
|
50
|
+
>>> # Parse a version
|
|
51
|
+
>>> version = SemanticVersion.parse("v1.2.3")
|
|
52
|
+
>>> print(version.major, version.minor, version.patch)
|
|
53
|
+
1 2 3
|
|
54
|
+
|
|
55
|
+
>>> # Increment versions
|
|
56
|
+
>>> incrementer = VersionIncrementer()
|
|
57
|
+
>>> next_version = incrementer.increment(version, IncrementType.PATCH)
|
|
58
|
+
>>> print(next_version)
|
|
59
|
+
v1.2.4
|
|
60
|
+
|
|
61
|
+
Advanced usage with conflict detection:
|
|
62
|
+
>>> # With existing tags to avoid conflicts
|
|
63
|
+
>>> existing_tags = {"v1.2.3", "v1.2.4", "v1.2.5-dev.1"}
|
|
64
|
+
>>> incrementer = VersionIncrementer(existing_tags)
|
|
65
|
+
>>> next_version = incrementer.increment(version, IncrementType.PATCH)
|
|
66
|
+
>>> print(next_version) # Will find next available version
|
|
67
|
+
v1.2.5
|
|
68
|
+
|
|
69
|
+
Pre-release handling:
|
|
70
|
+
>>> # Create pre-release versions
|
|
71
|
+
>>> prerelease = incrementer.increment(
|
|
72
|
+
... version, IncrementType.PRERELEASE, "alpha"
|
|
73
|
+
... )
|
|
74
|
+
>>> print(prerelease)
|
|
75
|
+
v1.2.4-alpha.1
|
|
76
|
+
|
|
77
|
+
>>> # Increment existing pre-release
|
|
78
|
+
>>> alpha_version = SemanticVersion.parse("v1.0.0-alpha.1")
|
|
79
|
+
>>> next_alpha = incrementer.increment(alpha_version, IncrementType.PRERELEASE)
|
|
80
|
+
>>> print(next_alpha)
|
|
81
|
+
v1.0.0-alpha.2
|
|
82
|
+
|
|
83
|
+
## GitHub Actions Usage
|
|
84
|
+
|
|
85
|
+
Basic workflow step:
|
|
86
|
+
- name: Increment version
|
|
87
|
+
id: increment
|
|
88
|
+
uses: lfreleng-actions/semantic-tag-increment@v1
|
|
89
|
+
with:
|
|
90
|
+
tag: ${{ steps.get_version.outputs.version }}
|
|
91
|
+
increment: 'patch'
|
|
92
|
+
|
|
93
|
+
- name: Use incremented version
|
|
94
|
+
run: echo "New version: ${{ steps.increment.outputs.tag }}"
|
|
95
|
+
|
|
96
|
+
Advanced workflow with pre-release:
|
|
97
|
+
- name: Increment pre-release
|
|
98
|
+
id: increment
|
|
99
|
+
uses: lfreleng-actions/semantic-tag-increment@v1
|
|
100
|
+
with:
|
|
101
|
+
tag: 'v1.2.3'
|
|
102
|
+
increment: 'prerelease'
|
|
103
|
+
prerelease_type: 'rc'
|
|
104
|
+
|
|
105
|
+
- name: Create release
|
|
106
|
+
run: |
|
|
107
|
+
echo "Full version: ${{ steps.increment.outputs.tag }}"
|
|
108
|
+
echo "Numeric version: ${{ steps.increment.outputs.numeric_tag }}"
|
|
109
|
+
|
|
110
|
+
## Supported Version Patterns
|
|
111
|
+
|
|
112
|
+
The tool supports all valid semantic version patterns including:
|
|
113
|
+
- Basic versions: 1.2.3, v1.2.3, V1.2.3
|
|
114
|
+
- Pre-release versions: 1.2.3-alpha.1, 1.2.3-beta.2, 1.2.3-rc.1
|
|
115
|
+
- Complex pre-release: 1.2.3-alpha.1.2, 1.2.3-dev.20231201
|
|
116
|
+
- Build metadata: 1.2.3+build.123, 1.2.3-alpha.1+build.456
|
|
117
|
+
- Edge cases: 1.2.3----RC-SNAPSHOT.12.9.1--.12+788
|
|
118
|
+
|
|
119
|
+
## Features
|
|
120
|
+
|
|
121
|
+
- ✅ Full semantic versioning specification compliance
|
|
122
|
+
- ✅ Intelligent pre-release increment detection
|
|
123
|
+
- ✅ Conflict detection with existing git tags
|
|
124
|
+
- ✅ Multiple output formats (full, numeric, both)
|
|
125
|
+
- ✅ GitHub Actions integration
|
|
126
|
+
- ✅ Comprehensive CLI interface
|
|
127
|
+
- ✅ Python API for programmatic use
|
|
128
|
+
- ✅ Extensive test coverage
|
|
129
|
+
- ✅ Type hints and mypy support
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
__version__ = "1.0.0"
|
|
133
|
+
|
|
134
|
+
from .cli import main
|
|
135
|
+
from .cli_interface import app
|
|
136
|
+
from .incrementer import VersionIncrementer
|
|
137
|
+
from .parser import SemanticVersion
|
|
138
|
+
from .exceptions import (
|
|
139
|
+
SemanticVersionError,
|
|
140
|
+
ValidationError,
|
|
141
|
+
ParseError,
|
|
142
|
+
IncrementError,
|
|
143
|
+
GitOperationError,
|
|
144
|
+
ConfigurationError,
|
|
145
|
+
SecurityError,
|
|
146
|
+
handle_cli_errors,
|
|
147
|
+
handle_github_actions_errors,
|
|
148
|
+
ErrorReporter,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
__all__ = [
|
|
152
|
+
"SemanticVersion",
|
|
153
|
+
"VersionIncrementer",
|
|
154
|
+
"app",
|
|
155
|
+
"main",
|
|
156
|
+
"__version__",
|
|
157
|
+
# Exception classes
|
|
158
|
+
"SemanticVersionError",
|
|
159
|
+
"ValidationError",
|
|
160
|
+
"ParseError",
|
|
161
|
+
"IncrementError",
|
|
162
|
+
"GitOperationError",
|
|
163
|
+
"ConfigurationError",
|
|
164
|
+
"SecurityError",
|
|
165
|
+
# Error handling utilities
|
|
166
|
+
"handle_cli_errors",
|
|
167
|
+
"handle_github_actions_errors",
|
|
168
|
+
"ErrorReporter",
|
|
169
|
+
]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2025 The Linux Foundation
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Main entry point for the semantic tag increment tool.
|
|
6
|
+
|
|
7
|
+
This module allows the package to be executed as a module using:
|
|
8
|
+
python -m semantic_tag_increment
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .cli import main
|
|
12
|
+
|
|
13
|
+
if __name__ == "__main__":
|
|
14
|
+
main()
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2025 The Linux Foundation
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Application context module.
|
|
6
|
+
|
|
7
|
+
This module handles application context detection and configuration for
|
|
8
|
+
string-mode tag incrementing in different execution modes (CLI vs GitHub Actions).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import sys
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
|
|
14
|
+
from .io_operations import IOOperations
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class AppContext:
|
|
19
|
+
"""Application execution context."""
|
|
20
|
+
|
|
21
|
+
is_github_actions: bool
|
|
22
|
+
is_cli_mode: bool
|
|
23
|
+
debug_mode: bool
|
|
24
|
+
has_cli_command: bool
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ContextDetector:
|
|
28
|
+
"""Detects and configures application execution context."""
|
|
29
|
+
|
|
30
|
+
CLI_COMMANDS: frozenset[str] = frozenset(
|
|
31
|
+
{"increment", "validate", "suggest", "help", "--help", "-h"}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def detect_context() -> AppContext:
|
|
36
|
+
"""
|
|
37
|
+
Detect the current application execution context.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
AppContext with detected settings
|
|
41
|
+
"""
|
|
42
|
+
is_github_actions = IOOperations.is_github_actions()
|
|
43
|
+
has_cli_command = ContextDetector._has_cli_command()
|
|
44
|
+
debug_mode = ContextDetector._get_debug_mode()
|
|
45
|
+
|
|
46
|
+
# CLI mode if:
|
|
47
|
+
# 1. Not in GitHub Actions, OR
|
|
48
|
+
# 2. Help was requested, OR
|
|
49
|
+
# 3. Explicit CLI command provided
|
|
50
|
+
is_cli_mode = (
|
|
51
|
+
not is_github_actions
|
|
52
|
+
or ContextDetector._is_help_requested()
|
|
53
|
+
or has_cli_command
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return AppContext(
|
|
57
|
+
is_github_actions=is_github_actions,
|
|
58
|
+
is_cli_mode=is_cli_mode,
|
|
59
|
+
debug_mode=debug_mode,
|
|
60
|
+
has_cli_command=has_cli_command
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def _has_cli_command() -> bool:
|
|
65
|
+
"""Check if any CLI commands are present in argv."""
|
|
66
|
+
return any(cmd in sys.argv for cmd in ContextDetector.CLI_COMMANDS)
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def _is_help_requested() -> bool:
|
|
70
|
+
"""Check if help was requested."""
|
|
71
|
+
return "--help" in sys.argv or "-h" in sys.argv
|
|
72
|
+
|
|
73
|
+
@staticmethod
|
|
74
|
+
def _get_debug_mode() -> bool:
|
|
75
|
+
"""Determine if debug mode should be enabled."""
|
|
76
|
+
# Check CLI debug flag first
|
|
77
|
+
if "--debug" in sys.argv:
|
|
78
|
+
return True
|
|
79
|
+
|
|
80
|
+
# Check GitHub Actions debug input
|
|
81
|
+
if IOOperations.is_github_actions():
|
|
82
|
+
debug_input = IOOperations.get_env_var("INPUT_DEBUG", "false")
|
|
83
|
+
if debug_input:
|
|
84
|
+
return debug_input.lower() in ("true", "1", "yes")
|
|
85
|
+
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class GitHubActionsConfig:
|
|
90
|
+
"""Configuration for GitHub Actions mode."""
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def get_inputs() -> dict[str, str | None]:
|
|
94
|
+
"""
|
|
95
|
+
Get GitHub Actions inputs from environment variables.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
Dictionary of input values with defaults applied
|
|
99
|
+
"""
|
|
100
|
+
input_mappings = {
|
|
101
|
+
"tag": "INPUT_TAG",
|
|
102
|
+
"increment": "INPUT_INCREMENT",
|
|
103
|
+
"prerelease_type": "INPUT_PRERELEASE_TYPE",
|
|
104
|
+
"path": "INPUT_PATH",
|
|
105
|
+
"debug": "INPUT_DEBUG",
|
|
106
|
+
"check_tags": "INPUT_CHECK_TAGS",
|
|
107
|
+
"preserve_metadata": "INPUT_PRESERVE_METADATA",
|
|
108
|
+
"fetch_timeout": "INPUT_FETCH_TIMEOUT",
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
defaults: dict[str, str | None] = {
|
|
112
|
+
"increment": "dev",
|
|
113
|
+
"prerelease_type": None,
|
|
114
|
+
"path": ".",
|
|
115
|
+
"debug": "false",
|
|
116
|
+
"check_tags": "true",
|
|
117
|
+
"preserve_metadata": "false",
|
|
118
|
+
"fetch_timeout": "120",
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
config: dict[str, str | None] = {}
|
|
122
|
+
for param, env_var in input_mappings.items():
|
|
123
|
+
value = IOOperations.get_env_var(env_var, defaults.get(param))
|
|
124
|
+
if value is not None and value != "":
|
|
125
|
+
config[param] = value
|
|
126
|
+
|
|
127
|
+
return config
|
|
128
|
+
|
|
129
|
+
@staticmethod
|
|
130
|
+
def validate_required_inputs(config: dict[str, str | None]) -> None:
|
|
131
|
+
"""
|
|
132
|
+
Validate that required inputs are present for string mode.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
config: Configuration dictionary
|
|
136
|
+
|
|
137
|
+
Raises:
|
|
138
|
+
ValueError: If required inputs are missing
|
|
139
|
+
"""
|
|
140
|
+
# Validate required tag input
|
|
141
|
+
tag = config.get("tag")
|
|
142
|
+
if not tag or not tag.strip():
|
|
143
|
+
raise ValueError("String mode requires a non-empty 'tag' input")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2025 The Linux Foundation
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
CLI interface for semantic tag incrementing.
|
|
6
|
+
|
|
7
|
+
This module provides the command-line interface using Typer for both standalone
|
|
8
|
+
CLI usage and GitHub Actions integration.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# Import the new main entry point
|
|
12
|
+
from .main import main
|
|
13
|
+
from .github_actions import GitHubActionsRunner
|
|
14
|
+
from .app_context import ContextDetector
|
|
15
|
+
from .cli_interface import app
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def run_github_action() -> None:
|
|
19
|
+
"""
|
|
20
|
+
Run in GitHub Actions mode.
|
|
21
|
+
|
|
22
|
+
This function provides backwards compatibility for tests while using
|
|
23
|
+
the new refactored GitHub Actions runner.
|
|
24
|
+
"""
|
|
25
|
+
context = ContextDetector.detect_context()
|
|
26
|
+
runner = GitHubActionsRunner(debug_mode=context.debug_mode)
|
|
27
|
+
runner.run()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Re-export for backwards compatibility
|
|
31
|
+
__all__ = ["main", "run_github_action", "app"]
|