1
1
#!/usr/bin/env python
2
2
3
- # WARNING: DO NOT EDIT!
4
- #
5
- # This file was generated by plugin_template, and is managed by it. Please use
6
- # './plugin-template --github pulp_npm' to update this file.
7
- #
8
- # For more info visit https://github.com/pulp/plugin_template
9
-
10
3
import argparse
11
4
import re
12
5
import os
6
+ import tomllib
13
7
import yaml
8
+ from pathlib import Path
14
9
from tempfile import TemporaryDirectory
15
10
from packaging .version import Version
16
11
from git import Repo
17
12
18
- UPSTREAM_REMOTE = "https://github.com/pulp/pulp_npm.git"
19
- DEFAULT_BRANCH = "main"
20
13
RELEASE_BRANCH_REGEX = r"^([0-9]+)\.([0-9]+)$"
21
14
Y_CHANGELOG_EXTS = [".feature" , ".removal" , ".deprecation" ]
22
15
Z_CHANGELOG_EXTS = [".bugfix" , ".doc" , ".misc" ]
23
16
24
17
25
- def main ():
18
+ def options ():
26
19
"""Check which branches need a release."""
27
20
parser = argparse .ArgumentParser ()
28
21
parser .add_argument (
@@ -32,17 +25,60 @@ def main():
32
25
"'supported'. Defaults to 'supported', see `supported_release_branches` in "
33
26
"`plugin_template.yml`." ,
34
27
)
35
- opts = parser .parse_args ()
28
+ return parser .parse_args ()
29
+
30
+
31
+ def template_config ():
32
+ # Assume this script lies in .ci/scripts
33
+ path = Path (__file__ ).absolute ().parent .parent .parent / "template_config.yml"
34
+ return yaml .safe_load (path .read_text ())
35
+
36
36
37
+ def current_version (repo , commitish ):
38
+ try :
39
+ pyproject_toml = tomllib .loads (repo .git .show (f"{ commitish } :pyproject.toml" ))
40
+ try :
41
+ current_version = pyproject_toml ["project" ]["version" ]
42
+ except Exception :
43
+ current_version = pyproject_toml ["tool" ]["bumpversion" ]["current_version" ]
44
+ except Exception :
45
+ current_version = repo .git .grep (
46
+ "current_version" , commitish , "--" , ".bumpversion.cfg"
47
+ ).split ("=" )[- 1 ]
48
+ return Version (current_version )
49
+
50
+
51
+ def check_pyproject_dependencies (repo , from_commit , to_commit ):
52
+ try :
53
+ old_pyproject = tomllib .load (repo .show ("{from_commit}:pyproject.toml" ))
54
+ old_dependencies = set (old_pyproject ["project" ]["dependencies" ])
55
+ new_pyproject = tomllib .load (repo .show ("{to_commit}:pyproject.toml" ))
56
+ new_dependencies = set (new_pyproject ["project" ]["dependencies" ])
57
+ if old_dependencies != new_dependencies :
58
+ return ["dependencies" ]
59
+ else :
60
+ return []
61
+ except Exception as e :
62
+ print (f"WARNING: Comparing the dependencies in pyproject.toml failed. ({ e } )" )
63
+ # Gathering more details failed.
64
+ return ["pyproject.toml changed somehow (PLEASE check if dependencies are affected)." ]
65
+
66
+
67
+ def main (options , template_config ):
37
68
with TemporaryDirectory () as d :
38
69
# Clone from upstream to ensure we have updated branches & main
70
+ GITHUB_ORG = template_config ["github_org" ]
71
+ PLUGIN_NAME = template_config ["plugin_name" ]
72
+ UPSTREAM_REMOTE = f"https://github.com/{ GITHUB_ORG } /{ PLUGIN_NAME } .git"
73
+ DEFAULT_BRANCH = template_config ["plugin_default_branch" ]
74
+
39
75
repo = Repo .clone_from (UPSTREAM_REMOTE , d , filter = "blob:none" )
40
76
heads = [h .split ("/" )[- 1 ] for h in repo .git .ls_remote ("--heads" ).split ("\n " )]
41
77
available_branches = [h for h in heads if re .search (RELEASE_BRANCH_REGEX , h )]
42
78
available_branches .sort (key = lambda ver : Version (ver ))
43
79
available_branches .append (DEFAULT_BRANCH )
44
80
45
- branches = opts .branches
81
+ branches = options .branches
46
82
if branches == "supported" :
47
83
with open (f"{ d } /template_config.yml" , mode = "r" ) as f :
48
84
tc = yaml .safe_load (f )
@@ -86,6 +122,11 @@ def main():
86
122
)
87
123
if req_txt_diff :
88
124
reasons .append ("requirements.txt" )
125
+ pyproject_diff = repo .git .diff (
126
+ f"{ last_tag } " , f"origin/{ branch } " , "--name-only" , "--" , "pyproject.toml"
127
+ )
128
+ if pyproject_diff :
129
+ reasons .extend (check_pyproject_dependencies (repo , last_tag , f"origin/{ branch } " ))
89
130
90
131
if reasons :
91
132
curr_version = Version (last_tag )
@@ -106,15 +147,10 @@ def main():
106
147
for change in changes .split ("\n " ):
107
148
_ , ext = os .path .splitext (change )
108
149
if ext in Y_CHANGELOG_EXTS :
109
- # We don't put Y release bumps in the commit message, check file instead
110
- # The 'current_version' is always the next version to release
111
- next_version = repo .git .grep (
112
- "current_version" , DEFAULT_BRANCH , "--" , ".bumpversion.cfg"
113
- ).split ("=" )[- 1 ]
114
- next_version = Version (next_version )
115
- print (
116
- f"A new Y-release is needed! New Version: { next_version .base_version } "
117
- )
150
+ # We don't put Y release bumps in the commit message, check file instead.
151
+ # The 'current_version' is always the dev of the next version to release.
152
+ next_version = current_version (repo , DEFAULT_BRANCH ).base_version
153
+ print (f"A new Y-release is needed! New Version: { next_version } " )
118
154
releases .append (next_version )
119
155
break
120
156
@@ -123,4 +159,4 @@ def main():
123
159
124
160
125
161
if __name__ == "__main__" :
126
- main ()
162
+ main (options (), template_config () )
0 commit comments