-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelease
More file actions
executable file
·84 lines (70 loc) · 2.52 KB
/
release
File metadata and controls
executable file
·84 lines (70 loc) · 2.52 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import json
from glob import glob
from os import environ, path
import requests
import sys
import subprocess
from ruamel.yaml import YAML
from rich.console import Console
con = Console()
meta = YAML(typ="safe", pure=True).load(open("zenodo.yml"))
headers = {"Content-Type": "application/json"}
def check_status(r):
code = r.status_code
if code // 100 != 2:
raise RuntimeError(f"Request failed with code {code}! \n{r.json()}")
if __name__ == "__main__":
if "ZENODO_TOKEN" not in environ:
raise ValueError("ZENODO_TOKEN env variable needs to be set!")
token = environ["ZENODO_TOKEN"]
params = {"access_token": token}
version = meta["version"]
meta["title"] = "MICOM model databases version %s" % version
con.log(f"[green] Starting release for version {version}.")
con.log(":hammer: Creating new Zenodo deposition...")
r = requests.post(
"https://zenodo.org/api/deposit/depositions",
params=params,
json={},
headers=headers
)
check_status(r)
deposition = r.json()
bucket_url = deposition["links"]["bucket"]
con.log(f"[green]Successfully created the new deposition {deposition['id']}.")
con.log(":hammer: Uploading metadata...")
r = requests.put(
"https://zenodo.org/api/deposit/depositions/%s" % deposition["id"],
params=params,
data=json.dumps({"metadata": meta}),
headers=headers
)
check_status(r)
con.log("[green]Uploaded metadata.")
files = glob(f"recipes/*/databases/*_{version}.qza")
uploads = {}
for fi in files:
name = path.basename(fi)
con.log(f":hammer: Uploading {name}...")
with open(fi, "rb") as fp:
r = requests.put(
"%s/%s" % (bucket_url, name),
data=fp,
params=params,
)
check_status(r)
con.log(f"[green]Finished uploading {name}.")
uploads[name] = r.json()
con.log(":hammer: Publishing deposition...")
r = requests.post(
"https://zenodo.org/api/deposit/depositions/%s/actions/publish" % deposition["id"],
params=params
)
check_status(r)
final = r.json()
with open(path.join("release_notes", f"{version}.txt"), "w") as rn:
rn.write(f"MICOM model databases version {version}.\n\n>> {final['doi_url']}<<\n")
con.log(f"[green]Published the new release to {final['doi_url']}")
with open(path.join("release_notes", version + ".json"), "w") as log:
json.dump(final, log, indent=4)