driazati commented on code in PR #14520:
URL: https://github.com/apache/tvm/pull/14520#discussion_r1160146021


##########
ci/jenkins/generate.py:
##########
@@ -150,14 +151,57 @@ def update_jenkinsfile(source: Path) -> ChangeData:
     return ChangeData(diff=diff, content=new_content, source=source, 
destination=destination)
 
 
+AUTOGENERATED_RE = re.compile(r'(^<!--- (?:END )?AUTOGENERATED DO NOT EDIT 
--->$)', re.MULTILINE)
+
+
+AUTOGENERATED_START_LINE = '<!--- AUTOGENERATED DO NOT EDIT --->'
+AUTOGENERATED_END_LINE = '<!--- END AUTOGENERATED DO NOT EDIT --->'
+
+
+BADGE_LINE_TEMPLATE = (
+    '[![{build_name}]'
+    
'(https://ci.tlcpack.ai/buildStatus/icon?job=tvm-{build_name}%2fmain&subject={build_name})]'
+    '(https://ci.tlcpack.ai/job/tvm-{build_name}/job/main/)'
+)
+
+def update_readme(sources):
+    readme_path = REPO_ROOT / "README.md"
+    with open(readme_path) as readme_f:
+        readme = readme_f.read()
+
+    parts = AUTOGENERATED_RE.split(readme)
+    if (len(parts) != 5 or
+        parts[1] != AUTOGENERATED_START_LINE or
+        parts[3] != AUTOGENERATED_END_LINE):
+        print(r"README.md didn't split properly: {parts!r}")
+        sys.exit(2)
+
+    def _to_jenkins_name(src):
+        """Produce the varying part of the name of the Jenkins build for a 
Jenkinsfile.
+
+        e.g. given path/to/foo_bar_jenkinsfile.groovy.j2, returns foo-bar to 
correspond to
+        a Jenkins build named tvm-foo-bar.
+        """
+        return str(src.stem)[:-len("_jenkinsfile.groovy")].replace("_", "-")
+
+    lines = (
+        [''] + # preserve leading \n
+        [BADGE_LINE_TEMPLATE.format(build_name=_to_jenkins_name(n)) for n in 
sorted(sources)] +
+        ['']  # preserve trailing \n
+    )
+    parts[2] = '\n'.join(lines)
+
+    with open(readme_path, "w") as readme_f:
+        readme_f.write(''.join(parts))
+
 if __name__ == "__main__":
     help = "Regenerate Jenkinsfile from template"
     parser = argparse.ArgumentParser(description=help)
     parser.add_argument("--force", action="store_true", help="always overwrite 
timestamp")
     parser.add_argument("--check", action="store_true", help="just verify the 
output didn't change")

Review Comment:
   Can you also integrate the stuff into `--check` so lint will error if the 
README hasn't been regenerated?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to