forked from chinapandaman/PyPDFForm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_release.py
51 lines (43 loc) · 1.39 KB
/
create_release.py
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
# -*- coding: utf-8 -*-
"""Creates a GitHub release."""
import os
import re
import sys
from getpass import getpass
import requests
if __name__ == "__main__":
with open("PyPDFForm/__init__.py", encoding="utf8") as f:
version = re.search(r'__version__ = "(.*?)"', f.read())
if version:
version = version.group(1)
latest_version = sys.argv[1].replace("(", "").replace(")", "")
print(f"Latest deployed version: v{latest_version}.")
if latest_version == version:
sys.exit(f"v{latest_version} is already deployed.")
print(f"Bumping to: v{version}")
token = os.environ.get("GITHUB_TOKEN")
if not token:
token = getpass("Enter GitHub Token: ")
else:
cont = input("Enter Yes to continue: ")
if cont != "Yes":
sys.exit("Aborted.")
url = "https://api.github.com/repos/chinapandaman/PyPDFForm/releases"
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
}
body = {
"tag_name": f"v{version}",
"name": f"v{version}",
"generate_release_notes": True,
}
response = requests.post(
url=url,
headers=headers,
json=body,
)
if response.status_code == 201:
print(f"Successfully deployed v{version}.")
else:
print(f"Failed deploying v{version}. Status code: {response.status_code}.")