github.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. """
  3. WARNING!
  4. This script includes example code from the Lean Prover community, who
  5. used this repo to store the Zulip content as well as the code. We
  6. recommend to most folks to create a **separate** repo for your
  7. content, even if you are using Github to serve the content, and expect
  8. to convert this tool to a supported option based on that model.
  9. """
  10. from datetime import datetime
  11. import time, argparse, subprocess
  12. parser = argparse.ArgumentParser(description="Push/pull repo.")
  13. # resets the current repository to match origin/master
  14. def github_pull():
  15. print(subprocess.check_output(["git", "fetch", "origin", "master"]))
  16. print(subprocess.check_output(["git", "reset", "--hard", "origin/master"]))
  17. # commits changes in archive/ and pushes the current repository to origin/master
  18. def github_push():
  19. print(subprocess.check_output(["git", "add", "archive/*"]))
  20. print(subprocess.check_output(["git", "add", "_includes/archive_update.html"]))
  21. print(
  22. subprocess.check_output(
  23. [
  24. "git",
  25. "commit",
  26. "-m",
  27. "auto update: {}".format(
  28. datetime.utcfromtimestamp(time.time()).strftime(
  29. "%b %d %Y at %H:%M UTC"
  30. )
  31. ),
  32. ]
  33. )
  34. )
  35. print(subprocess.check_output(["git", "push"]))
  36. parser.add_argument(
  37. "-f",
  38. action="store_true",
  39. default=False,
  40. help="Pull from GitHub before updating. (Warning: could overwrite this script.)",
  41. )
  42. parser.add_argument(
  43. "-p", action="store_true", default=False, help="Push results to GitHub."
  44. )
  45. if results.f:
  46. github_pull()
  47. if results.p:
  48. github_push()