3636we want to only cache on a "pass" or "fail" status as these mean that Tuxsuite
3737actually completed its work and didnt timeout.
3838"""
39+
3940import argparse
4041import json
4142import os
4849# pylint: disable-next=import-error
4950import requests
5051
51- from utils import get_patches_hash , get_workflow_name_to_var_name , update_repository_variable
52+ from utils import (
53+ get_patches_hash ,
54+ get_workflow_name_to_var_name ,
55+ update_repository_variable ,
56+ )
5257
5358OWNER = "ClangBuiltLinux"
5459REPO = "continuous-integration2"
6368TIMEOUT = 64
6469
6570
66- class MalformedCacheError (Exception ):
67- ...
71+ class MalformedCacheError (Exception ): ...
6872
6973
7074def parse_args ():
@@ -107,17 +111,16 @@ def ___purge___cache___():
107111 list_response = requests .get (list_url , headers = headers , timeout = TIMEOUT )
108112 print (list_response .content )
109113 all_variables_keys = [
110- x ["name" ] for x in json .loads (list_response .content )["variables" ]
114+ x ["name" ]
115+ for x in json .loads (list_response .content )["variables" ]
111116 if x ["name" ].startswith ("_" )
112117 ]
113118
114119 for key in all_variables_keys :
115120 delete_url = (
116121 f"https://api.github.com/repos/{ OWNER } /{ REPO } /actions/variables/{ key } "
117122 )
118- delete_response = requests .delete (delete_url ,
119- headers = headers ,
120- timeout = TIMEOUT )
123+ delete_response = requests .delete (delete_url , headers = headers , timeout = TIMEOUT )
121124 if delete_response .status_code != 204 :
122125 print (f"ERROR: Couldn't delete cache entry with key { key } " )
123126 sys .exit (1 )
@@ -154,16 +157,19 @@ def get_repository_variable_or_none(name: str) -> Optional[dict]:
154157 return json .loads (as_dict ["value" ])
155158
156159
157- def create_repository_variable (name : str , linux_sha : str , clang_version : str ,
158- patches_hash : str ) -> None :
160+ def create_repository_variable (
161+ name : str , linux_sha : str , clang_version : str , patches_hash : str
162+ ) -> None :
159163 _url = f"https://api.github.com/repos/{ OWNER } /{ REPO } /actions/variables"
160164
161- _value = json .dumps ({
162- "linux_sha" : linux_sha ,
163- "clang_version" : clang_version ,
164- "patches_hash" : patches_hash ,
165- "build_status" : "presuite" ,
166- })
165+ _value = json .dumps (
166+ {
167+ "linux_sha" : linux_sha ,
168+ "clang_version" : clang_version ,
169+ "patches_hash" : patches_hash ,
170+ "build_status" : "presuite" ,
171+ }
172+ )
167173 data = {"name" : name , "value" : _value }
168174
169175 resp = requests .post (_url , headers = headers , json = data , timeout = TIMEOUT )
@@ -199,8 +205,10 @@ def create_repository_variable(name: str, linux_sha: str, clang_version: str,
199205 # pull down repo variable
200206 result = get_repository_variable_or_none (VAR_NAME )
201207 if result is None :
202- print (f"CACHE MISS: Did not find repo variable { VAR_NAME } "
203- f"from workflow_name: { args .workflow_name } . Creating it now." )
208+ print (
209+ f"CACHE MISS: Did not find repo variable { VAR_NAME } "
210+ f"from workflow_name: { args .workflow_name } . Creating it now."
211+ )
204212 create_repository_variable (
205213 VAR_NAME ,
206214 linux_sha = curr_sha ,
@@ -219,14 +227,19 @@ def create_repository_variable(name: str, linux_sha: str, clang_version: str,
219227 raise MalformedCacheError (
220228 f"The cache with key { VAR_NAME } based on workflow '{ args .workflow_name } ' "
221229 f"is one or more fields. It's missing: { missing_fields } \n "
222- f"The current cache looks as follows:\n { result } ." )
230+ f"The current cache looks as follows:\n { result } ."
231+ )
223232
224233 cached_sha = result ["linux_sha" ]
225234 cached_clang_version = result ["clang_version" ]
226235 cached_build_status = result ["build_status" ]
227236 cached_patches_hash = result .get ("patches_hash" , curr_patches_hash )
228237
229- if cached_sha != curr_sha or cached_clang_version != curr_clang_version or cached_patches_hash != curr_patches_hash :
238+ if (
239+ cached_sha != curr_sha
240+ or cached_clang_version != curr_clang_version
241+ or cached_patches_hash != curr_patches_hash
242+ ):
230243 print (f"""\
231244 CACHE MISS: current linux_sha is { curr_sha } , clang_version is { curr_clang_version } ,
232245 and current patches_hash is { curr_patches_hash } while { args .workflow_name } has
@@ -271,5 +284,4 @@ def create_repository_variable(name: str, linux_sha: str, clang_version: str,
271284 with open (env_file , "a" , encoding = "utf-8" ) as fd :
272285 fd .write (f"CACHE_PASS={ cached_build_status .strip ()} " )
273286
274- sys .exit (
275- 0 ) # signifies to the workflow that no jobs should run ('success')
287+ sys .exit (0 ) # signifies to the workflow that no jobs should run ('success')
0 commit comments