-
Notifications
You must be signed in to change notification settings - Fork 18
/
build_plugin.py
71 lines (55 loc) · 2.4 KB
/
build_plugin.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import json
import yaml
import argparse
import re
def extract_target_framework(csproj_path):
with open(csproj_path, "r") as file:
content = file.read()
target_framework_match = re.compile(r"<TargetFramework>(.*?)<\/TargetFramework>", re.IGNORECASE).search(content)
target_frameworks_match = re.compile(r"<TargetFrameworks>(.*?)<\/TargetFrameworks>", re.IGNORECASE).search(content)
if target_framework_match:
return target_framework_match.group(1)
elif target_frameworks_match:
return target_frameworks_match.group(1).split(";")[0] # Return the first framework
else:
return None
parser = argparse.ArgumentParser()
parser.add_argument("--repo", required=True)
parser.add_argument("--version", required=True)
parser.add_argument("--tag", required=True)
parser.add_argument("--prerelease", default=False)
opts = parser.parse_args()
framework = extract_target_framework("./Shokofin/Shokofin.csproj")
version = opts.version
tag = opts.tag
prerelease = bool(opts.prerelease)
artifact_dir = os.path.join(os.getcwd(), "artifacts")
if not os.path.exists(artifact_dir):
os.mkdir(artifact_dir)
jellyfin_repo_file="./manifest.json"
jellyfin_repo_url=f"https://github.com/{opts.repo}/releases/download"
# Add changelog to the build yaml before we generate the release.
build_file = "./build.yaml"
with open(build_file, "r") as file:
data = yaml.safe_load(file)
if "changelog" in data:
if "CHANGELOG" in os.environ:
data["changelog"] = os.environ["CHANGELOG"].strip()
else:
data["changelog"] = ""
with open(build_file, "w") as file:
yaml.dump(data, file, sort_keys=False)
zipfile=os.popen("jprm --verbosity=debug plugin build \".\" --output=\"%s\" --version=\"%s\" --dotnet-framework=\"%s\"" % (artifact_dir, version, framework)).read().strip()
jellyfin_plugin_release_url=f"{jellyfin_repo_url}/{tag}/shoko_{version}.zip"
os.system("jprm repo add --plugin-url=%s %s %s" % (jellyfin_plugin_release_url, jellyfin_repo_file, zipfile))
# Compact the unstable manifest after building, so it only contains the last 5 versions.
if prerelease:
with open(jellyfin_repo_file, "r") as file:
data = json.load(file)
for item in data:
if "versions" in item and len(item["versions"]) > 5:
item["versions"] = item["versions"][:5]
with open(jellyfin_repo_file, "w") as file:
json.dump(data, file, indent=4)
print(version)