Skip to content

Commit

Permalink
Handle moved and removed submodules more gracefully.
Browse files Browse the repository at this point in the history
Also, tweak the release message and error handling.
  • Loading branch information
adafruit-adabot committed Jan 10, 2018
1 parent a1344cd commit 812c633
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions adabot/circuitpython_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ def update_bundle(bundle_path):
# sh fails to find the subcommand so we use subprocess.
subprocess.run(shlex.split("git submodule foreach 'git checkout -q `git rev-list --tags --max-count=1`'"), stdout=subprocess.DEVNULL)

# Don't update circuitpython, its going away soon.
git.submodule("update", "circuitpython")

status = StringIO()
result = git.status("--short", _out=status)
updates = []
Expand All @@ -109,7 +106,7 @@ def update_bundle(bundle_path):
for status_line in status.split("\n"):
action, directory = status_line.split()
if action != "M" or not directory.startswith("libraries"):
RuntimeError("Unsupported updates")
raise RuntimeError("Unsupported updates")

# Compute the tag difference.
diff = StringIO()
Expand Down Expand Up @@ -209,23 +206,33 @@ def new_release(bundle, bundle_path):
repo_links = {}

output = StringIO()
git.diff("--submodule=log", last_tag + "..", _out=output)
git.diff("--submodule=short", last_tag + "..", _out=output)
output = output.getvalue().strip()
if not output:
print("Everything is already released.")
return
current_submodule = None
current_index = None
for line in output.split("\n"):
if not line.startswith("Submodule"):
if line.startswith("diff"):
current_submodule = line.split()[-1][len("b/"):]
continue
elif "index" in line:
current_index = line
continue
line = line.split()
directory = line[1]
if directory == "circuitpython":
elif not line.startswith("+Subproject"):
continue
commit_range = line[2].strip(":")

# We have a candidate submodule change.
directory = current_submodule
commit_range = current_index.split()[1]
library_name = directory.split("/")[-1]
if commit_range.startswith("0000000"):
added_submodules.append(library_name)
commit_range = commit_range.split(".")[-1]
elif commit_range.endswith("0000000"):
# For now, skip documenting deleted modules.
continue
else:
updated_submodules.append(library_name)

Expand Down Expand Up @@ -261,7 +268,7 @@ def new_release(bundle, bundle_path):

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

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")
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")

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.")

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

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

Expand All @@ -285,9 +295,13 @@ def new_release(bundle, bundle_path):
directory = os.path.abspath(".bundles")
for bundle in bundles:
bundle_path = os.path.join(directory, bundle)
fetch_bundle(bundle, bundle_path)
update_info = update_bundle(bundle_path)
if update_info:
commit_updates(bundle_path, update_info)
push_updates(bundle_path)
new_release(bundle, bundle_path)
try:
fetch_bundle(bundle, bundle_path)
update_info = update_bundle(bundle_path)
if update_info:
commit_updates(bundle_path, update_info)
push_updates(bundle_path)
new_release(bundle, bundle_path)
except RuntimeError as e:
print("Failed to update and release:", bundle)
print(e)

0 comments on commit 812c633

Please sign in to comment.