1#!/usr/bin/env nix-shell
2#! nix-shell -i python -p nix-prefetch-github python3Packages.githubkit
3import json
4import subprocess
5import sys
6
7from githubkit import GitHub, UnauthAuthStrategy
8from githubkit.versions.latest.models import (
9 Commit,
10 ContentSubmodule,
11 Tag,
12)
13
14DEPS_PATH: str = "./pkgs/by-name/ed/edopro/deps.nix"
15
16with GitHub(UnauthAuthStrategy()) as github:
17 edopro: Tag = github.rest.repos.list_tags("edo9300", "edopro").parsed_data[0]
18
19 # This dep is not versioned in any way and is why we check below to see if this is a new version.
20 irrlicht: Commit = github.rest.repos.list_commits(
21 "edo9300", "irrlicht1-8-4"
22 ).parsed_data[0]
23
24
25edopro_working_version: str = ""
26try:
27 with open(DEPS_PATH, "r") as file:
28 for line in file.readlines():
29 if "edopro-version" in line:
30 edopro_working_version = line.split('"')[1]
31except FileNotFoundError:
32 print("Error: Dep file not found.", file=sys.stderr)
33 exit(2)
34
35if edopro_working_version == "":
36 print("Working version is unbound", file=sys.stderr)
37 exit(5)
38
39if edopro_working_version == edopro.name:
40 print("Version is updated")
41 exit(0)
42
43
44def get_hash(owner: str, repo: str, rev: str, submodule: bool = False) -> str:
45 args: list[str] = ["nix-prefetch-github", owner, repo, "--rev", rev]
46
47 if submodule:
48 args.append("--fetch-submodules")
49
50 out: subprocess.CompletedProcess = subprocess.run(args, capture_output=True)
51 out_json = json.loads(out.stdout.decode())
52
53 return out_json["hash"]
54
55
56edopro_hash = get_hash("edo9300", "edopro", edopro.commit.sha, submodule=True)
57irrlicht_hash = get_hash("edo9300", "irrlicht1-8-4", irrlicht.sha)
58
59asset_legacy_hash: str = (
60 subprocess.run(
61 [
62 "nix-prefetch-url",
63 f"https://github.com/ProjectIgnis/edopro-assets/releases/download/{edopro.name}/ProjectIgnis-EDOPro-{edopro.name}-linux.tar.gz",
64 "--unpack",
65 ],
66 capture_output=True,
67 )
68 .stdout.decode()
69 .strip()
70)
71asset_hash: str = (
72 subprocess.run(
73 [
74 "nix",
75 "--extra-experimental-features",
76 "nix-command",
77 "hash",
78 "to-sri",
79 "--type",
80 "sha256",
81 asset_legacy_hash,
82 ],
83 capture_output=True,
84 )
85 .stdout.decode()
86 .strip()
87)
88
89
90with open(DEPS_PATH, "w") as file:
91 contents = f"""# This is automatically generated by the update script.
92# DO NOT MANUALLY EDIT.
93{{
94 assets-hash = "{asset_hash}";
95 edopro-version = "{edopro.name}";
96 edopro-rev = "{edopro.commit.sha}";
97 edopro-hash = "{edopro_hash}";
98 irrlicht-version = "{"1.9.0-unstable-" + irrlicht.commit.committer.date.strftime("%Y-%m-%d")}";
99 irrlicht-rev = "{irrlicht.sha}";
100 irrlicht-hash = "{irrlicht_hash}";
101}}
102"""
103
104 file.write(contents)