diff --git a/scripts/download_github_runs.py b/scripts/download_github_runs.py index b98c8f8c..d8bf0ee3 100644 --- a/scripts/download_github_runs.py +++ b/scripts/download_github_runs.py @@ -4,6 +4,10 @@ Download GitHub Actions artifacts and rename them with version numbers. Usage: python download_github_runs.py 2.0.4 https://github.com/78/xiaozhi-esp32/actions/runs/18866246016 + +Output: + Files are downloaded to releases// directory relative to the project root. + Example: releases/2.0.4/v2.0.4_atk-dnesp32s3-box0.zip """ import argparse @@ -147,12 +151,17 @@ def rename_artifact(original_name: str, version: str) -> str: if name.startswith("xiaozhi_"): name = name[len("xiaozhi_"):] - # Remove extension - name_without_ext = os.path.splitext(name)[0] + # Remove known extensions only (not using splitext to avoid issues with + # names containing dots like "esp32-s3-touch-amoled-2.06") + known_extensions = ('.bin', '.zip') + for ext in known_extensions: + if name.endswith(ext): + name = name[:-len(ext)] + break # Remove hash suffix (pattern: underscore followed by 40+ hex characters) # This matches Git commit hashes and similar identifiers - name_without_hash = re.sub(r'_[a-f0-9]{40,}$', '', name_without_ext) + name_without_hash = re.sub(r'_[a-f0-9]{40,}$', '', name) # Add version prefix and .zip extension new_name = f"v{version}_{name_without_hash}.zip" @@ -160,6 +169,17 @@ def rename_artifact(original_name: str, version: str) -> str: return new_name +def get_default_releases_dir() -> Path: + """ + Get the default releases directory path relative to this script's location. + + Returns: + Path to the releases directory (script_dir/../releases) + """ + script_dir = Path(__file__).resolve().parent + return script_dir.parent / "releases" + + def main(): """Main function to download and rename GitHub Actions artifacts.""" parser = argparse.ArgumentParser( @@ -175,8 +195,8 @@ def main(): ) parser.add_argument( "--output-dir", - default="../releases", - help="Output directory for downloaded artifacts (default: ../releases)" + default=None, + help="Output directory for downloaded artifacts (default: releases/ relative to project root)" ) args = parser.parse_args() @@ -211,8 +231,15 @@ def main(): print(f" - {artifact['name']}") print() + # Determine output directory + if args.output_dir: + # User specified custom output directory + output_dir = Path(args.output_dir) / args.version + else: + # Default: releases/ relative to script location + output_dir = get_default_releases_dir() / args.version + # Create output directory - output_dir = Path(args.output_dir) output_dir.mkdir(parents=True, exist_ok=True) # Download and rename each artifact