mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Run documentation dependencies extractor on Travis deployment
This commit is contained in:
parent
d1d23c55bc
commit
2182b2c742
@ -18,7 +18,7 @@ script:
|
|||||||
fi
|
fi
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- secure: KcJQbknBOdC5lA4nFGKPXVRVIGLDXDRzC8XkHuXJCE9pIR/wbxbkvx8fHKcC6SC9eHgzneC3+o4m4+CjIbVvIwDgslRbJ8Y59i90ncONmdoRx1HUYHwuYWVZm9HJFjCsIbrEqhSyyKS+PB3WZVOLbErtNHsgS8f43PTh5Ujg7Vg=
|
- secure: cdxkn5cAx+s1C9Ne5m+odEhde1uuSg6XGMDgepN4DwSAJwtMnUv3ZmDebd5YJC1raZJdep+n09Cj0GoTNICQRkco50DxHKHYNad41wetY0tn0cs9gmPYzyFE5q4vuWiQ47dlGhQQ7IJDyX0nU++gG5E50/PhlZfebdedGSprN/4=
|
||||||
notifications:
|
notifications:
|
||||||
slack:
|
slack:
|
||||||
rooms:
|
rooms:
|
||||||
|
@ -12,7 +12,7 @@ import sys
|
|||||||
import shutil
|
import shutil
|
||||||
import traceback
|
import traceback
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
from pygithub3 import Github
|
from github import Github, InputGitAuthor
|
||||||
|
|
||||||
|
|
||||||
TRANSLATIONISSUE = 367
|
TRANSLATIONISSUE = 367
|
||||||
@ -21,39 +21,69 @@ TRANSLATIONBODY = """**[ACE3 Translation Guide](http://ace3mod.com/wiki/developm
|
|||||||
{}
|
{}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DEPENDENCIESPATH = "docs/_includes/dependencies_list.md"
|
||||||
|
|
||||||
REPOUSER = "acemod"
|
REPOUSER = "acemod"
|
||||||
REPONAME = "ACE3"
|
REPONAME = "ACE3"
|
||||||
REPOPATH = "{}/{}".format(REPOUSER,REPONAME)
|
REPOPATH = "{}/{}".format(REPOUSER,REPONAME)
|
||||||
|
|
||||||
|
|
||||||
def update_translations(token):
|
def update_translations(repo):
|
||||||
diag = sp.check_output(["python3", "tools/stringtablediag.py", "--markdown"])
|
diag = sp.check_output(["python3", "tools/stringtablediag.py", "--markdown"])
|
||||||
diag = str(diag, "utf-8")
|
diag = str(diag, "utf-8")
|
||||||
repo = Github(token).get_repo(REPOPATH)
|
|
||||||
issue = repo.get_issue(TRANSLATIONISSUE)
|
issue = repo.get_issue(TRANSLATIONISSUE)
|
||||||
issue.edit(body=TRANSLATIONBODY.format(diag))
|
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():
|
def main():
|
||||||
print("Obtaining token ...")
|
print("Obtaining token ...")
|
||||||
try:
|
try:
|
||||||
token = os.environ["GH_TOKEN"]
|
token = os.environ["GH_TOKEN"]
|
||||||
|
repo = Github(token).get_repo(REPOPATH)
|
||||||
except:
|
except:
|
||||||
print("Could not obtain token.")
|
print("Could not obtain token.")
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
print("done.")
|
print("Token sucessfully obtained.")
|
||||||
|
|
||||||
print("\nUpdating translation issue ...")
|
print("\nUpdating translation issue ...")
|
||||||
try:
|
try:
|
||||||
update_translations(token)
|
update_translations(repo)
|
||||||
except:
|
except:
|
||||||
print("Failed to update translation issue.")
|
print("Failed to update translation issue.")
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return 1
|
return 1
|
||||||
else:
|
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
|
return 0
|
||||||
|
|
||||||
|
@ -16,12 +16,13 @@ def get_dependencies(line):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("""
|
if "--markdown" not in sys.argv:
|
||||||
####################################
|
print("""
|
||||||
# Extract ACE3 Module Dependencies #
|
####################################
|
||||||
# (for Jekyll include) #
|
# Extract ACE3 Module Dependencies #
|
||||||
####################################
|
# (for Jekyll include) #
|
||||||
""")
|
####################################
|
||||||
|
""")
|
||||||
|
|
||||||
scriptpath = os.path.realpath(__file__)
|
scriptpath = os.path.realpath(__file__)
|
||||||
projectpath = os.path.dirname(os.path.dirname(scriptpath))
|
projectpath = os.path.dirname(os.path.dirname(scriptpath))
|
||||||
@ -44,40 +45,48 @@ def main():
|
|||||||
|
|
||||||
# Open config.cpp file and extract dependencies
|
# Open config.cpp file and extract dependencies
|
||||||
data = []
|
data = []
|
||||||
with open(os.path.join(addonspath, folder, "config.cpp")) as file:
|
configfile = os.path.join(addonspath, folder, "config.cpp")
|
||||||
match = False
|
if os.path.exists(configfile):
|
||||||
for line in file:
|
with open(os.path.join(addonspath, folder, "config.cpp")) as file:
|
||||||
# One-line
|
match = False
|
||||||
if not match and re.match(r"\s+requiredAddons\[\]\ = {.+?};", line):
|
for line in file:
|
||||||
data += get_dependencies(line)
|
# One-line
|
||||||
break
|
if not match and re.match(r"\s+requiredAddons\[\]\ = {.+?};", line):
|
||||||
# Multi-line
|
|
||||||
else:
|
|
||||||
if re.match(r"\s+requiredAddons\[\]\ = {", line):
|
|
||||||
# First line
|
|
||||||
match = True
|
|
||||||
data += get_dependencies(line)
|
data += get_dependencies(line)
|
||||||
continue
|
|
||||||
elif match and re.match(r"\s+};", line):
|
|
||||||
# Final line
|
|
||||||
data += get_dependencies(line)
|
|
||||||
match = False
|
|
||||||
break
|
break
|
||||||
elif match:
|
# Multi-line
|
||||||
# All lines between
|
else:
|
||||||
data += get_dependencies(line)
|
if re.match(r"\s+requiredAddons\[\]\ = {", line):
|
||||||
continue
|
# 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 = "`, `".join(data)
|
||||||
data = "`{}`".format(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:
|
with open(dependenciespath, "a", newline="\n") as file:
|
||||||
file.writelines([
|
file.writelines([jekyll_statement, "\n"])
|
||||||
"{% if include.component == \"" + folder + "\" %}\n",
|
|
||||||
"{}\n".format(data),
|
if "--markdown" not in sys.argv:
|
||||||
"{% endif %}\n\n",
|
print("{}: {}".format(folder,data))
|
||||||
])
|
else:
|
||||||
|
print(jekyll_statement)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user