Skip to content

Commit 812c633

Browse files
Handle moved and removed submodules more gracefully.
Also, tweak the release message and error handling.
1 parent a1344cd commit 812c633

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

adabot/circuitpython_bundle.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ def update_bundle(bundle_path):
9898
# sh fails to find the subcommand so we use subprocess.
9999
subprocess.run(shlex.split("git submodule foreach 'git checkout -q `git rev-list --tags --max-count=1`'"), stdout=subprocess.DEVNULL)
100100

101-
# Don't update circuitpython, its going away soon.
102-
git.submodule("update", "circuitpython")
103-
104101
status = StringIO()
105102
result = git.status("--short", _out=status)
106103
updates = []
@@ -109,7 +106,7 @@ def update_bundle(bundle_path):
109106
for status_line in status.split("\n"):
110107
action, directory = status_line.split()
111108
if action != "M" or not directory.startswith("libraries"):
112-
RuntimeError("Unsupported updates")
109+
raise RuntimeError("Unsupported updates")
113110

114111
# Compute the tag difference.
115112
diff = StringIO()
@@ -209,23 +206,33 @@ def new_release(bundle, bundle_path):
209206
repo_links = {}
210207

211208
output = StringIO()
212-
git.diff("--submodule=log", last_tag + "..", _out=output)
209+
git.diff("--submodule=short", last_tag + "..", _out=output)
213210
output = output.getvalue().strip()
214211
if not output:
215212
print("Everything is already released.")
216213
return
214+
current_submodule = None
215+
current_index = None
217216
for line in output.split("\n"):
218-
if not line.startswith("Submodule"):
217+
if line.startswith("diff"):
218+
current_submodule = line.split()[-1][len("b/"):]
219+
continue
220+
elif "index" in line:
221+
current_index = line
219222
continue
220-
line = line.split()
221-
directory = line[1]
222-
if directory == "circuitpython":
223+
elif not line.startswith("+Subproject"):
223224
continue
224-
commit_range = line[2].strip(":")
225+
226+
# We have a candidate submodule change.
227+
directory = current_submodule
228+
commit_range = current_index.split()[1]
225229
library_name = directory.split("/")[-1]
226230
if commit_range.startswith("0000000"):
227231
added_submodules.append(library_name)
228232
commit_range = commit_range.split(".")[-1]
233+
elif commit_range.endswith("0000000"):
234+
# For now, skip documenting deleted modules.
235+
continue
229236
else:
230237
updated_submodules.append(library_name)
231238

@@ -261,7 +268,7 @@ def new_release(bundle, bundle_path):
261268

262269
release_description.append("\n--------------------------\n")
263270

264-
release_description.append("The libraries in each release are compiled for all recent major versions of CircuitPython. Please download the one that matches your version of CircuitPython. For example, download the bundle with `2.x` in the filename for CircuitPython versions 2.0.0 and 2.1.0.\n")
271+
release_description.append("The libraries in each release are compiled for all recent major versions of CircuitPython. Please download the one that matches your version of CircuitPython. You may need to update your CircuitPython if your version isn't available. For example, if you are running 2.1.0 you should update to 2.2.0 and get a bundle for 2.2.0.\n")
265272

266273
release_description.append("To install, simply download the matching zip file, unzip it, and copy the lib folder onto your CIRCUITPY drive. Non-express boards such as the [Trinket M0](https://www.adafruit.com/product/3500), [Gemma M0](https://www.adafruit.com/product/3501) and [Feather M0 Basic](https://www.adafruit.com/product/2772) will need to selectively copy files over.")
267274

@@ -274,8 +281,11 @@ def new_release(bundle, bundle_path):
274281
"prerelease": False}
275282

276283
print("Releasing {}".format(release["tag_name"]))
284+
print(release["body"])
277285
response = github.post("/repos/adafruit/" + bundle + "/releases", json=release)
278286
if not response.ok:
287+
print("Failed to create release")
288+
print(release)
279289
print(response.request.url)
280290
print(response.text)
281291

@@ -285,9 +295,13 @@ def new_release(bundle, bundle_path):
285295
directory = os.path.abspath(".bundles")
286296
for bundle in bundles:
287297
bundle_path = os.path.join(directory, bundle)
288-
fetch_bundle(bundle, bundle_path)
289-
update_info = update_bundle(bundle_path)
290-
if update_info:
291-
commit_updates(bundle_path, update_info)
292-
push_updates(bundle_path)
293-
new_release(bundle, bundle_path)
298+
try:
299+
fetch_bundle(bundle, bundle_path)
300+
update_info = update_bundle(bundle_path)
301+
if update_info:
302+
commit_updates(bundle_path, update_info)
303+
push_updates(bundle_path)
304+
new_release(bundle, bundle_path)
305+
except RuntimeError as e:
306+
print("Failed to update and release:", bundle)
307+
print(e)

0 commit comments

Comments
 (0)