@@ -95,6 +95,102 @@ def fetch_github_actions_artifacts(token, version):
9595 return download_artifacts_github_actions (session , token , run_url )
9696
9797
98+ def wait_for_build_complete_circleci (session , token , pipeline_id ):
99+ while True :
100+ response = session .get (
101+ f"https://circleci.com/api/v2/pipeline/{ pipeline_id } /workflow" ,
102+ headers = {
103+ "Circle-Token" : token ,
104+ },
105+ )
106+ response .raise_for_status ()
107+ if response .json ()["status" ] == "success" :
108+ break
109+ time .sleep (3 )
110+
111+
112+ def download_artifacts_circleci (session , urls ):
113+ paths = []
114+ for url in urls :
115+ name = url .split ("/" )[- 1 ]
116+ response = session .get (
117+ url ,
118+ headers = {},
119+ )
120+ out_path = os .path .join (
121+ os .path .dirname (__file__ ),
122+ "dist" ,
123+ os .path .basename (name ),
124+ )
125+ with open (out_path , "wb" ) as f :
126+ f .write (response .content )
127+ paths .append (out_path )
128+ return paths
129+
130+
131+ def fetch_circleci_artifacts (token , version ):
132+ session = requests .Session ()
133+
134+ response = session .get (
135+ "https://circleci.com/api/v2/pipeline?org-slug=gh/pyca" ,
136+ headers = {"Circle-Token" : token },
137+ )
138+ response .raise_for_status ()
139+ pipeline_id = None
140+ for item in response .json ()["items" ]:
141+ if item ["project_slug" ] == "gh/pyca/cryptography" :
142+ if item ["vcs" ].get ("tag" , None ) == version :
143+ pipeline_id = item ["id" ]
144+ break
145+
146+ if pipeline_id is None :
147+ raise ValueError (
148+ "Could not find a pipeline for version {0}" .format (version )
149+ )
150+
151+ wait_for_build_complete_circleci (session , token , pipeline_id )
152+ urls = fetch_circleci_artifact_urls (session , token , item ["id" ])
153+ return download_artifacts_circleci (session , urls )
154+
155+
156+ def fetch_circleci_artifact_urls (session , token , pipeline_id ):
157+ response = session .get (
158+ f"https://circleci.com/api/v2/pipeline/{ pipeline_id } /workflow" ,
159+ headers = {"Circle-Token" : token },
160+ )
161+ response .raise_for_status ()
162+ workflow_id = response .json ()["items" ][0 ]["id" ]
163+ job_response = session .get (
164+ f"https://circleci.com/api/v2/workflow/{ workflow_id } /job" ,
165+ headers = {"Circle-Token" : token },
166+ )
167+ job_response .raise_for_status ()
168+ artifact_urls = []
169+ for job in job_response .json ()["items" ]:
170+ urls = fetch_circleci_artifact_url_from_job (
171+ session , token , job ["job_number" ]
172+ )
173+ artifact_urls .extend (urls )
174+
175+ return artifact_urls
176+
177+
178+ def fetch_circleci_artifact_url_from_job (session , token , job ):
179+ response = session .get (
180+ f"https://circleci.com/api/v2/project/gh/pyca/cryptography/"
181+ f"{ job } /artifacts" ,
182+ headers = {"Circle-Token" : token },
183+ )
184+ response .raise_for_status ()
185+ urls = []
186+ for item in response .json ()["items" ]:
187+ url = item .get ("url" , None )
188+ if url is not None :
189+ urls .append (url )
190+
191+ return urls
192+
193+
98194@click .command ()
99195@click .argument ("version" )
100196def release (version ):
@@ -106,7 +202,12 @@ def release(version):
106202 f"https://github.com/settings/tokens/new?"
107203 f"description={ version } &scopes=repo"
108204 )
205+ print (
206+ "Get a CircleCI token at: "
207+ "https://app.circleci.com/settings/user/tokens"
208+ )
109209 github_token = getpass .getpass ("Github person access token: " )
210+ circle_token = getpass .getpass ("CircleCI token: " )
110211
111212 # Tag and push the tag (this will trigger the wheel builder in Actions)
112213 run ("git" , "tag" , "-s" , version , "-m" , "{0} release" .format (version ))
@@ -116,9 +217,13 @@ def release(version):
116217 github_actions_artifact_paths = fetch_github_actions_artifacts (
117218 github_token , version
118219 )
220+ # Download wheels from CircleCI
221+ circle_artifact_paths = fetch_circleci_artifacts (circle_token , version )
222+
223+ artifact_paths = github_actions_artifact_paths + circle_artifact_paths
119224
120225 # Upload wheels and sdist
121- run ("twine" , "upload" , * github_actions_artifact_paths )
226+ run ("twine" , "upload" , * artifact_paths )
122227
123228
124229if __name__ == "__main__" :
0 commit comments