release_diff.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import subprocess
  2. import os
  3. import git
  4. import sys
  5. from release_helper import *
  6. repo = git.Repo(REPO_PATH)
  7. commit_head = repo.head.commit.hexsha
  8. pkgReleases = PackageReleaseList(PACKAGE_RELEASE_PATH)
  9. # argv[1] is the commit hash
  10. if len(sys.argv) > 1:
  11. commit_diff = sys.argv[1]
  12. else:
  13. print("No commit hash specified")
  14. commit_diff = "f8b529a956da57d8623247bea594e65469cac1c5"
  15. tag = commit_diff # 替换为您要使用的标签
  16. output_file = "diff.md" # 替换为您要写入的文件名
  17. f = open(output_file, "w")
  18. # checkout to the commit_diff
  19. repo.git.checkout(commit_diff)
  20. pkgReleases_diff = PackageReleaseList(PACKAGE_RELEASE_PATH)
  21. # checkout master
  22. repo.git.checkout("master")
  23. f.write(f"# Diff from PikaPython {commit_diff}\n")
  24. f.write(f"## package diff\n")
  25. f.write("|package|state|version|\n")
  26. f.write("|---|---|---|\n")
  27. # find new released package and package version
  28. for pkg in pkgReleases.packages:
  29. # find pkg in pkgReleases_diff
  30. pkg_diff = pkgReleases_diff.findPackage(pkg.name)
  31. if None == pkg_diff:
  32. # print("New package: " + pkg.name + pkg.latestVersion().version)
  33. out_str = f"|{pkg.name}| Create | {pkg.latestVersion().version}|"
  34. print(out_str)
  35. f.write(out_str + '\n')
  36. continue
  37. pkg_diff = pkgReleases_diff.findPackage(pkg.name)
  38. if pkg_diff.latestVersion().version != pkg.latestVersion().version:
  39. out_str = f"|{pkg.name}| Update | {pkg_diff.latestVersion().version} --> {pkg.latestVersion().version}|"
  40. print(out_str)
  41. f.write(out_str + '\n')
  42. # 构建 git log 命令并调用 subprocess 执行
  43. git_log_cmd = f"git log {tag}..HEAD --pretty=format:%s"
  44. result = subprocess.run(git_log_cmd, stdout=subprocess.PIPE, shell=True)
  45. # 从结果中获取输出并将其写入文件
  46. output_str = result.stdout.decode("utf-8").replace('\n', '\n\n')
  47. f.write('## git diff\n')
  48. f.write(output_str)
  49. f.close()
  50. exit()