19
19
sys .path .append ("adabot" )
20
20
import adabot .github_requests as github
21
21
22
- SUPPORTED_PORTS = ["atmel-samd" , "cxd56" , "esp32s2" , "litex" , "mimxrt10xx" , "nrf" , "stm" ]
23
-
24
- BIN = ('bin' ,)
25
- UF2 = ('uf2' ,)
26
- BIN_UF2 = ('bin' , 'uf2' )
27
- HEX = ('hex' ,)
28
- HEX_UF2 = ('hex' , 'uf2' )
29
- SPK = ('spk' ,)
30
- DFU = ('dfu' ,)
31
- BIN_DFU = ('bin' , 'dfu' )
32
-
33
- # Example:
34
- # https://downloads.circuitpython.org/bin/trinket_m0/en_US/adafruit-circuitpython-trinket_m0-en_US-5.0.0-rc.0.uf2
35
- DOWNLOAD_BASE_URL = "https://downloads.circuitpython.org/bin"
22
+ SUPPORTED_PORTS = [
23
+ "atmel-samd" ,
24
+ "cxd56" ,
25
+ "esp32s2" ,
26
+ "litex" ,
27
+ "mimxrt10xx" ,
28
+ "nrf" ,
29
+ "stm" ,
30
+ ]
31
+
32
+ BIN = ("bin" ,)
33
+ UF2 = ("uf2" ,)
34
+ BIN_UF2 = ("bin" , "uf2" )
35
+ HEX = ("hex" ,)
36
+ HEX_UF2 = ("hex" , "uf2" )
37
+ SPK = ("spk" ,)
38
+ DFU = ("dfu" ,)
39
+ BIN_DFU = ("bin" , "dfu" )
36
40
37
41
# Default extensions
38
42
extension_by_port = {
42
46
"cxd56" : SPK ,
43
47
"mimxrt10xx" : HEX_UF2 ,
44
48
"litex" : DFU ,
45
- "esp32s2" : BIN_UF2
49
+ "esp32s2" : BIN_UF2 ,
46
50
}
47
51
48
52
# Per board overrides
57
61
"feather_m0_rfm69" : BIN_UF2 ,
58
62
"feather_m0_rfm9x" : BIN_UF2 ,
59
63
"uchip" : BIN_UF2 ,
60
-
61
64
# nRF52840 dev kits that may not have UF2 bootloaders,
62
65
"makerdiary_nrf52840_mdk" : HEX ,
63
66
"makerdiary_nrf52840_mdk_usb_dongle" : HEX_UF2 ,
64
67
"pca10056" : BIN_UF2 ,
65
68
"pca10059" : BIN_UF2 ,
66
69
"electronut_labs_blip" : HEX ,
67
-
68
70
# stm32
69
- "meowbit_v121" : UF2
71
+ "meowbit_v121" : UF2 ,
70
72
}
71
73
72
74
aliases_by_board = {
73
- "circuitplayground_express" : ["circuitplayground_express_4h" , "circuitplayground_express_digikey_pycon2019" ],
75
+ "circuitplayground_express" : [
76
+ "circuitplayground_express_4h" ,
77
+ "circuitplayground_express_digikey_pycon2019" ,
78
+ ],
74
79
"pybadge" : ["edgebadge" ],
75
80
"pyportal" : ["pyportal_pynt" ],
76
81
"gemma_m0" : ["gemma_m0_pycon2018" ],
77
- "pewpew10" : ["pewpew13" ]
82
+ "pewpew10" : ["pewpew13" ],
78
83
}
79
84
85
+
80
86
def get_languages ():
81
87
languages = []
82
88
for f in os .scandir ("../locale" ):
83
89
if f .name .endswith (".po" ):
84
90
languages .append (f .name [:- 3 ])
85
91
return languages
86
92
93
+
87
94
def get_board_mapping ():
88
95
boards = {}
89
96
for port in SUPPORTED_PORTS :
@@ -95,23 +102,30 @@ def get_board_mapping():
95
102
extensions = extension_by_port [port ]
96
103
extensions = extension_by_board .get (board_path .name , extensions )
97
104
aliases = aliases_by_board .get (board_path .name , [])
98
- boards [board_id ] = {"port" : port ,
99
- "extensions" : extensions ,
100
- "download_count" : 0 ,
101
- "aliases" : aliases }
105
+ boards [board_id ] = {
106
+ "port" : port ,
107
+ "extensions" : extensions ,
108
+ "download_count" : 0 ,
109
+ "aliases" : aliases ,
110
+ }
102
111
for alias in aliases :
103
- boards [alias ] = {"port" : port ,
104
- "extensions" : extensions ,
105
- "download_count" : 0 ,
106
- "alias" : True ,
107
- "aliases" : []}
112
+ boards [alias ] = {
113
+ "port" : port ,
114
+ "extensions" : extensions ,
115
+ "download_count" : 0 ,
116
+ "alias" : True ,
117
+ "aliases" : [],
118
+ }
108
119
return boards
109
120
121
+
110
122
def get_version_info ():
111
123
version = None
112
124
sha = git ("rev-parse" , "--short" , "HEAD" ).stdout .decode ("utf-8" )
113
125
try :
114
- version = git ("describe" , "--tags" , "--exact-match" ).stdout .decode ("utf-8" ).strip ()
126
+ version = (
127
+ git ("describe" , "--tags" , "--exact-match" ).stdout .decode ("utf-8" ).strip ()
128
+ )
115
129
except sh .ErrorReturnCode_128 :
116
130
# No exact match
117
131
pass
@@ -120,18 +134,21 @@ def get_version_info():
120
134
sha = os .environ ["GITHUB_SHA" ]
121
135
122
136
if not version :
123
- version = "{}-{}" .format (date .today ().strftime ("%Y%m%d" ), sha [:7 ])
137
+ version = "{}-{}" .format (date .today ().strftime ("%Y%m%d" ), sha [:7 ])
124
138
125
139
return sha , version
126
140
141
+
127
142
def get_current_info ():
128
143
response = github .get ("/repos/adafruit/circuitpython-org/git/refs/heads/master" )
129
144
if not response .ok :
130
145
print (response .text )
131
146
raise RuntimeError ("cannot get master sha" )
132
147
commit_sha = response .json ()["object" ]["sha" ]
133
148
134
- response = github .get ("/repos/adafruit/circuitpython-org/contents/_data/files.json?ref=" + commit_sha )
149
+ response = github .get (
150
+ "/repos/adafruit/circuitpython-org/contents/_data/files.json?ref=" + commit_sha
151
+ )
135
152
if not response .ok :
136
153
print (response .text )
137
154
raise RuntimeError ("cannot get previous files.json" )
@@ -145,6 +162,7 @@ def get_current_info():
145
162
current_info [info ["id" ]] = info
146
163
return git_info , current_info
147
164
165
+
148
166
def create_pr (changes , updated , git_info , user ):
149
167
commit_sha , original_blob_sha = git_info
150
168
branch_name = "new_release_" + changes ["new_release" ]
@@ -158,7 +176,7 @@ def create_pr(changes, updated, git_info, user):
158
176
updated_list .append (info )
159
177
160
178
updated = json .dumps (updated_list , sort_keys = True , indent = 1 ).encode ("utf-8" ) + b"\n "
161
- #print(updated.decode("utf-8"))
179
+ # print(updated.decode("utf-8"))
162
180
pr_title = "Automated website update for release {}" .format (changes ["new_release" ])
163
181
boards = ""
164
182
if changes ["new_boards" ]:
@@ -167,16 +185,13 @@ def create_pr(changes, updated, git_info, user):
167
185
if changes ["new_languages" ]:
168
186
languages = "New languages:\n * " + "\n * " .join (changes ["new_languages" ])
169
187
message = "Automated website update for release {} by Blinka.\n \n {}\n \n {}\n " .format (
170
- changes ["new_release" ],
171
- boards ,
172
- languages
188
+ changes ["new_release" ], boards , languages
173
189
)
174
190
175
- create_branch = {
176
- "ref" : "refs/heads/" + branch_name ,
177
- "sha" : commit_sha
178
- }
179
- response = github .post ("/repos/{}/circuitpython-org/git/refs" .format (user ), json = create_branch )
191
+ create_branch = {"ref" : "refs/heads/" + branch_name , "sha" : commit_sha }
192
+ response = github .post (
193
+ "/repos/{}/circuitpython-org/git/refs" .format (user ), json = create_branch
194
+ )
180
195
if not response .ok and response .json ()["message" ] != "Reference already exists" :
181
196
print ("unable to create branch" )
182
197
print (response .text )
@@ -186,10 +201,13 @@ def create_pr(changes, updated, git_info, user):
186
201
"message" : message ,
187
202
"content" : base64 .b64encode (updated ).decode ("utf-8" ),
188
203
"sha" : original_blob_sha ,
189
- "branch" : branch_name
204
+ "branch" : branch_name ,
190
205
}
191
206
192
- response = github .put ("/repos/{}/circuitpython-org/contents/_data/files.json" .format (user ), json = update_file )
207
+ response = github .put (
208
+ "/repos/{}/circuitpython-org/contents/_data/files.json" .format (user ),
209
+ json = update_file ,
210
+ )
193
211
if not response .ok :
194
212
print ("unable to post new file" )
195
213
print (response .text )
@@ -199,7 +217,7 @@ def create_pr(changes, updated, git_info, user):
199
217
"head" : user + ":" + branch_name ,
200
218
"base" : "master" ,
201
219
"body" : message ,
202
- "maintainer_can_modify" : True
220
+ "maintainer_can_modify" : True ,
203
221
}
204
222
response = github .post ("/repos/adafruit/circuitpython-org/pulls" , json = pr_info )
205
223
if not response .ok :
@@ -220,17 +238,14 @@ def print_active_user():
220
238
print ("Not logged in" )
221
239
return None
222
240
241
+
223
242
def generate_download_info ():
224
243
boards = {}
225
244
errors = []
226
245
227
246
new_tag = os .environ ["RELEASE_TAG" ]
228
247
229
- changes = {
230
- "new_release" : new_tag ,
231
- "new_boards" : [],
232
- "new_languages" : []
233
- }
248
+ changes = {"new_release" : new_tag , "new_boards" : [], "new_languages" : []}
234
249
235
250
user = print_active_user ()
236
251
@@ -254,8 +269,9 @@ def generate_download_info():
254
269
info = current_info [board ]
255
270
for version in info ["versions" ]:
256
271
previous_releases .add (version ["version" ])
257
- previous_languages .update (version ["files" ].keys ())
258
- if version ["stable" ] == new_stable :
272
+ if version ["stable" ] == new_stable or (
273
+ new_stable and version ["version" ].startswith (this_version )
274
+ ):
259
275
info ["versions" ].remove (version )
260
276
261
277
board_mapping = get_board_mapping ()
@@ -272,29 +288,15 @@ def generate_download_info():
272
288
alias_info = board_mapping [alias ]
273
289
if alias not in current_info :
274
290
changes ["new_boards" ].append (alias )
275
- current_info [alias ] = {"downloads" : 0 ,
276
- "versions" : []}
291
+ current_info [alias ] = {"downloads" : 0 , "versions" : []}
277
292
278
293
new_version = {
279
294
"stable" : new_stable ,
280
295
"version" : new_tag ,
281
296
"modules" : support_matrix .get (alias , "[]" ),
282
- "files" : {},
283
297
"languages" : languages ,
284
- "extensions" : board_info ["extensions" ]
298
+ "extensions" : board_info ["extensions" ],
285
299
}
286
- for language in languages :
287
- files = []
288
- new_version ["files" ][language ] = files
289
- for extension in board_info ["extensions" ]:
290
- files .append (
291
- "{base_url}/{alias}/{language}/adafruit-circuitpython-{alias}-{language}-{tag}.{extension}"
292
- .format (
293
- base_url = DOWNLOAD_BASE_URL ,
294
- tag = new_tag ,
295
- alias = alias ,
296
- language = language ,
297
- extension = extension ))
298
300
current_info [alias ]["downloads" ] = alias_info ["download_count" ]
299
301
current_info [alias ]["versions" ].append (new_version )
300
302
@@ -305,6 +307,7 @@ def generate_download_info():
305
307
else :
306
308
print ("No new release to update" )
307
309
310
+
308
311
if __name__ == "__main__" :
309
312
if "RELEASE_TAG" in os .environ and os .environ ["RELEASE_TAG" ]:
310
313
generate_download_info ()
0 commit comments