1
+
2
+ import os
3
+ import logging
4
+ import time
5
+ import requests
6
+ import argparse
7
+ from OBAS_utils .release_utils import closeRelease
8
+
9
+ logging .basicConfig (encoding = "utf-8" , level = logging .INFO )
10
+
11
+ parser = argparse .ArgumentParser ("release" )
12
+ parser .add_argument ("branch_client_python" , help = "The new version number of the release." , type = str )
13
+ parser .add_argument ("previous_version" , help = "The previous version number of the release." , type = str )
14
+ parser .add_argument ("new_version" , help = "The new version number of the release." , type = str )
15
+ parser .add_argument ("--dev" , help = "Flag to prevent pushing the release." , action = "store_false" )
16
+ args = parser .parse_args ()
17
+
18
+ previous_version = args .previous_version
19
+ new_version = args .new_version
20
+ branch_client_python = args .branch_client_python
21
+
22
+ github_token = os .environ ["GREN_GITHUB_TOKEN" ]
23
+
24
+ os .environ ["DRONE_COMMIT_AUTHOR" ] = "Filigran-Automation"
25
+ os .environ ["GIT_AUTHOR_NAME" ] = "Filigran Automation"
26
+ os .
environ [
"GIT_AUTHOR_EMAIL" ]
= "[email protected] "
27
+ os .environ ["GIT_COMMITTER_NAME" ] = "Filigran Automation"
28
+ os .
environ [
"GIT_COMMITTER_EMAIL" ]
= "[email protected] "
29
+
30
+ # Python library release
31
+ logging .info ("[client-python] Starting the release" )
32
+ with open ("./pyobas/__init__.py" , "r" ) as file :
33
+ filedata = file .read ()
34
+ filedata = filedata .replace (previous_version , new_version )
35
+ with open ("./pyobas/__init__.py" , "w" ) as file :
36
+ file .write (filedata )
37
+ with open ("./pyobas/_version.py" , "r" ) as file :
38
+ filedata = file .read ()
39
+ filedata = filedata .replace (previous_version , new_version )
40
+ with open ("./pyobas/_version.py" , "w" ) as file :
41
+ file .write (filedata )
42
+
43
+ # Commit the change
44
+ logging .info ("[client-python] Pushing to " + branch_client_python )
45
+ os .system (
46
+ 'git commit -a -m "[client] Release '
47
+ + new_version
48
+ + '" > /dev/null 2>&1' )
49
+ if not args .dev :
50
+ os .system ('git push origin '
51
+ + branch_client_python
52
+ + " > /dev/null 2>&1"
53
+ )
54
+
55
+ logging .info ("[client-python] Tagging" )
56
+ os .system (
57
+ "git tag -f "
58
+ + new_version
59
+ )
60
+ if not args .dev :
61
+ os .system (
62
+ "git push -f --tags > /dev/null 2>&1"
63
+ )
64
+
65
+ logging .info ("[client-python] Generating release" )
66
+ os .system ("gren release > /dev/null 2>&1" )
67
+
68
+ # Modify the release note
69
+ logging .info ("[client-python] Getting the current release note" )
70
+ release = requests .get (
71
+ "https://api.github.com/repos/OpenBAS-Platform/client-python/releases/latest" ,
72
+ headers = {
73
+ "Accept" : "application/vnd.github+json" ,
74
+ "Authorization" : "Bearer " + github_token ,
75
+ "X-GitHub-Api-Version" : "2022-11-28" ,
76
+ },
77
+ )
78
+ release_data = release .json ()
79
+ release_body = release_data ["body" ]
80
+
81
+ logging .info ("[client-python] Generating the new release note" )
82
+ if not args .dev :
83
+ github_release_note = requests .post (
84
+ "https://api.github.com/repos/OpenBAS-Platform/client-python/releases/generate-notes" ,
85
+ headers = {
86
+ "Accept" : "application/vnd.github+json" ,
87
+ "Authorization" : "Bearer " + github_token ,
88
+ "X-GitHub-Api-Version" : "2022-11-28" ,
89
+ },
90
+ json = {"tag_name" : new_version , "previous_tag_name" : previous_version },
91
+ )
92
+ github_release_note_data = github_release_note .json ()
93
+ github_release_note_data_body = github_release_note_data ["body" ]
94
+ if "Full Changelog" not in release_body :
95
+ new_release_note = (
96
+ release_body
97
+ + "\n "
98
+ + github_release_note_data_body .replace (
99
+ "## What's Changed" , "#### Pull Requests:\n "
100
+ ).replace ("## New Contributors" , "#### New Contributors:\n " )
101
+ )
102
+ else :
103
+ new_release_note = release_body
104
+
105
+ logging .info ("[client-python] Updating the release" )
106
+ requests .patch (
107
+ "https://api.github.com/repos/OpenBAS-Platform/client-python/releases/"
108
+ + str (release_data ["id" ]),
109
+ headers = {
110
+ "Accept" : "application/vnd.github+json" ,
111
+ "Authorization" : "Bearer " + github_token ,
112
+ "X-GitHub-Api-Version" : "2022-11-28" ,
113
+ },
114
+ json = {"body" : new_release_note },
115
+ )
116
+
117
+ if not args .dev :
118
+ closeRelease ("https://api.github.com/repos/OpenBAS-Platform/client-python" , new_version , github_token )
119
+
120
+ logging .info (
121
+ "[client-python] Release done! Waiting 10 minutes for CI/CD and publication..."
122
+ )
123
+
124
+ if not args .dev :
125
+ time .sleep (600 )
0 commit comments