-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.py
More file actions
44 lines (34 loc) · 1.11 KB
/
Build.py
File metadata and controls
44 lines (34 loc) · 1.11 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
import requests
import json
from datetime import datetime, timezone, timedelta
owner = "mifongjvav"
repo = "SenseiPlus"
version = "3.0.1"
def get_latest_commit_sha(owner_func, repo_func, short=True, branch=None):
if branch:
url = f"https://api.github.com/repos/{owner_func}/{repo_func}/commits/{branch}"
else:
url = f"https://api.github.com/repos/{owner_func}/{repo_func}/commits"
response = requests.get(url, verify=False)
response.raise_for_status()
if branch:
sha = response.json()["sha"]
else:
sha = response.json()[0]["sha"]
if short:
return sha[:7]
return sha
def get_build_date():
# UTC+8 时区
utc8 = timezone(timedelta(hours=8))
now_utc8 = datetime.now(utc8)
return now_utc8.strftime("%Y-%m-%d %H:%M:%S")
short_sha = get_latest_commit_sha(owner, repo, short=True)
build_info = {
"commit": short_sha,
"build_date": get_build_date(),
"version": version
}
with open("build_info.json", "w", encoding="utf-8") as f:
json.dump(build_info, f, indent=4, ensure_ascii=False)
print("✅ 已生成 build_info.json")