common-python-tasks 0.0.3__py3-none-any.whl → 0.2.0__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.
- common_python_tasks/__init__.py +14 -3
- common_python_tasks/__main__.py +79 -6
- common_python_tasks/git.py +61 -22
- common_python_tasks/github.py +58 -1
- common_python_tasks/project.py +3 -3
- common_python_tasks/tasks.py +318 -128
- common_python_tasks/utils.py +43 -9
- {common_python_tasks-0.0.3.dist-info → common_python_tasks-0.2.0.dist-info}/METADATA +57 -44
- {common_python_tasks-0.0.3.dist-info → common_python_tasks-0.2.0.dist-info}/RECORD +11 -11
- {common_python_tasks-0.0.3.dist-info → common_python_tasks-0.2.0.dist-info}/WHEEL +1 -1
- {common_python_tasks-0.0.3.dist-info → common_python_tasks-0.2.0.dist-info}/licenses/LICENSE +0 -0
common_python_tasks/tasks.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import contextvars
|
|
1
2
|
import logging
|
|
2
3
|
import os
|
|
4
|
+
from functools import partial, wraps
|
|
3
5
|
from pathlib import Path
|
|
4
6
|
|
|
5
7
|
from poethepoet_tasks import TaskCollection
|
|
@@ -46,6 +48,160 @@ tasks = TaskCollection(
|
|
|
46
48
|
]
|
|
47
49
|
)
|
|
48
50
|
|
|
51
|
+
_task_call_depth: contextvars.ContextVar[int] = contextvars.ContextVar(
|
|
52
|
+
"common_python_tasks_task_call_depth", default=0
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
_original_script = tasks.script
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _wrap_task_function(func: callable, task_name: str | None) -> callable:
|
|
59
|
+
resolved_task_name = task_name or func.__name__.replace("_", "-").lower()
|
|
60
|
+
|
|
61
|
+
@wraps(func)
|
|
62
|
+
def wrapped(*args, **kwargs):
|
|
63
|
+
current_depth = _task_call_depth.get()
|
|
64
|
+
if current_depth > 0:
|
|
65
|
+
LOGGER.log(
|
|
66
|
+
(
|
|
67
|
+
logging.INFO
|
|
68
|
+
if not resolved_task_name.startswith("_")
|
|
69
|
+
else logging.DEBUG
|
|
70
|
+
),
|
|
71
|
+
"Running task %s",
|
|
72
|
+
resolved_task_name,
|
|
73
|
+
)
|
|
74
|
+
token = _task_call_depth.set(current_depth + 1)
|
|
75
|
+
try:
|
|
76
|
+
return func(*args, **kwargs)
|
|
77
|
+
finally:
|
|
78
|
+
_task_call_depth.reset(token)
|
|
79
|
+
|
|
80
|
+
return wrapped
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _script(
|
|
84
|
+
func=None,
|
|
85
|
+
*,
|
|
86
|
+
task_name: str | None = None,
|
|
87
|
+
help: str | None = None,
|
|
88
|
+
task_args: bool = True,
|
|
89
|
+
options: dict | None = None,
|
|
90
|
+
tags: tuple[str, ...] = (),
|
|
91
|
+
):
|
|
92
|
+
if func is None:
|
|
93
|
+
return partial(
|
|
94
|
+
_script,
|
|
95
|
+
task_name=task_name,
|
|
96
|
+
help=help,
|
|
97
|
+
task_args=task_args,
|
|
98
|
+
options=options,
|
|
99
|
+
tags=tags,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
wrapped = _wrap_task_function(func, task_name)
|
|
103
|
+
return _original_script(
|
|
104
|
+
wrapped,
|
|
105
|
+
task_name=task_name,
|
|
106
|
+
help=help,
|
|
107
|
+
task_args=task_args,
|
|
108
|
+
options=options,
|
|
109
|
+
tags=tags,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
tasks.script = _script
|
|
114
|
+
|
|
115
|
+
NO_PROMPT_ENV_VAR = "COMMON_PYTHON_TASKS_NO_PROMPT"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _should_update_release_changelog() -> bool:
|
|
119
|
+
from common_python_tasks.env import env_truthy
|
|
120
|
+
|
|
121
|
+
return env_truthy("RELEASE_UPDATE_CHANGELOG")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _confirm_release_with_uncommitted_changes(dirty_files: list[Path]) -> bool:
|
|
125
|
+
preview = ", ".join(str(path) for path in dirty_files[:5])
|
|
126
|
+
if len(dirty_files) > 5:
|
|
127
|
+
preview = f"{preview}, ... and {len(dirty_files) - 5} more"
|
|
128
|
+
|
|
129
|
+
LOGGER.warning("Repository has uncommitted changes: %s", preview)
|
|
130
|
+
try:
|
|
131
|
+
response = input("Proceed with release anyway? [y/N]: ").strip().lower()
|
|
132
|
+
except (EOFError, OSError):
|
|
133
|
+
return False
|
|
134
|
+
return response in {"y", "yes"}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _resolve_allow_dirty_release(dirty_files: list[Path]) -> bool:
|
|
138
|
+
from common_python_tasks.utils import fatal
|
|
139
|
+
|
|
140
|
+
if not dirty_files:
|
|
141
|
+
return False
|
|
142
|
+
|
|
143
|
+
if os.getenv(NO_PROMPT_ENV_VAR) == "1":
|
|
144
|
+
LOGGER.warning(
|
|
145
|
+
"Proceeding with release despite uncommitted changes because %s=1",
|
|
146
|
+
NO_PROMPT_ENV_VAR,
|
|
147
|
+
)
|
|
148
|
+
return True
|
|
149
|
+
|
|
150
|
+
if _confirm_release_with_uncommitted_changes(dirty_files):
|
|
151
|
+
return True
|
|
152
|
+
|
|
153
|
+
fatal("Aborted due to uncommitted changes.")
|
|
154
|
+
return False
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _update_release_changelog(release_tag: str, dry_run: bool = False) -> None:
|
|
158
|
+
from common_python_tasks.utils import prepend_changelog, run_command
|
|
159
|
+
|
|
160
|
+
changelog_path = Path("CHANGELOG.md")
|
|
161
|
+
if dry_run:
|
|
162
|
+
run_command(
|
|
163
|
+
[
|
|
164
|
+
"git-cliff",
|
|
165
|
+
"--unreleased",
|
|
166
|
+
"--tag",
|
|
167
|
+
release_tag,
|
|
168
|
+
"--prepend",
|
|
169
|
+
changelog_path,
|
|
170
|
+
],
|
|
171
|
+
dry_run=True,
|
|
172
|
+
)
|
|
173
|
+
run_command(["git", "add", changelog_path], dry_run=True)
|
|
174
|
+
run_command(
|
|
175
|
+
[
|
|
176
|
+
"git",
|
|
177
|
+
"commit",
|
|
178
|
+
"-m",
|
|
179
|
+
f"chore(release): update changelog for {release_tag}",
|
|
180
|
+
],
|
|
181
|
+
dry_run=True,
|
|
182
|
+
)
|
|
183
|
+
return
|
|
184
|
+
|
|
185
|
+
prepend_changelog(release_tag, changelog_path)
|
|
186
|
+
|
|
187
|
+
status = run_command(
|
|
188
|
+
["git", "status", "--porcelain", "--", changelog_path],
|
|
189
|
+
capture_output=True,
|
|
190
|
+
)
|
|
191
|
+
changed_files = (
|
|
192
|
+
status.stdout.strip()
|
|
193
|
+
if status is not None and isinstance(status.stdout, str)
|
|
194
|
+
else ""
|
|
195
|
+
)
|
|
196
|
+
if not changed_files:
|
|
197
|
+
LOGGER.info("CHANGELOG.md already matches release %s", release_tag)
|
|
198
|
+
return
|
|
199
|
+
|
|
200
|
+
run_command(["git", "add", changelog_path])
|
|
201
|
+
run_command(
|
|
202
|
+
["git", "commit", "-m", f"chore(release): update changelog for {release_tag}"]
|
|
203
|
+
)
|
|
204
|
+
|
|
49
205
|
|
|
50
206
|
def _parse_build_args(
|
|
51
207
|
cli_build_args: list[str] | None,
|
|
@@ -73,7 +229,7 @@ def _parse_build_args(
|
|
|
73
229
|
return parsed_build_args or None
|
|
74
230
|
|
|
75
231
|
|
|
76
|
-
@tasks.script(task_name="_black", tags=["format", "internal"])
|
|
232
|
+
@tasks.script(task_name="_black", tags=["format", "internal", "common"])
|
|
77
233
|
def black() -> None:
|
|
78
234
|
"""Run black formatting."""
|
|
79
235
|
from common_python_tasks.utils import require_package, run_command
|
|
@@ -82,7 +238,7 @@ def black() -> None:
|
|
|
82
238
|
run_command(["black", "--quiet", "."])
|
|
83
239
|
|
|
84
240
|
|
|
85
|
-
@tasks.script(task_name="_isort", tags=["format", "internal"])
|
|
241
|
+
@tasks.script(task_name="_isort", tags=["format", "internal", "common"])
|
|
86
242
|
def isort() -> None:
|
|
87
243
|
"""Run isort formatting."""
|
|
88
244
|
from common_python_tasks.utils import get_config_path, require_package, run_command
|
|
@@ -100,13 +256,13 @@ def isort() -> None:
|
|
|
100
256
|
"isort",
|
|
101
257
|
"--quiet",
|
|
102
258
|
".",
|
|
103
|
-
"--settings-path",
|
|
259
|
+
"--settings-path" if isort_config_path else None,
|
|
104
260
|
isort_config_path,
|
|
105
261
|
]
|
|
106
262
|
)
|
|
107
263
|
|
|
108
264
|
|
|
109
|
-
@tasks.script(task_name="_autoflake", tags=["format", "internal"])
|
|
265
|
+
@tasks.script(task_name="_autoflake", tags=["format", "internal", "common"])
|
|
110
266
|
def autoflake() -> None:
|
|
111
267
|
"""Run autoflake to remove unused imports."""
|
|
112
268
|
from common_python_tasks.utils import require_package, run_command
|
|
@@ -124,7 +280,7 @@ def autoflake() -> None:
|
|
|
124
280
|
)
|
|
125
281
|
|
|
126
282
|
|
|
127
|
-
@tasks.script(task_name="_black_check", tags=["lint", "internal"])
|
|
283
|
+
@tasks.script(task_name="_black_check", tags=["lint", "internal", "common"])
|
|
128
284
|
def black_check() -> None:
|
|
129
285
|
"""Run black in check mode."""
|
|
130
286
|
from common_python_tasks.utils import require_package, run_command
|
|
@@ -133,7 +289,7 @@ def black_check() -> None:
|
|
|
133
289
|
run_command(["black", "--quiet", "--diff", Path("."), "--check"])
|
|
134
290
|
|
|
135
291
|
|
|
136
|
-
@tasks.script(task_name="_isort_check", tags=["lint"])
|
|
292
|
+
@tasks.script(task_name="_isort_check", tags=["lint", "common"])
|
|
137
293
|
def isort_check() -> None:
|
|
138
294
|
"""Run isort linting."""
|
|
139
295
|
from common_python_tasks.utils import get_config_path, require_package, run_command
|
|
@@ -152,13 +308,13 @@ def isort_check() -> None:
|
|
|
152
308
|
"--quiet",
|
|
153
309
|
".",
|
|
154
310
|
"--check-only",
|
|
155
|
-
"--settings-path",
|
|
311
|
+
"--settings-path" if isort_config_path else None,
|
|
156
312
|
isort_config_path,
|
|
157
313
|
]
|
|
158
314
|
)
|
|
159
315
|
|
|
160
316
|
|
|
161
|
-
@tasks.script(task_name="_autoflake_check", tags=["lint", "internal"])
|
|
317
|
+
@tasks.script(task_name="_autoflake_check", tags=["lint", "internal", "common"])
|
|
162
318
|
def autoflake_check() -> None:
|
|
163
319
|
"""Run autoflake in check mode."""
|
|
164
320
|
from common_python_tasks.utils import require_package, run_command
|
|
@@ -176,7 +332,7 @@ def autoflake_check() -> None:
|
|
|
176
332
|
)
|
|
177
333
|
|
|
178
334
|
|
|
179
|
-
@tasks.script(task_name="_flake8_check", tags=["lint"])
|
|
335
|
+
@tasks.script(task_name="_flake8_check", tags=["lint", "common"])
|
|
180
336
|
def flake8_check() -> None:
|
|
181
337
|
"""Run flake8 linting."""
|
|
182
338
|
from common_python_tasks.utils import get_config_path, require_package, run_command
|
|
@@ -185,10 +341,17 @@ def flake8_check() -> None:
|
|
|
185
341
|
|
|
186
342
|
flake8_config_path = get_config_path("FLAKE8_CONFIG", ".flake8", ".flake8")
|
|
187
343
|
|
|
188
|
-
run_command(
|
|
344
|
+
run_command(
|
|
345
|
+
[
|
|
346
|
+
"flake8",
|
|
347
|
+
Path("."),
|
|
348
|
+
"--config" if flake8_config_path else None,
|
|
349
|
+
flake8_config_path,
|
|
350
|
+
]
|
|
351
|
+
)
|
|
189
352
|
|
|
190
353
|
|
|
191
|
-
@tasks.script(tags=["test"])
|
|
354
|
+
@tasks.script(tags=["test", "common"])
|
|
192
355
|
def test(quiet: bool = False) -> None:
|
|
193
356
|
"""Run the test suite with coverage (if `pytest-cov` is installed).
|
|
194
357
|
|
|
@@ -250,7 +413,7 @@ def test(quiet: bool = False) -> None:
|
|
|
250
413
|
sys.exit(5)
|
|
251
414
|
|
|
252
415
|
|
|
253
|
-
@tasks.script(task_name="clean", tags=["clean"])
|
|
416
|
+
@tasks.script(task_name="clean", tags=["clean", "common"])
|
|
254
417
|
def clean(dist_only: bool = False) -> None:
|
|
255
418
|
"""Clean up temporary files and directories.
|
|
256
419
|
|
|
@@ -274,7 +437,7 @@ def clean(dist_only: bool = False) -> None:
|
|
|
274
437
|
item.unlink(missing_ok=True)
|
|
275
438
|
|
|
276
439
|
|
|
277
|
-
@tasks.script(task_name="format", tags=["format"])
|
|
440
|
+
@tasks.script(task_name="format", tags=["format", "common"])
|
|
278
441
|
def format_all() -> None:
|
|
279
442
|
"""Format Python code with autoflake, black, and isort."""
|
|
280
443
|
from common_python_tasks.utils import run_available_tools
|
|
@@ -289,7 +452,7 @@ def format_all() -> None:
|
|
|
289
452
|
)
|
|
290
453
|
|
|
291
454
|
|
|
292
|
-
@tasks.script(task_name="lint", tags=["lint"])
|
|
455
|
+
@tasks.script(task_name="lint", tags=["lint", "common"])
|
|
293
456
|
def lint_all() -> None:
|
|
294
457
|
"""Lint Python code with autoflake, black, isort, and flake8."""
|
|
295
458
|
from common_python_tasks.utils import run_available_tools
|
|
@@ -676,7 +839,7 @@ def push_image(debug: bool = False) -> None:
|
|
|
676
839
|
run_command(["docker", "push", full_tag])
|
|
677
840
|
|
|
678
841
|
|
|
679
|
-
@tasks.script(task_name="publish-package", tags=["packaging"])
|
|
842
|
+
@tasks.script(task_name="publish-package", tags=["packaging", "common"])
|
|
680
843
|
def publish_package(build_first: bool = True) -> None:
|
|
681
844
|
"""Publish the package to the PyPI server.
|
|
682
845
|
|
|
@@ -690,7 +853,9 @@ def publish_package(build_first: bool = True) -> None:
|
|
|
690
853
|
run_command(["poetry", "publish"])
|
|
691
854
|
|
|
692
855
|
|
|
693
|
-
@tasks.script(
|
|
856
|
+
@tasks.script(
|
|
857
|
+
task_name="publish-github-release", tags=["packaging", "release", "common"]
|
|
858
|
+
)
|
|
694
859
|
def publish_github_release(
|
|
695
860
|
tag_name: str | None = None,
|
|
696
861
|
*,
|
|
@@ -733,7 +898,7 @@ def publish_github_release(
|
|
|
733
898
|
)
|
|
734
899
|
|
|
735
900
|
|
|
736
|
-
@tasks.script(task_name="build-package", tags=["packaging", "build"])
|
|
901
|
+
@tasks.script(task_name="build-package", tags=["packaging", "build", "common"])
|
|
737
902
|
def build_package(wheel_only: bool = False, clean_dist: bool = False) -> None:
|
|
738
903
|
"""Build the package (wheel and sdist)."""
|
|
739
904
|
from common_python_tasks.utils import run_command
|
|
@@ -748,13 +913,14 @@ def build_package(wheel_only: bool = False, clean_dist: bool = False) -> None:
|
|
|
748
913
|
run_command(command)
|
|
749
914
|
|
|
750
915
|
|
|
751
|
-
@tasks.script(tags=["packaging"])
|
|
916
|
+
@tasks.script(tags=["packaging", "common"])
|
|
752
917
|
def bump_version(
|
|
753
918
|
component: str = "auto",
|
|
754
919
|
*,
|
|
755
920
|
stage: str | None = None,
|
|
756
921
|
dry_run: bool = False,
|
|
757
|
-
|
|
922
|
+
allow_dirty: bool = False,
|
|
923
|
+
) -> str:
|
|
758
924
|
"""Bump the project version.
|
|
759
925
|
|
|
760
926
|
Args:
|
|
@@ -762,78 +928,42 @@ def bump_version(
|
|
|
762
928
|
`auto` to infer the bump from git history using git-cliff.
|
|
763
929
|
stage: Optional pre-release stage to apply: `alpha`, `beta`, or `rc`.
|
|
764
930
|
dry_run: If `True`, print what would happen without making changes.
|
|
765
|
-
|
|
766
|
-
from typing import Literal
|
|
931
|
+
allow_dirty: If `True`, allow version bumping with uncommitted changes.
|
|
767
932
|
|
|
933
|
+
Returns:
|
|
934
|
+
The new version string that was/would be set.
|
|
935
|
+
"""
|
|
768
936
|
from common_python_tasks.git import (
|
|
937
|
+
compute_next_release_version,
|
|
769
938
|
ensure_on_default_branch,
|
|
770
939
|
get_dirty_files,
|
|
771
|
-
infer_bump_component_from_git_cliff,
|
|
772
940
|
)
|
|
773
|
-
from common_python_tasks.project import get_project_version_from_poetry
|
|
774
941
|
from common_python_tasks.utils import (
|
|
775
942
|
fatal,
|
|
776
943
|
log_dry_run,
|
|
777
944
|
run_command,
|
|
778
945
|
)
|
|
779
|
-
from dunamai import Version
|
|
780
|
-
|
|
781
|
-
component = component.lower()
|
|
782
|
-
stage = stage.lower() if stage is not None else None
|
|
783
946
|
|
|
784
947
|
ensure_on_default_branch()
|
|
785
948
|
|
|
786
|
-
|
|
787
|
-
current_version_text: str | None = None
|
|
788
|
-
if component == "auto":
|
|
789
|
-
import re
|
|
790
|
-
|
|
791
|
-
current_version_text = get_project_version_from_poetry()
|
|
792
|
-
component = infer_bump_component_from_git_cliff()
|
|
793
|
-
current_version = Version.parse(current_version_text)
|
|
794
|
-
if re.match(r"^0\.", str(current_version.base)):
|
|
795
|
-
LOGGER.info(
|
|
796
|
-
"Current version %s is pre-production; forcing patch bump.",
|
|
797
|
-
current_version_text,
|
|
798
|
-
)
|
|
799
|
-
component = "patch"
|
|
800
|
-
if component not in valid_components:
|
|
801
|
-
fatal(
|
|
802
|
-
f'Invalid component "{component}". Must be one of: {set(valid_components.keys())} or "auto"'
|
|
803
|
-
)
|
|
804
|
-
bump_index: Literal[0, 1, 2] = valid_components[component]
|
|
805
|
-
|
|
806
|
-
valid_stages = {"alpha", "a", "beta", "b", "rc"}
|
|
807
|
-
if stage is not None and stage not in valid_stages:
|
|
808
|
-
fatal(
|
|
809
|
-
f'Invalid stage "{stage}". Must be one of: {valid_stages} or empty for none.'
|
|
810
|
-
)
|
|
811
|
-
|
|
812
|
-
if get_dirty_files():
|
|
949
|
+
if get_dirty_files() and not allow_dirty:
|
|
813
950
|
fatal(
|
|
814
951
|
"Repository has uncommitted changes. "
|
|
815
952
|
"Please commit or stash changes before bumping version."
|
|
816
953
|
)
|
|
817
954
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
)
|
|
821
|
-
|
|
822
|
-
if stage is not None:
|
|
823
|
-
bumped.stage = {"a": "alpha", "b": "beta"}.get(stage, stage)
|
|
824
|
-
bumped.revision = 1
|
|
825
|
-
|
|
826
|
-
new_version = bumped.serialize()
|
|
955
|
+
result = compute_next_release_version(component, stage)
|
|
956
|
+
new_version = result.version
|
|
827
957
|
|
|
828
958
|
if dry_run:
|
|
829
959
|
log_dry_run("Would bump version to %s", new_version)
|
|
830
960
|
else:
|
|
831
|
-
new_tag = f"v{new_version}"
|
|
832
961
|
LOGGER.info("Bumping version to %s", new_version)
|
|
833
|
-
run_command(["git", "tag",
|
|
962
|
+
run_command(["git", "tag", f"v{new_version}"])
|
|
963
|
+
return new_version
|
|
834
964
|
|
|
835
965
|
|
|
836
|
-
@tasks.script(tags=["packaging", "release"])
|
|
966
|
+
@tasks.script(tags=["packaging", "release", "common"])
|
|
837
967
|
def changelog() -> None:
|
|
838
968
|
"""Print the changelog for the current version based on git history and git-cliff."""
|
|
839
969
|
from common_python_tasks.utils import changelog as _changelog
|
|
@@ -841,12 +971,18 @@ def changelog() -> None:
|
|
|
841
971
|
print(_changelog())
|
|
842
972
|
|
|
843
973
|
|
|
844
|
-
|
|
845
|
-
|
|
974
|
+
def _normalize_release_stage(stage: str | None) -> str | None:
|
|
975
|
+
if stage is not None and stage.lower() == "none":
|
|
976
|
+
return None
|
|
977
|
+
return stage
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
def _run_release_flow(
|
|
846
981
|
component: str = "patch",
|
|
847
982
|
*,
|
|
848
983
|
stage: str | None = None,
|
|
849
984
|
dry_run: bool = False,
|
|
985
|
+
include_containers: bool,
|
|
850
986
|
debug: bool = False,
|
|
851
987
|
no_cache: bool = False,
|
|
852
988
|
plain: bool = False,
|
|
@@ -858,68 +994,47 @@ def release(
|
|
|
858
994
|
pre_script: str | None = None,
|
|
859
995
|
post_script: str | None = None,
|
|
860
996
|
) -> None:
|
|
861
|
-
"""Run a full release flow for package (and containers when included).
|
|
862
|
-
|
|
863
|
-
Args:
|
|
864
|
-
component: The version component to bump: `major`, `minor`, or `patch`.
|
|
865
|
-
stage: Optional pre-release stage to apply: `alpha`, `beta`, or `rc`.
|
|
866
|
-
dry_run: If `True`, only perform a dry-run version bump.
|
|
867
|
-
debug: Build/push debug container image tags when releasing containers.
|
|
868
|
-
no_cache: Do not use cache when building container images.
|
|
869
|
-
plain: Do not pretty-print container build output.
|
|
870
|
-
single_arch: Build container image for a single architecture.
|
|
871
|
-
build_args: Additional build arguments for the Docker build as repeated
|
|
872
|
-
`KEY=VALUE` values.
|
|
873
|
-
container_env: Inline container environment variables as repeated
|
|
874
|
-
`KEY=VALUE` values.
|
|
875
|
-
container_envfile: Repeated list of container environment files.
|
|
876
|
-
assets: Optional repeated list of release asset patterns or paths.
|
|
877
|
-
pre_script: Optional shell command to run before the release steps.
|
|
878
|
-
post_script: Optional shell command to run after the release completes.
|
|
879
|
-
"""
|
|
880
|
-
from common_python_tasks.docker import build_image
|
|
881
997
|
from common_python_tasks.git import (
|
|
882
998
|
build_release_hook_environment,
|
|
883
999
|
ensure_on_default_branch,
|
|
884
|
-
|
|
885
|
-
from common_python_tasks.github import (
|
|
886
|
-
get_github_release_asset_paths,
|
|
887
|
-
)
|
|
888
|
-
from common_python_tasks.github import (
|
|
889
|
-
publish_github_release as publish_github_release_helper,
|
|
890
|
-
)
|
|
891
|
-
from common_python_tasks.project import (
|
|
892
|
-
get_release_tag_from_poetry_version,
|
|
893
|
-
is_task_tag_included,
|
|
1000
|
+
get_dirty_files,
|
|
894
1001
|
)
|
|
895
1002
|
from common_python_tasks.utils import (
|
|
896
1003
|
log_dry_run,
|
|
897
1004
|
run_command,
|
|
898
1005
|
)
|
|
899
1006
|
|
|
900
|
-
normalized_stage = stage
|
|
901
|
-
if normalized_stage is not None and normalized_stage.lower() == "none":
|
|
902
|
-
normalized_stage = None
|
|
903
|
-
|
|
1007
|
+
normalized_stage = _normalize_release_stage(stage)
|
|
904
1008
|
pre_script = pre_script or os.getenv("RELEASE_PRE_SCRIPT")
|
|
905
1009
|
post_script = post_script or os.getenv("RELEASE_POST_SCRIPT")
|
|
906
1010
|
|
|
907
1011
|
ensure_on_default_branch()
|
|
1012
|
+
allow_dirty = _resolve_allow_dirty_release(get_dirty_files())
|
|
908
1013
|
hook_env = build_release_hook_environment(component, normalized_stage, dry_run)
|
|
1014
|
+
if allow_dirty:
|
|
1015
|
+
hook_env[NO_PROMPT_ENV_VAR] = "1"
|
|
909
1016
|
if pre_script:
|
|
910
|
-
run_command(["sh", "-lc", pre_script], env=hook_env, dry_run=
|
|
1017
|
+
run_command(["sh", "-lc", pre_script], env=hook_env, dry_run=False)
|
|
911
1018
|
|
|
912
1019
|
if dry_run:
|
|
913
1020
|
log_dry_run("Would clean generated artifacts before release")
|
|
914
1021
|
else:
|
|
915
1022
|
clean()
|
|
916
1023
|
|
|
917
|
-
|
|
1024
|
+
if _should_update_release_changelog():
|
|
1025
|
+
_update_release_changelog(hook_env["RELEASE_TAG"], dry_run=dry_run)
|
|
1026
|
+
|
|
1027
|
+
bump_version(
|
|
1028
|
+
component=hook_env["RELEASE_COMPONENT"],
|
|
1029
|
+
stage=normalized_stage,
|
|
1030
|
+
dry_run=dry_run,
|
|
1031
|
+
allow_dirty=allow_dirty,
|
|
1032
|
+
)
|
|
918
1033
|
if dry_run:
|
|
919
1034
|
log_dry_run("Would push tags to origin")
|
|
920
1035
|
log_dry_run("Would build package with clean_dist=True")
|
|
921
1036
|
log_dry_run("Would publish package with build_first=False")
|
|
922
|
-
if
|
|
1037
|
+
if include_containers:
|
|
923
1038
|
log_dry_run(
|
|
924
1039
|
"Would build container image with debug=%s no_cache=%s plain=%s single_arch=%s",
|
|
925
1040
|
debug,
|
|
@@ -928,23 +1043,19 @@ def release(
|
|
|
928
1043
|
single_arch,
|
|
929
1044
|
)
|
|
930
1045
|
log_dry_run("Would push container image with debug=%s", debug)
|
|
931
|
-
else:
|
|
932
|
-
log_dry_run("Containers tag is not included; would skip image build/push")
|
|
933
|
-
release_tag = get_release_tag_from_poetry_version()
|
|
934
|
-
asset_paths = get_github_release_asset_paths(assets)
|
|
935
1046
|
log_dry_run(
|
|
936
|
-
"Would publish GitHub Release %s with assets
|
|
937
|
-
release_tag,
|
|
938
|
-
asset_paths,
|
|
1047
|
+
"Would publish GitHub Release %s with built assets", hook_env["RELEASE_TAG"]
|
|
939
1048
|
)
|
|
940
1049
|
if post_script:
|
|
941
|
-
run_command(["sh", "-lc", post_script], env=hook_env, dry_run=
|
|
1050
|
+
run_command(["sh", "-lc", post_script], env=hook_env, dry_run=False)
|
|
942
1051
|
return
|
|
943
1052
|
|
|
944
1053
|
build_package(clean_dist=True)
|
|
945
1054
|
publish_package(build_first=False)
|
|
946
1055
|
|
|
947
|
-
if
|
|
1056
|
+
if include_containers:
|
|
1057
|
+
from common_python_tasks.docker import build_image
|
|
1058
|
+
|
|
948
1059
|
build_image(
|
|
949
1060
|
debug=debug,
|
|
950
1061
|
no_cache=no_cache,
|
|
@@ -956,29 +1067,111 @@ def release(
|
|
|
956
1067
|
)
|
|
957
1068
|
push_image(debug=debug)
|
|
958
1069
|
|
|
959
|
-
|
|
960
|
-
asset_paths = get_github_release_asset_paths(assets)
|
|
961
|
-
|
|
962
|
-
run_command(["git", "push", "origin", release_tag])
|
|
1070
|
+
run_command(["git", "push", "origin", hook_env["RELEASE_TAG"]])
|
|
963
1071
|
try:
|
|
964
|
-
|
|
965
|
-
|
|
1072
|
+
publish_github_release(
|
|
1073
|
+
hook_env["RELEASE_TAG"],
|
|
966
1074
|
prerelease=normalized_stage is not None,
|
|
967
|
-
assets=
|
|
1075
|
+
assets=assets,
|
|
968
1076
|
)
|
|
969
1077
|
except SystemExit:
|
|
970
1078
|
LOGGER.warning(
|
|
971
1079
|
"GitHub Release publication failed after pushing %s; attempting to remove remote tag",
|
|
972
|
-
|
|
1080
|
+
hook_env["RELEASE_TAG"],
|
|
973
1081
|
)
|
|
974
1082
|
run_command(
|
|
975
|
-
["git", "push", "origin", "--delete",
|
|
1083
|
+
["git", "push", "origin", "--delete", hook_env["RELEASE_TAG"]],
|
|
976
1084
|
acceptable_returncodes={0, 1},
|
|
977
1085
|
)
|
|
978
1086
|
raise
|
|
979
1087
|
|
|
980
1088
|
if post_script:
|
|
981
|
-
run_command(["sh", "-lc", post_script], env=hook_env, dry_run=
|
|
1089
|
+
run_command(["sh", "-lc", post_script], env=hook_env, dry_run=False)
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
@tasks.script(task_name="release", tags=["packaging", "release", "containers"])
|
|
1093
|
+
def release(
|
|
1094
|
+
component: str = "patch",
|
|
1095
|
+
*,
|
|
1096
|
+
stage: str | None = None,
|
|
1097
|
+
dry_run: bool = False,
|
|
1098
|
+
debug: bool = False,
|
|
1099
|
+
no_cache: bool = False,
|
|
1100
|
+
plain: bool = False,
|
|
1101
|
+
single_arch: bool = False,
|
|
1102
|
+
build_args: list[str] | None = None,
|
|
1103
|
+
container_env: list[str] | None = None,
|
|
1104
|
+
container_envfile: list[str] | None = None,
|
|
1105
|
+
assets: list[str] | None = None,
|
|
1106
|
+
pre_script: str | None = None,
|
|
1107
|
+
post_script: str | None = None,
|
|
1108
|
+
) -> None:
|
|
1109
|
+
"""Run a full release flow for package and containers.
|
|
1110
|
+
|
|
1111
|
+
Args:
|
|
1112
|
+
component: The version component to bump: `major`, `minor`, or `patch`.
|
|
1113
|
+
stage: Optional pre-release stage to apply: `alpha`, `beta`, or `rc`.
|
|
1114
|
+
dry_run: If `True`, only perform a dry-run version bump.
|
|
1115
|
+
debug: Build/push debug container image tags when releasing containers.
|
|
1116
|
+
no_cache: Do not use cache when building container images.
|
|
1117
|
+
plain: Do not pretty-print container build output.
|
|
1118
|
+
single_arch: Build container image for a single architecture.
|
|
1119
|
+
build_args: Additional build arguments for the Docker build as repeated
|
|
1120
|
+
`KEY=VALUE` values.
|
|
1121
|
+
container_env: Inline container environment variables as repeated
|
|
1122
|
+
`KEY=VALUE` values.
|
|
1123
|
+
container_envfile: Repeated list of container environment files.
|
|
1124
|
+
assets: Optional repeated list of release asset patterns or paths.
|
|
1125
|
+
pre_script: Optional shell command to run before the release steps.
|
|
1126
|
+
post_script: Optional shell command to run after the release completes.
|
|
1127
|
+
"""
|
|
1128
|
+
_run_release_flow(
|
|
1129
|
+
component=component,
|
|
1130
|
+
stage=stage,
|
|
1131
|
+
dry_run=dry_run,
|
|
1132
|
+
include_containers=True,
|
|
1133
|
+
debug=debug,
|
|
1134
|
+
no_cache=no_cache,
|
|
1135
|
+
plain=plain,
|
|
1136
|
+
single_arch=single_arch,
|
|
1137
|
+
build_args=build_args,
|
|
1138
|
+
container_env=container_env,
|
|
1139
|
+
container_envfile=container_envfile,
|
|
1140
|
+
assets=assets,
|
|
1141
|
+
pre_script=pre_script,
|
|
1142
|
+
post_script=post_script,
|
|
1143
|
+
)
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
@tasks.script(task_name="release", tags=["packaging", "release", "common"])
|
|
1147
|
+
def release_without_containers(
|
|
1148
|
+
component: str = "patch",
|
|
1149
|
+
*,
|
|
1150
|
+
stage: str | None = None,
|
|
1151
|
+
dry_run: bool = False,
|
|
1152
|
+
assets: list[str] | None = None,
|
|
1153
|
+
pre_script: str | None = None,
|
|
1154
|
+
post_script: str | None = None,
|
|
1155
|
+
) -> None:
|
|
1156
|
+
"""Run a full release flow for package artifacts without container publishing.
|
|
1157
|
+
|
|
1158
|
+
Args:
|
|
1159
|
+
component: The version component to bump: `major`, `minor`, or `patch`.
|
|
1160
|
+
stage: Optional pre-release stage to apply: `alpha`, `beta`, or `rc`.
|
|
1161
|
+
dry_run: If `True`, only perform a dry-run version bump.
|
|
1162
|
+
assets: Optional repeated list of release asset patterns or paths.
|
|
1163
|
+
pre_script: Optional shell command to run before the release steps.
|
|
1164
|
+
post_script: Optional shell command to run after the release completes.
|
|
1165
|
+
"""
|
|
1166
|
+
_run_release_flow(
|
|
1167
|
+
component=component,
|
|
1168
|
+
stage=stage,
|
|
1169
|
+
dry_run=dry_run,
|
|
1170
|
+
include_containers=False,
|
|
1171
|
+
assets=assets,
|
|
1172
|
+
pre_script=pre_script,
|
|
1173
|
+
post_script=post_script,
|
|
1174
|
+
)
|
|
982
1175
|
|
|
983
1176
|
|
|
984
1177
|
@tasks.script(
|
|
@@ -1021,7 +1214,7 @@ def build_with_containers(
|
|
|
1021
1214
|
)
|
|
1022
1215
|
|
|
1023
1216
|
|
|
1024
|
-
@tasks.script(task_name="build", tags=["packaging"])
|
|
1217
|
+
@tasks.script(task_name="build", tags=["packaging", "common"])
|
|
1025
1218
|
def build_without_containers() -> None:
|
|
1026
1219
|
"""Build the project."""
|
|
1027
1220
|
from common_python_tasks.docker import build
|
|
@@ -1305,9 +1498,6 @@ def container_shell(
|
|
|
1305
1498
|
) -> None:
|
|
1306
1499
|
"""Run the debug image with an interactive shell.
|
|
1307
1500
|
|
|
1308
|
-
Behavior when `tag` is `None` mirrors `run_container`:
|
|
1309
|
-
- select the most-recently-built tag for the project's image (do not build).
|
|
1310
|
-
|
|
1311
1501
|
Args:
|
|
1312
1502
|
tag: Image tag to use. If `None`, use the most-recently-built tag.
|
|
1313
1503
|
shell: Preferred shell name or path. If `None`, use the first available from
|