Repository navigation
Expand file tree
/
Copy pathrelease.py
More file actions
executable file
·97 lines (74 loc) · 3.07 KB
/
Copy pathrelease.py
File metadata and controls
executable file
·97 lines (74 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
# Helper script to create and publish a new python-chess release.
import os
import chess
import sys
import subprocess
def system(command):
print(command)
exit_code = os.system(command)
if exit_code != 0:
sys.exit(exit_code)
def check_git():
print("--- CHECK GIT ----------------------------------------------------")
system("git diff --exit-code")
system("git diff --cached --exit-code")
system("git fetch origin")
behind = int(subprocess.check_output(["git", "rev-list", "--count", "main..origin/main"]))
if behind > 0:
print(f"main is {behind} commit(s) behind origin/main")
sys.exit(1)
def test():
print("--- TEST ---------------------------------------------------------")
for python in ["3.11", "3.12", "3.13", "3.14", "3.15", "3.16"]:
system(f"uv run --locked --isolated --no-dev --python {python} python test.py")
system(f"uv run --locked --isolated --no-dev --python {python} python -m doctest README.rst")
def check_changelog():
print("--- CHECK CHANGELOG ----------------------------------------------")
with open("CHANGELOG.md", "r") as changelog_file:
changelog = changelog_file.read().splitlines()
heading = f"## v{chess.__version__}"
if heading not in changelog:
print(f"Not found: {heading}")
sys.exit(1)
def check_docs():
print("--- CHECK DOCS ---------------------------------------------------")
system("rm -rf dist")
system("uv build")
system("uv run --locked twine check --strict dist/*")
def tag_and_push():
print("--- TAG AND PUSH -------------------------------------------------")
tagname = f"v{chess.__version__}"
release_filename = f"release-{tagname}.txt"
if not os.path.exists(release_filename):
print(f">>> Creating {release_filename} ...")
in_section = False
with open(release_filename, "w") as release_txt, open("CHANGELOG.md", "r") as changelog_file:
headline = f"python-chess {tagname}"
release_txt.write(headline + os.linesep)
for line in changelog_file:
if line.rstrip() == f"## {tagname}":
in_section = True
elif line.startswith("## "):
in_section = False
elif in_section:
release_txt.write(line)
with open(release_filename, "r") as release_txt:
release = release_txt.read().strip() + os.linesep
print(release)
with open(release_filename, "w") as release_txt:
release_txt.write(release)
guessed_tagname = input(">>> Sure? Confirm tagname: ")
if guessed_tagname != tagname:
print(f"Actual tagname is: {tagname}")
sys.exit(1)
system(f"git tag {tagname} -s -F {release_filename}")
system(f"git push --atomic origin main {tagname}")
print("PyPI upload and GitHub release happen in CI, once all checks pass:")
print("https://github.com/niklasf/python-chess/actions")
if __name__ == "__main__":
check_docs()
test()
check_git()
check_changelog()
tag_and_push()