55from pathlib import Path
66import zipfile
77import io
8+ import shutil
89
910# Constants
1011REPO_OWNER = "contentauth"
1112REPO_NAME = "c2pa-rs"
1213GITHUB_API_BASE = "https://api.github.com"
13- ARTIFACTS_DIR = Path ("artifacts" )
14+ SCRIPTS_ARTIFACTS_DIR = Path ("scripts/artifacts" )
15+ ROOT_ARTIFACTS_DIR = Path ("artifacts" )
1416
1517def get_release_by_tag (tag ):
1618 """Get release information for a specific tag from GitHub."""
@@ -22,7 +24,7 @@ def get_release_by_tag(tag):
2224def download_and_extract_libs (url , platform_name ):
2325 """Download a zip artifact and extract only the libs folder."""
2426 print (f"Downloading artifact for { platform_name } ..." )
25- platform_dir = ARTIFACTS_DIR / platform_name
27+ platform_dir = SCRIPTS_ARTIFACTS_DIR / platform_name
2628 platform_dir .mkdir (parents = True , exist_ok = True )
2729
2830 response = requests .get (url )
@@ -31,12 +33,28 @@ def download_and_extract_libs(url, platform_name):
3133 with zipfile .ZipFile (io .BytesIO (response .content )) as zip_ref :
3234 # Extract only files inside the libs/ directory
3335 for member in zip_ref .namelist ():
36+ print (f" Processing zip member: { member } " )
3437 if member .startswith ("lib/" ) and not member .endswith ("/" ):
38+ print (f" Processing lib file from downloadedzip: { member } " )
3539 target_path = platform_dir / os .path .relpath (member , "lib" )
40+ print (f" Moving file to target path: { target_path } " )
3641 target_path .parent .mkdir (parents = True , exist_ok = True )
3742 with zip_ref .open (member ) as source , open (target_path , "wb" ) as target :
3843 target .write (source .read ())
39- print (f"Successfully downloaded and extracted libraries for { platform_name } " )
44+
45+ print (f"Done downloading and extracting libraries for { platform_name } " )
46+
47+ def copy_artifacts_to_root ():
48+ """Copy the artifacts folder from scripts/artifacts to the root of the repository."""
49+ if not SCRIPTS_ARTIFACTS_DIR .exists ():
50+ print ("No artifacts found in scripts/artifacts" )
51+ return
52+
53+ print ("Copying artifacts from scripts/artifacts to root..." )
54+ if ROOT_ARTIFACTS_DIR .exists ():
55+ shutil .rmtree (ROOT_ARTIFACTS_DIR )
56+ shutil .copytree (SCRIPTS_ARTIFACTS_DIR , ROOT_ARTIFACTS_DIR )
57+ print ("Done copying artifacts" )
4058
4159def main ():
4260 if len (sys .argv ) < 2 :
@@ -46,11 +64,12 @@ def main():
4664
4765 release_tag = sys .argv [1 ]
4866 try :
49- ARTIFACTS_DIR .mkdir (exist_ok = True )
67+ SCRIPTS_ARTIFACTS_DIR .mkdir (exist_ok = True )
5068 print (f"Fetching release information for tag { release_tag } ..." )
5169 release = get_release_by_tag (release_tag )
5270 print (f"Found release: { release ['tag_name' ]} " )
5371
72+ artifacts_downloaded = False
5473 for asset in release ['assets' ]:
5574 if not asset ['name' ].endswith ('.zip' ):
5675 continue
@@ -63,14 +82,17 @@ def main():
6382 platform_name = '-' .join (parts [3 :]).replace ('.zip' , '' )
6483
6584 download_and_extract_libs (asset ['browser_download_url' ], platform_name )
85+ artifacts_downloaded = True
6686
67- print ("\n All artifacts have been downloaded and extracted successfully!" )
87+ if artifacts_downloaded :
88+ print ("\n All artifacts have been downloaded and extracted successfully!" )
89+ copy_artifacts_to_root ()
6890
6991 except requests .exceptions .RequestException as e :
70- print (f"Error downloading artifacts : { e } " , file = sys . stderr )
92+ print (f"Error: { e } " )
7193 sys .exit (1 )
7294 except Exception as e :
73- print (f"Unexpected error : { e } " , file = sys . stderr )
95+ print (f"Error : { e } " )
7496 sys .exit (1 )
7597
7698if __name__ == "__main__" :
0 commit comments