Skip to content

Commit d1df36a

Browse files
authored
Merge pull request #40 from sommersoft/arduino_release
Add Arduino Release "Status" & Add Arduino Checks To Travis
2 parents 1345508 + edc36a6 commit d1df36a

File tree

2 files changed

+83
-12
lines changed

2 files changed

+83
-12
lines changed

.travis.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ cache:
77
pip: true
88

99
env:
10-
# LIB_CHECK_FILE is for circuitpython_libraries.py output
10+
# LIB_CHECK_CP_FILE is for circuitpython_libraries.py output
11+
# LIB_CHECK_ARD_FILE is for arduino_libraries.py output
1112
# LIB_DL_STATS_FILE is for future Bundle and PyPi download stats script
12-
- LIB_CHECK_FILE='bin/adabot/library_report_'`date +%Y%m%d`'.txt' LIB_DL_STATS_FILE='bin/adabot/library_download_stats_'`date +%Y%m%d`'.txt'
13+
- LIB_CHECK_CP_FILE='bin/adabot/circuitpython_library_report_'`date +%Y%m%d`'.txt'
14+
- LIB_CHECK_ARD_FILE='bin/adabot/arduino_library_report_'`date +%Y%m%d`'.txt'
15+
- LIB_DL_STATS_FILE='bin/adabot/library_download_stats_'`date +%Y%m%d`'.txt'
1316

1417
addons:
1518
artifacts:
@@ -23,16 +26,21 @@ script:
2326
- mkdir -p bin/adabot
2427

2528
# Run the Bundle update script
26-
- echo "Updating Bundle..." && echo -en 'travis_fold:start:update\\r'
29+
- echo "Updating CircuitPython Library Bundles..." && echo -en 'travis_fold:start:update\\r'
2730
- python -m adabot.circuitpython_bundle
2831
- echo -en 'travis_fold:end:update\\r'
2932

3033
# Run the circuitpython_libraries.py report; output a file with results for AWS
31-
- echo "Running library checks..." && echo -en 'travis_fold:start:lib_check\\r'
32-
- python -m adabot.circuitpython_libraries -o $LIB_CHECK_FILE
34+
- echo "Running CircuitPython library checks..." && echo -en 'travis_fold:start:lib_check\\r'
35+
- python -m adabot.circuitpython_libraries -o $LIB_CHECK_CP_FILE
3336
- echo -en 'travis_fold:end:lib_check\\r'
3437

3538
# Run the circuitpython_library_download_stats.py; output a file with results for AWS
36-
- echo "Getting Library Download Stats..." && echo -en 'travis_fold:start:stats\\r'
39+
- echo "Getting CircuitPython Library Download Stats..." && echo -en 'travis_fold:start:stats\\r'
3740
- python -m adabot.circuitpython_library_download_stats -o $LIB_DL_STATS_FILE
3841
- echo -en 'travis_fold:end:stats\\r'
42+
43+
# Run the arduino_libraries.py report; output a file with results for AWS
44+
- echo "Running Arduino library checks..." && echo -en 'travis_fold:start:ard_lib_check\\r'
45+
- python -m adabot.arduino_libraries -o $LIB_CHECK_ARD_FILE
46+
- echo -en 'travis_fold:end:ard_lib_check\\r'

adabot/arduino_libraries.py

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ def list_repos():
6969

7070
return repos
7171

72+
def is_arduino_library(repo):
73+
""" Returns if the repo is an Arduino library, as determined by the existence of
74+
the 'library.properties' file.
75+
"""
76+
has_lib_prop = github.get("/repos/adafruit/" + repo["name"] + "/contents")
77+
if has_lib_prop.ok:
78+
return ("library.properties" in has_lib_prop.text)
79+
else:
80+
return False
81+
7282
def output_handler(message="", quiet=False):
7383
"""Handles message output to prompt/file for print_*() functions."""
7484
if output_filename is not None:
@@ -115,23 +125,76 @@ def validate_library_properties(repo):
115125
#print("{} skipped".format(repo["name"]))
116126
return
117127

128+
def validate_release_state(repo):
129+
"""Validate if a repo 1) has a release, and 2) if there have been commits
130+
since the last release. Returns a list of string error messages for the
131+
repository.
132+
"""
133+
134+
if not is_arduino_library(repo):
135+
return
136+
repo_last_release = github.get("/repos/" + repo["full_name"] + "/releases/latest")
137+
if not repo_last_release.ok:
138+
return
139+
repo_release_json = repo_last_release.json()
140+
if "tag_name" in repo_release_json:
141+
tag_name = repo_release_json["tag_name"]
142+
elif "message" in repo_release_json:
143+
output_handler("Error: retrieving latest release information failed on '{0}'. Information Received: {1}".format(
144+
repo["name"], repo_release_json["message"]))
145+
return
146+
147+
compare_tags = github.get("/repos/" + repo["full_name"] + "/compare/master..." + tag_name)
148+
if not compare_tags.ok:
149+
output_handler("Error: failed to compare {0} 'master' to tag '{1}'".format(repo["name"], tag_name))
150+
return
151+
compare_tags_json = compare_tags.json()
152+
if "status" in compare_tags_json:
153+
if compare_tags.json()["status"] != "identical":
154+
#print("Compare {4} status: {0} \n Ahead: {1} \t Behind: {2} \t Commits: {3}".format(
155+
# compare_tags_json["status"], compare_tags_json["ahead_by"],
156+
# compare_tags_json["behind_by"], compare_tags_json["total_commits"], repo["full_name"]))
157+
return [tag_name, compare_tags_json["behind_by"]]
158+
elif "errors" in compare_tags_json:
159+
output_handler("Error: comparing latest release to 'master' failed on '{0}'. Error Message: {1}".format(
160+
repo["name"], compare_tags_json["message"]))
161+
162+
return
163+
118164
def run_arduino_lib_checks():
119165
output_handler("Running Arduino Library Checks")
166+
output_handler("Getting list of libraries to check...")
120167

121168
repo_list = list_repos()
169+
output_handler("Found {} Arduino libraries to check\n".format(len(repo_list)))
122170
failed_lib_prop = [[" Repo", "Release Tag", "library.properties Version"], [" ----", "-----------", "--------------------------"]]
171+
needs_release_list = [[" Repo", "Latest Release", "Commits Behind"], [" ----", "--------------", "--------------"]]
123172
for repo in repo_list:
124173
lib_check = validate_library_properties(repo)
125174
if lib_check:
126175
if lib_check[0] != lib_check[1]:
127176
failed_lib_prop.append([" " + str(repo["name"]), lib_check[0], lib_check[1]])
128177

129-
output_handler("Libraries Have Mismatched Release Tag and library.properties Version: ({})".format(len(failed_lib_prop)))
130-
long_col = [(max([len(str(row[i])) for row in failed_lib_prop]) + 3)
131-
for i in range(len(failed_lib_prop[0]))]
132-
row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
133-
for lib in failed_lib_prop:
134-
print(row_format.format(*lib))
178+
needs_release = validate_release_state(repo)
179+
if needs_release:
180+
needs_release_list.append([" " + str(repo["name"]), needs_release[0], needs_release[1]])
181+
182+
if len(failed_lib_prop) > 2:
183+
output_handler("Libraries Have Mismatched Release Tag and library.properties Version: ({})".format(len(failed_lib_prop)))
184+
long_col = [(max([len(str(row[i])) for row in failed_lib_prop]) + 3)
185+
for i in range(len(failed_lib_prop[0]))]
186+
row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
187+
for lib in failed_lib_prop:
188+
output_handler(row_format.format(*lib))
189+
190+
if len(needs_release_list) > 2:
191+
output_handler()
192+
output_handler("Libraries have commits since last release: ({})".format(len(needs_release_list)))
193+
long_col = [(max([len(str(row[i])) for row in needs_release_list]) + 3)
194+
for i in range(len(needs_release_list[0]))]
195+
row_format = "".join(["{:<" + str(this_col) + "}" for this_col in long_col])
196+
for lib in needs_release_list:
197+
output_handler(row_format.format(*lib))
135198

136199
if __name__ == "__main__":
137200
cmd_line_args = cmd_line_parser.parse_args()

0 commit comments

Comments
 (0)