|
2 | 2 | # 2.0, and the BSD License. See the LICENSE file in the root of this repository |
3 | 3 | # for complete details. |
4 | 4 |
|
| 5 | +# /// script |
| 6 | +# dependencies = [ |
| 7 | +# "click", |
| 8 | +# ] |
| 9 | +# /// |
5 | 10 |
|
6 | | -import getpass |
7 | | -import glob |
8 | | -import io |
9 | | -import json |
10 | | -import os |
11 | 11 | import subprocess |
12 | | -import time |
13 | | -import zipfile |
14 | 12 |
|
15 | 13 | import click |
16 | 14 |
|
17 | | -import requests |
18 | | - |
19 | 15 |
|
20 | 16 | def run(*args, **kwargs): |
21 | 17 | print("[running] {}".format(list(args))) |
22 | 18 | subprocess.check_call(list(args), **kwargs) |
23 | 19 |
|
24 | 20 |
|
25 | | -def wait_for_build_complete_github_actions(session, token, run_url): |
26 | | - while True: |
27 | | - response = session.get( |
28 | | - run_url, |
29 | | - headers={ |
30 | | - "Content-Type": "application/json", |
31 | | - "Authorization": "token {}".format(token), |
32 | | - }, |
33 | | - ) |
34 | | - response.raise_for_status() |
35 | | - if response.json()["conclusion"] is not None: |
36 | | - break |
37 | | - time.sleep(3) |
38 | | - |
39 | | - |
40 | | -def download_artifacts_github_actions(session, token, run_url): |
41 | | - response = session.get( |
42 | | - run_url, |
43 | | - headers={ |
44 | | - "Content-Type": "application/json", |
45 | | - "Authorization": "token {}".format(token), |
46 | | - }, |
47 | | - ) |
48 | | - response.raise_for_status() |
49 | | - |
50 | | - response = session.get( |
51 | | - response.json()["artifacts_url"], |
52 | | - headers={ |
53 | | - "Content-Type": "application/json", |
54 | | - "Authorization": "token {}".format(token), |
55 | | - }, |
56 | | - ) |
57 | | - response.raise_for_status() |
58 | | - paths = [] |
59 | | - for artifact in response.json()["artifacts"]: |
60 | | - response = session.get( |
61 | | - artifact["archive_download_url"], |
62 | | - headers={ |
63 | | - "Content-Type": "application/json", |
64 | | - "Authorization": "token {}".format(token), |
65 | | - }, |
66 | | - ) |
67 | | - with zipfile.ZipFile(io.BytesIO(response.content)) as z: |
68 | | - for name in z.namelist(): |
69 | | - if not name.endswith(".whl"): |
70 | | - continue |
71 | | - p = z.open(name) |
72 | | - out_path = os.path.join( |
73 | | - os.path.dirname(__file__), |
74 | | - "dist", |
75 | | - os.path.basename(name), |
76 | | - ) |
77 | | - with open(out_path, "wb") as f: |
78 | | - f.write(p.read()) |
79 | | - paths.append(out_path) |
80 | | - return paths |
81 | | - |
82 | | - |
83 | | -def build_github_actions_wheels(token, version): |
84 | | - session = requests.Session() |
85 | | - |
86 | | - response = session.post( |
87 | | - "https://api.github.com/repos/pyca/pynacl/actions/workflows/" |
88 | | - "wheel-builder.yml/dispatches", |
89 | | - headers={ |
90 | | - "Content-Type": "application/json", |
91 | | - "Accept": "application/vnd.github.v3+json", |
92 | | - "Authorization": "token {}".format(token), |
93 | | - }, |
94 | | - data=json.dumps({"ref": "master", "inputs": {"version": version}}), |
95 | | - ) |
96 | | - response.raise_for_status() |
97 | | - |
98 | | - # Give it a few seconds for the run to kick off. |
99 | | - time.sleep(5) |
100 | | - response = session.get( |
101 | | - ( |
102 | | - "https://api.github.com/repos/pyca/pynacl/actions/workflows/" |
103 | | - "wheel-builder.yml/runs?event=repository_dispatch" |
104 | | - ), |
105 | | - headers={ |
106 | | - "Content-Type": "application/json", |
107 | | - "Authorization": "token {}".format(token), |
108 | | - }, |
109 | | - ) |
110 | | - response.raise_for_status() |
111 | | - run_url = response.json()["workflow_runs"][0]["url"] |
112 | | - wait_for_build_complete_github_actions(session, token, run_url) |
113 | | - return download_artifacts_github_actions(session, token, run_url) |
114 | | - |
115 | | - |
116 | 21 | @click.command() |
117 | 22 | @click.argument("version") |
118 | 23 | def release(version): |
119 | 24 | """ |
120 | 25 | ``version`` should be a string like '0.4' or '1.0'. |
121 | 26 | """ |
122 | | - github_token = getpass.getpass("Github person access token: ") |
123 | | - |
124 | 27 | run("git", "tag", "-s", version, "-m", "{} release".format(version)) |
125 | | - run("git", "push", "--tags") |
126 | | - |
127 | | - run("python", "setup.py", "sdist") |
128 | | - |
129 | | - sdist = glob.glob("dist/PyNaCl-{}*".format(version)) |
130 | | - |
131 | | - github_actions_wheel_paths = build_github_actions_wheels( |
132 | | - github_token, version |
133 | | - ) |
134 | | - |
135 | | - run("twine", "upload", *github_actions_wheel_paths) |
136 | | - run("twine", "upload", "-s", *sdist) |
| 28 | + run("git", "push", "git@github.com:pyca/pynacl.git", version) |
137 | 29 |
|
138 | 30 |
|
139 | 31 | if __name__ == "__main__": |
|
0 commit comments