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