1#!/usr/bin/env nix-shell
2#! nix-shell -i python -p "python3.withPackages (ps: with ps; [ ps.httpx ps.socksio ])"
3
4import json
5import os
6import pathlib
7import subprocess
8
9import httpx
10
11platforms = {
12 "x86_64-linux": "linux-amd64",
13 "aarch64-linux": "linux-aarch64",
14 "x86_64-darwin": "darwin-amd64",
15 "aarch64-darwin": "darwin-arm64",
16}
17
18if __name__ == "__main__":
19 headers = {}
20 token = os.getenv("GITHUB_TOKEN")
21 if token is not None:
22 headers["Authorization"] = "Bearer {}".format(token)
23
24 resp = httpx.get(
25 "https://api.github.com/repos/withered-magic/starpls/releases/latest",
26 headers=headers,
27 )
28
29 latest_release = resp.json().get("tag_name")
30 version = latest_release.removeprefix("v")
31
32 assets = {
33 "version": version,
34 "assets": {},
35 }
36
37 for k, v in platforms.items():
38 url = "https://github.com/withered-magic/starpls/releases/download/v{}/starpls-{}".format(
39 version, v
40 )
41
42 process = subprocess.run(
43 ["nix-prefetch-url", "--type", "sha256", url],
44 capture_output=True,
45 text=True,
46 )
47
48 process.check_returncode()
49
50 process = subprocess.run(
51 ["nix-hash", "--type", "sha256", "--to-sri", process.stdout.rstrip()],
52 capture_output=True,
53 text=True,
54 )
55
56 process.check_returncode()
57
58 hash = process.stdout.rstrip()
59 assets["assets"][k] = {
60 "url": url,
61 "hash": hash,
62 }
63
64 (pathlib.Path(__file__).parent / "manifest.json").write_text(
65 json.dumps(assets, indent=2) + "\n"
66 )