From 2182b2c7424524722bceda993926e753ad2adfe4 Mon Sep 17 00:00:00 2001 From: jonpas Date: Fri, 19 Aug 2016 16:12:09 +0200 Subject: [PATCH] Run documentation dependencies extractor on Travis deployment --- .travis.yml | 2 +- tools/deploy.py | 42 +++++++++++++++++--- tools/extract_dependencies.py | 75 ++++++++++++++++++++--------------- 3 files changed, 79 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3828300d7f..90c037b514 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ script: fi env: global: - - secure: KcJQbknBOdC5lA4nFGKPXVRVIGLDXDRzC8XkHuXJCE9pIR/wbxbkvx8fHKcC6SC9eHgzneC3+o4m4+CjIbVvIwDgslRbJ8Y59i90ncONmdoRx1HUYHwuYWVZm9HJFjCsIbrEqhSyyKS+PB3WZVOLbErtNHsgS8f43PTh5Ujg7Vg= + - secure: cdxkn5cAx+s1C9Ne5m+odEhde1uuSg6XGMDgepN4DwSAJwtMnUv3ZmDebd5YJC1raZJdep+n09Cj0GoTNICQRkco50DxHKHYNad41wetY0tn0cs9gmPYzyFE5q4vuWiQ47dlGhQQ7IJDyX0nU++gG5E50/PhlZfebdedGSprN/4= notifications: slack: rooms: diff --git a/tools/deploy.py b/tools/deploy.py index 2bc894176d..42b5a825a3 100644 --- a/tools/deploy.py +++ b/tools/deploy.py @@ -12,7 +12,7 @@ import sys import shutil import traceback import subprocess as sp -from pygithub3 import Github +from github import Github, InputGitAuthor TRANSLATIONISSUE = 367 @@ -21,39 +21,69 @@ TRANSLATIONBODY = """**[ACE3 Translation Guide](http://ace3mod.com/wiki/developm {} """ +DEPENDENCIESPATH = "docs/_includes/dependencies_list.md" + REPOUSER = "acemod" REPONAME = "ACE3" REPOPATH = "{}/{}".format(REPOUSER,REPONAME) -def update_translations(token): +def update_translations(repo): diag = sp.check_output(["python3", "tools/stringtablediag.py", "--markdown"]) diag = str(diag, "utf-8") - repo = Github(token).get_repo(REPOPATH) issue = repo.get_issue(TRANSLATIONISSUE) issue.edit(body=TRANSLATIONBODY.format(diag)) +def update_dependencies(repo): + dependencies = sp.check_output(["python3", "tools/extract_dependencies.py", "--markdown"]) + dependencies = str(dependencies, "utf-8") + diff = sp.check_output(["git", "diff", "--name-only", DEPENDENCIESPATH]) + diff = str(diff, "utf-8") + + if diff != "": + sha = repo.get_contents(DEPENDENCIESPATH + #, ref="travisForDocs" # Debug + ).sha + repo.update_file( + path="/{}".format(DEPENDENCIESPATH), + message="[Docs] Update component dependencies\nAutomatically committed through Travis CI.\n\n[ci skip]", + content=dependencies, sha=sha, committer=InputGitAuthor("ace3mod", "ace3mod@gmail.com") + #, branch="travisForDocs" # Debug + ) + print("Dependencies successfully updated.") + else: + print("Dependencies skipped - no change.") + def main(): print("Obtaining token ...") try: token = os.environ["GH_TOKEN"] + repo = Github(token).get_repo(REPOPATH) except: print("Could not obtain token.") print(traceback.format_exc()) return 1 else: - print("done.") + print("Token sucessfully obtained.") print("\nUpdating translation issue ...") try: - update_translations(token) + update_translations(repo) except: print("Failed to update translation issue.") print(traceback.format_exc()) return 1 else: - print("done.") + print("Translation issue successfully updated.") + + print("\nUpdating dependencies list ...") + try: + update_dependencies(repo) + except: + print("Failed to update dependencies.") + print(traceback.format_exc()) + return 1 return 0 diff --git a/tools/extract_dependencies.py b/tools/extract_dependencies.py index 960c38ebcd..3dbc0aca46 100644 --- a/tools/extract_dependencies.py +++ b/tools/extract_dependencies.py @@ -16,12 +16,13 @@ def get_dependencies(line): def main(): - print(""" - #################################### - # Extract ACE3 Module Dependencies # - # (for Jekyll include) # - #################################### - """) + if "--markdown" not in sys.argv: + print(""" + #################################### + # Extract ACE3 Module Dependencies # + # (for Jekyll include) # + #################################### + """) scriptpath = os.path.realpath(__file__) projectpath = os.path.dirname(os.path.dirname(scriptpath)) @@ -44,40 +45,48 @@ def main(): # Open config.cpp file and extract dependencies data = [] - with open(os.path.join(addonspath, folder, "config.cpp")) as file: - match = False - for line in file: - # One-line - if not match and re.match(r"\s+requiredAddons\[\]\ = {.+?};", line): - data += get_dependencies(line) - break - # Multi-line - else: - if re.match(r"\s+requiredAddons\[\]\ = {", line): - # First line - match = True + configfile = os.path.join(addonspath, folder, "config.cpp") + if os.path.exists(configfile): + with open(os.path.join(addonspath, folder, "config.cpp")) as file: + match = False + for line in file: + # One-line + if not match and re.match(r"\s+requiredAddons\[\]\ = {.+?};", line): data += get_dependencies(line) - continue - elif match and re.match(r"\s+};", line): - # Final line - data += get_dependencies(line) - match = False break - elif match: - # All lines between - data += get_dependencies(line) - continue + # Multi-line + else: + if re.match(r"\s+requiredAddons\[\]\ = {", line): + # First line + match = True + data += get_dependencies(line) + continue + elif match and re.match(r"\s+};", line): + # Final line + data += get_dependencies(line) + match = False + break + elif match: + # All lines between + data += get_dependencies(line) + continue data = "`, `".join(data) data = "`{}`".format(data) - print("{}: {}".format(folder,data)) + + jekyll_statement = "".join([ + "{% if include.component == \"" + folder + "\" %}\n", + "{}\n".format(data), + "{% endif %}\n" + ]) with open(dependenciespath, "a", newline="\n") as file: - file.writelines([ - "{% if include.component == \"" + folder + "\" %}\n", - "{}\n".format(data), - "{% endif %}\n\n", - ]) + file.writelines([jekyll_statement, "\n"]) + + if "--markdown" not in sys.argv: + print("{}: {}".format(folder,data)) + else: + print(jekyll_statement) if __name__ == "__main__":