12
12
13
13
if TYPE_CHECKING :
14
14
from pathlib import Path
15
- from typing import Protocol
15
+ from typing import Protocol , Sequence
16
16
17
17
from click .testing import Result
18
18
@@ -24,40 +24,51 @@ class InitMirrorRepo4RebuildFn(Protocol):
24
24
def __call__ (
25
25
self ,
26
26
mirror_repo_dir : Path ,
27
- configuration_step : RepoActionConfigure ,
27
+ configuration_steps : Sequence [RepoActionConfigure ],
28
+ files_to_remove : Sequence [Path ],
28
29
) -> Path : ...
29
30
30
31
class RunPSReleaseFn (Protocol ):
31
32
def __call__ (
32
33
self ,
33
34
next_version_str : str ,
34
35
git_repo : Repo ,
36
+ config_toml_path : Path = ...,
35
37
) -> Result : ...
36
38
37
39
38
40
@pytest .fixture (scope = "session" )
39
41
def init_mirror_repo_for_rebuild (
40
42
build_repo_from_definition : BuildRepoFromDefinitionFn ,
41
- changelog_md_file : Path ,
42
- changelog_rst_file : Path ,
43
43
) -> InitMirrorRepo4RebuildFn :
44
44
def _init_mirror_repo_for_rebuild (
45
45
mirror_repo_dir : Path ,
46
- configuration_step : RepoActionConfigure ,
46
+ configuration_steps : Sequence [RepoActionConfigure ],
47
+ files_to_remove : Sequence [Path ],
47
48
) -> Path :
48
49
# Create the mirror repo directory
49
50
mirror_repo_dir .mkdir (exist_ok = True , parents = True )
50
51
51
52
# Initialize mirror repository
52
53
build_repo_from_definition (
53
54
dest_dir = mirror_repo_dir ,
54
- repo_construction_steps = [ configuration_step ] ,
55
+ repo_construction_steps = configuration_steps ,
55
56
)
56
57
57
58
with Repo (mirror_repo_dir ) as mirror_git_repo :
58
- # remove the default changelog files to enable Update Mode (new default of v10)
59
- mirror_git_repo .git .rm (str (changelog_md_file ), force = True )
60
- mirror_git_repo .git .rm (str (changelog_rst_file ), force = True )
59
+ for filepath in files_to_remove :
60
+ file = (
61
+ (mirror_git_repo .working_dir / filepath ).resolve ().absolute ()
62
+ if not filepath .is_absolute ()
63
+ else filepath
64
+ )
65
+ if (
66
+ not file .is_relative_to (mirror_git_repo .working_dir )
67
+ or not file .exists ()
68
+ ):
69
+ continue
70
+
71
+ mirror_git_repo .git .rm (str (file ), force = True )
61
72
62
73
return mirror_repo_dir
63
74
@@ -69,6 +80,7 @@ def run_psr_release(
69
80
run_cli : RunCliFn ,
70
81
changelog_rst_file : Path ,
71
82
update_pyproject_toml : UpdatePyprojectTomlFn ,
83
+ pyproject_toml_file : Path ,
72
84
) -> RunPSReleaseFn :
73
85
base_version_cmd = [MAIN_PROG_NAME , "--strict" , VERSION_SUBCMD ]
74
86
write_changelog_only_cmd = [
@@ -82,6 +94,7 @@ def run_psr_release(
82
94
def _run_psr_release (
83
95
next_version_str : str ,
84
96
git_repo : Repo ,
97
+ config_toml_path : Path = pyproject_toml_file ,
85
98
) -> Result :
86
99
version_n_buildmeta = next_version_str .split ("+" , maxsplit = 1 )
87
100
version_n_prerelease = version_n_buildmeta [0 ].split ("-" , maxsplit = 1 )
@@ -107,6 +120,7 @@ def _run_psr_release(
107
120
update_pyproject_toml (
108
121
"tool.semantic_release.changelog.default_templates.changelog_file" ,
109
122
str (changelog_rst_file ),
123
+ toml_file = config_toml_path ,
110
124
)
111
125
cli_cmd = [* write_changelog_only_cmd , * prerelease_args , * build_metadata_args ]
112
126
result = run_cli (cli_cmd [1 :], env = {Github .DEFAULT_ENV_TOKEN_NAME : "1234" })
@@ -116,7 +130,7 @@ def _run_psr_release(
116
130
git_repo .git .reset ("--mixed" , "HEAD" )
117
131
118
132
# Add the changelog file to the git index but reset the working directory
119
- git_repo .git .add (str (changelog_rst_file ))
133
+ git_repo .git .add (str (changelog_rst_file . resolve () ))
120
134
git_repo .git .checkout ("--" , "." )
121
135
122
136
# Actual run to release & write the MD changelog
0 commit comments