2024-05-19 16:01:54 +03:00
|
|
|
import subprocess
|
|
|
|
from zipfile import ZipFile, ZIP_DEFLATED as COMPRESS_TYPE
|
|
|
|
import shutil
|
|
|
|
import os
|
2024-05-23 21:02:39 +03:00
|
|
|
import tomllib
|
2024-06-02 00:11:46 +03:00
|
|
|
import json
|
|
|
|
from dataclasses import dataclass
|
2024-05-23 21:02:39 +03:00
|
|
|
|
|
|
|
cargo_manifest = tomllib.load(open("noita-proxy/Cargo.toml", "rb"))
|
|
|
|
version = cargo_manifest["package"]["version"]
|
|
|
|
|
|
|
|
print("Current version: ", version)
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
COMPRESS_LEVEL = 9
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class PullRequest:
|
|
|
|
number: int
|
|
|
|
author: str
|
|
|
|
title: str
|
|
|
|
|
|
|
|
def __str__(self):
|
2024-06-02 00:37:22 +03:00
|
|
|
return f"{self.title} by @{self.author} in #{self.number}"
|
2024-06-02 00:11:46 +03:00
|
|
|
|
2024-05-22 12:48:21 +03:00
|
|
|
def try_remove(path):
|
|
|
|
try:
|
|
|
|
os.remove(path)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
class ReleaseNotes:
|
|
|
|
def __init__(self):
|
|
|
|
self.md = []
|
|
|
|
|
|
|
|
def title(self, t):
|
|
|
|
self.md.append(f"## {t}\n")
|
|
|
|
|
|
|
|
def p(self, t):
|
|
|
|
self.md.append(f"\n{t}\n")
|
|
|
|
|
|
|
|
def l(self, t):
|
|
|
|
self.md.append(f"- {t}")
|
|
|
|
|
|
|
|
def gen_md(self):
|
|
|
|
return "\n".join(self.md)
|
|
|
|
|
|
|
|
def call_parse_json(args):
|
|
|
|
return json.loads(subprocess.check_output(args))
|
|
|
|
|
|
|
|
def check_release_exists(tag):
|
|
|
|
print("Checking if release exists:", tag)
|
|
|
|
ret = subprocess.call(["gh", "release", "view", tag])
|
|
|
|
exists = ret == 0
|
|
|
|
return exists
|
|
|
|
|
|
|
|
def get_last_release():
|
|
|
|
return call_parse_json(["gh", "release", "view", "--json", "publishedAt,name"])
|
|
|
|
|
|
|
|
def get_pull_requests_from(date):
|
|
|
|
parsed = call_parse_json(["gh", "pr", "list", "--state", "merged", "--search", "merged:>"+date, "--json", "number,title,author"])
|
|
|
|
return [PullRequest(entry["number"], entry["author"]["login"], entry["title"]) for entry in parsed]
|
|
|
|
|
2024-07-20 12:11:07 +03:00
|
|
|
def extract_steam_redist():
|
|
|
|
with ZipFile("redist/steam_dylib.zip", "r") as steam_dylib_zip:
|
|
|
|
steam_dylib_zip.extractall("target/tmp")
|
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
def make_release_assets():
|
|
|
|
print("Compiling Noita Proxy...")
|
|
|
|
|
|
|
|
os.chdir("noita-proxy")
|
|
|
|
|
2024-06-13 15:56:33 +03:00
|
|
|
subprocess.run(["cross", "build", "--profile", "release-lto", "--target", "x86_64-unknown-linux-gnu"], check=True)
|
|
|
|
subprocess.run(["cargo", "build", "--profile", "release-lto", "--target", "x86_64-pc-windows-gnu"], check=True)
|
2024-06-02 00:11:46 +03:00
|
|
|
|
|
|
|
os.chdir("..")
|
|
|
|
|
|
|
|
os.makedirs("target", exist_ok=True)
|
|
|
|
os.makedirs("target/tmp", exist_ok=True)
|
|
|
|
|
|
|
|
try_remove("target/noita-proxy-win.zip")
|
|
|
|
try_remove("target/noita-proxy-linux.zip")
|
|
|
|
try_remove("target/quant.ew.zip")
|
|
|
|
|
|
|
|
print("Extracting steam dylib...")
|
|
|
|
|
2024-07-20 12:11:07 +03:00
|
|
|
extract_steam_redist()
|
2024-06-02 00:11:46 +03:00
|
|
|
|
|
|
|
print("Writing win release...")
|
|
|
|
|
|
|
|
with ZipFile("target/noita-proxy-win.zip", "w") as release:
|
2024-06-13 15:56:33 +03:00
|
|
|
release.write("noita-proxy/target/x86_64-pc-windows-gnu/release-lto/noita-proxy.exe", arcname="noita_proxy.exe", compress_type=COMPRESS_TYPE, compresslevel=COMPRESS_LEVEL)
|
2024-06-02 00:11:46 +03:00
|
|
|
release.write("target/tmp/steam_api64.dll", arcname="steam_api64.dll", compress_type=COMPRESS_TYPE, compresslevel=COMPRESS_LEVEL)
|
|
|
|
|
|
|
|
print("Writing linux release...")
|
|
|
|
|
|
|
|
with ZipFile("target/noita-proxy-linux.zip", "w") as release:
|
2024-06-13 15:56:33 +03:00
|
|
|
release.write("noita-proxy/target/x86_64-unknown-linux-gnu/release-lto/noita-proxy", arcname="noita_proxy.x86_64", compress_type=COMPRESS_TYPE, compresslevel=COMPRESS_LEVEL)
|
2024-06-02 00:11:46 +03:00
|
|
|
release.write("target/tmp/libsteam_api.so", arcname="libsteam_api.so", compress_type=COMPRESS_TYPE, compresslevel=COMPRESS_LEVEL)
|
|
|
|
|
|
|
|
print("Writing mod release...")
|
|
|
|
|
|
|
|
shutil.make_archive("target/quant.ew", "zip", "quant.ew")
|
|
|
|
|
|
|
|
with ZipFile("target/quant.ew.zip", "a") as release:
|
|
|
|
release.writestr("files/version.lua", f'return "{version}"')
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
def main():
|
|
|
|
tag = "v"+version
|
|
|
|
if check_release_exists(tag):
|
|
|
|
print("Release already exists, exiting")
|
|
|
|
exit(1)
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
last_release = get_last_release()
|
|
|
|
print("Last release is:", last_release["name"])
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
pull_requests = get_pull_requests_from(last_release["publishedAt"])
|
|
|
|
print()
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
make_release_assets()
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
print()
|
|
|
|
print("Will release:", tag)
|
|
|
|
print("Accepted pull requests:")
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
for request in pull_requests:
|
|
|
|
print(request)
|
2024-05-22 12:48:21 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
print()
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
notes = ReleaseNotes()
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
notes.title("Noita Entangle Worlds "+tag)
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
notes.p("")
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
notes.title("Accepted pull requests")
|
2024-06-02 21:27:13 +03:00
|
|
|
if pull_requests:
|
|
|
|
for request in pull_requests:
|
|
|
|
notes.l(request)
|
|
|
|
else:
|
|
|
|
notes.p("No pull requests have been accepted in this release.")
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-12 19:07:03 +03:00
|
|
|
notes.title("Installation")
|
|
|
|
notes.p("Download and unpack `noita-proxy-win.zip` or `noita-proxy-linux.zip`, depending on your OS. After that, launch the proxy.")
|
|
|
|
notes.p("Proxy is able to download and install the mod automatically. There is no need to download the mod (`quant.ew.zip`) manually.")
|
2024-06-13 15:56:33 +03:00
|
|
|
notes.p("""You'll be prompted for a path to `noita.exe` when launching the proxy for the first time.
|
|
|
|
It should be detected automatically as long as you use steam version of the game and steam is launched.
|
2024-06-12 19:07:03 +03:00
|
|
|
""")
|
2024-06-20 14:54:27 +03:00
|
|
|
|
|
|
|
notes.title("Updating")
|
|
|
|
notes.p("There is a button in bottom-left corner on noita-proxy's main screen that allows to auto-update to a new version when one is available")
|
2024-06-12 19:07:03 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
print()
|
|
|
|
notes_path = "/tmp/rnotes.md"
|
|
|
|
with open(notes_path, "w") as f:
|
|
|
|
print(notes.gen_md(), file=f)
|
|
|
|
|
|
|
|
subprocess.check_call(["nano", notes_path])
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
title = input("Release title: ")
|
2024-05-19 16:01:54 +03:00
|
|
|
|
2024-06-16 23:53:13 +03:00
|
|
|
subprocess.call(["gh", "release", "create", tag, "--title", f"{tag} - {title}", "-F", notes_path, "./target/noita-proxy-linux.zip", "./target/noita-proxy-win.zip", "./target/quant.ew.zip"])
|
2024-05-23 21:02:39 +03:00
|
|
|
|
2024-06-02 00:11:46 +03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|