Skip to content

Commit 910e2e3

Browse files
committed
nix: add updater for partftpy
1 parent f356ef9 commit 910e2e3

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

contrib/package/nix/partftpy/default.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
fetchurl,
55
setuptools,
66
}:
7+
let
8+
pinData = lib.importJSON ./pin.json;
9+
in
710

811
buildPythonPackage rec {
912
pname = "partftpy";
10-
version = "0.4.0";
13+
inherit (pinData) version;
1114
pyproject = true;
1215

1316
src = fetchurl {
14-
url = "https://github.com/9001/partftpy/releases/download/v0.4.0/partftpy-0.4.0.tar.gz";
15-
hash = "sha256-5Q2zyuJ892PGZmb+YXg0ZPW/DK8RDL1uE0j5HPd4We0=";
17+
inherit (pinData) url hash;
1618
};
1719

1820
build-system = [ setuptools ];

contrib/package/nix/partftpy/pin.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"url": "https://github.com/9001/partftpy/releases/download/v0.4.0/partftpy-0.4.0.tar.gz",
3+
"version": "0.4.0",
4+
"hash": "sha256-5Q2zyuJ892PGZmb+YXg0ZPW/DK8RDL1uE0j5HPd4We0="
5+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
3+
# Update the Nix package pin
4+
#
5+
# Usage: ./update.sh
6+
7+
import base64
8+
import json
9+
import hashlib
10+
import sys
11+
from pathlib import Path
12+
13+
OUTPUT_FILE = Path("pin.json")
14+
TARGET_ASSET = lambda version: f"partftpy-{version}.tar.gz"
15+
HASH_TYPE = "sha256"
16+
LATEST_RELEASE_URL = "https://api.github.com/repos/9001/partftpy/releases/latest"
17+
18+
19+
def get_formatted_hash(binary):
20+
hasher = hashlib.new("sha256")
21+
hasher.update(binary)
22+
asset_hash = hasher.digest()
23+
encoded_hash = base64.b64encode(asset_hash).decode("ascii")
24+
return f"{HASH_TYPE}-{encoded_hash}"
25+
26+
27+
def remote_release_pin():
28+
import requests
29+
30+
response = requests.get(LATEST_RELEASE_URL).json()
31+
version = response["tag_name"].lstrip("v")
32+
asset_info = [a for a in response["assets"] if a["name"] == TARGET_ASSET(version)][0]
33+
download_url = asset_info["browser_download_url"]
34+
asset = requests.get(download_url)
35+
formatted_hash = get_formatted_hash(asset.content)
36+
37+
result = {"url": download_url, "version": version, "hash": formatted_hash}
38+
return result
39+
40+
41+
def main():
42+
result = remote_release_pin()
43+
44+
print(result)
45+
json_result = json.dumps(result, indent=4)
46+
OUTPUT_FILE.write_text(json_result)
47+
48+
49+
if __name__ == "__main__":
50+
main()

0 commit comments

Comments
 (0)