6
6
import shutil
7
7
from dateutil .relativedelta import relativedelta
8
8
9
- # Check that the `gh` command is in the path
10
9
def check_gh_command ():
10
+ """
11
+ Pretty much everything is processed from `gh`
12
+ Check that the `gh` command is in the path before anything else
13
+ """
11
14
if not shutil .which ('gh' ):
12
15
print ("Error: The `gh` command is not available in the PATH." )
13
16
print ("Please install the GitHub CLI (https://cli.github.com/) and try again." )
14
17
exit (1 )
15
18
16
- # humanize duration outputs
17
19
def duration_ago (dt ):
20
+ """
21
+ Humanize duration ouputs
22
+ """
18
23
delta = relativedelta (datetime .datetime .now (), dt )
19
24
if delta .years > 0 :
20
25
return f"{ delta .years } year{ 's' if delta .years > 1 else '' } ago"
@@ -30,16 +35,29 @@ def duration_ago(dt):
30
35
return "just now"
31
36
32
37
def parse_version (version ):
33
- # version pattern
38
+ """
39
+ Parse version assuming it is in the form of v1.2.3
40
+ """
34
41
pattern = r"v(\d+)\.(\d+)\.(\d+)"
35
42
match = re .match (pattern , version )
36
43
if match :
37
44
major , minor , patch = map (int , match .groups ())
38
45
return (major , minor , patch )
39
46
40
- # Calculate the end of life date for a minor release version
41
- # according to : https://kubernetes-csi.github.io/docs/project-policies.html#support
42
47
def end_of_life_grouped_versions (versions ):
48
+ """
49
+ Calculate the end of life date for a minor release version according to : https://kubernetes-csi.github.io/docs/project-policies.html#support
50
+
51
+ The input is an array of tuples of:
52
+ * grouped versions (e.g. 1.0, 1.1)
53
+ * array of that contains all versions and their release date (e.g. 1.0.0, 01-01-2013)
54
+
55
+ versions structure example :
56
+ [((3, 5), [('v3.5.0', datetime.datetime(2023, 4, 27, 22, 28, 6))]),
57
+ ((3, 4),
58
+ [('v3.4.1', datetime.datetime(2023, 4, 5, 17, 41, 15)),
59
+ ('v3.4.0', datetime.datetime(2022, 12, 27, 23, 43, 41))])]
60
+ """
43
61
supported_versions = []
44
62
# Prepare dates for later calculation
45
63
now = datetime .datetime .now ()
@@ -48,14 +66,9 @@ def end_of_life_grouped_versions(versions):
48
66
49
67
# get the newer versions on top
50
68
sorted_versions_list = sorted (versions .items (), key = lambda x : x [0 ], reverse = True )
51
- # structure example :
52
- # [((3, 5), [('v3.5.0', datetime.datetime(2023, 4, 27, 22, 28, 6))]),
53
- # ((3, 4),
54
- # [('v3.4.1', datetime.datetime(2023, 4, 5, 17, 41, 15)),
55
- # ('v3.4.0', datetime.datetime(2022, 12, 27, 23, 43, 41))])]
56
- latest = sorted_versions_list .pop (0 )
57
69
58
70
# the latest version is always supported no matter the release date
71
+ latest = sorted_versions_list .pop (0 )
59
72
supported_versions .append (latest [1 ][- 1 ])
60
73
61
74
for v in sorted_versions_list :
@@ -70,12 +83,21 @@ def end_of_life_grouped_versions(versions):
70
83
return supported_versions
71
84
72
85
def get_release_docker_image (repo , version ):
86
+ """
87
+ Extract docker image name from the relase page documentation
88
+ """
73
89
output = subprocess .check_output (['gh' , 'release' , '-R' , repo , 'view' , version ], text = True )
74
- match = re .search (r"`docker pull (.*)`" , output )
75
- docker_image = match .group (1 )
90
+ #Extract matching image name excluding `
91
+ match = re .search (r"docker pull ([\.\/\-\:\w\d]*)" , output )
92
+ docker_image = match .group (1 ) if match else ''
76
93
return ((version , docker_image ))
77
94
78
95
def get_versions_from_releases (repo ):
96
+ """
97
+ Using `gh` cli get the github releases page details then
98
+ create a list of grouped version on major.minor
99
+ and for each give all major.minor.patch with release dates
100
+ """
79
101
# Run the `gh release` command to get the release list
80
102
output = subprocess .check_output (['gh' , 'release' , '-R' , repo , 'list' ], text = True )
81
103
# Parse the output and group by major and minor version numbers
@@ -95,15 +117,15 @@ def get_versions_from_releases(repo):
95
117
96
118
97
119
def main ():
98
- # Argument parser
99
- parser = argparse . ArgumentParser ( description = 'Get the currently supported versions for a GitHub repository.' )
100
- parser . add_argument (
101
- '--repo' ,
102
- '-R' , required = True ,
103
- action = 'append' , dest = 'repos' ,
104
- help = '''The name of the repository in the format owner/repo. You can specify multiple -R repo to query multiple repositories e.g.: \n
105
- python -R kubernetes-csi/external-attacher -R kubernetes-csi/external-provisioner -R kubernetes-csi/external-resizer -R kubernetes-csi/external-snapshotter -R kubernetes-csi/livenessprobe -R kubernetes-csi/node-driver-registrar -R kubernetes-csi/external-health-monitor'''
106
- )
120
+ manual = """
121
+ This script lists the supported versions Github releases according to https://kubernetes-csi.github.io/docs/project-policies.html#support
122
+ It has been designed to help to update the tables from : https://kubernetes-csi.github.io/docs/sidecar-containers.html \n \n
123
+ It can take multiple repos as argument, for all CSI sidecars details you can run:
124
+ ./get_supported_version_csi-sidecar.py -R kubernetes-csi/external-attacher -R kubernetes-csi/external-provisioner -R kubernetes-csi/external-resizer -R kubernetes-csi/external-snapshotter -R kubernetes-csi/livenessprobe -R kubernetes-csi/node-driver-registrar -R kubernetes-csi/external-health-monitor \n
125
+ With the output you can then update the documentation manually.
126
+ """
127
+ parser = argparse . ArgumentParser ( formatter_class = argparse . RawDescriptionHelpFormatter , description = manual )
128
+ parser . add_argument ( '--repo' , '-R' , required = True , action = 'append' , dest = 'repos' , help = 'The name of the repository in the format owner/repo.' )
107
129
parser .add_argument ('--display' , '-d' , action = 'store_true' , help = '(default) Display EOL versions with their dates' , default = True )
108
130
parser .add_argument ('--doc' , '-D' , action = 'store_true' , help = 'Helper to https://kubernetes-csi.github.io/docs/ that prints Docker image for each EOL version' )
109
131
@@ -126,9 +148,9 @@ def main():
126
148
if args .doc :
127
149
print ("\n Supported Versions with docker images for each end of life version:\n " )
128
150
for version in eol_versions :
129
- _ , image = get_release_docker_image (args . repo , version [0 ])
151
+ _ , image = get_release_docker_image (repo , version [0 ])
130
152
print (f"{ version [0 ]} \t { image } " )
131
153
print ()
132
154
133
155
if __name__ == '__main__' :
134
- main ()
156
+ main ()
0 commit comments