From 81bc0fd9cb570d782963c7d5de1ef1810ac152dc Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Thu, 5 Sep 2024 08:40:05 -0700 Subject: [PATCH] Release script (#746) * Update main repo release script * update readme [skip ci] --- README.md | 7 ++++ scripts/main_repo_release.py | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 scripts/main_repo_release.py diff --git a/README.md b/README.md index 17cf485a1..464afcc17 100644 --- a/README.md +++ b/README.md @@ -237,3 +237,10 @@ This repo is using litegraph package hosted on https://github.com/Comfy-Org/lite - Option 1: Set `DEPLOY_COMFYUI_DIR` in `.env` and run `npm run deploy`. - Option 2: Copy everything under `dist/` to `ComfyUI/web/` in your ComfyUI checkout manually. + +## Publish release to ComfyUI main repo + +Run following command to publish a release to ComfyUI main repo. The script will create a new branch and do a commit to `web/` folder by checkout `dist.zip` +from GitHub release. + +- `python scripts/main_repo_release.py ` diff --git a/scripts/main_repo_release.py b/scripts/main_repo_release.py new file mode 100644 index 000000000..15d489743 --- /dev/null +++ b/scripts/main_repo_release.py @@ -0,0 +1,68 @@ +import os +import sys +import requests +import zipfile +import shutil +import git +import tempfile + + +def download_and_extract(version, temp_dir): + url = f"https://github.com/Comfy-Org/ComfyUI_frontend/releases/download/v{version}/dist.zip" + response = requests.get(url) + + if response.status_code == 200: + zip_path = os.path.join(temp_dir, "dist.zip") + with open(zip_path, "wb") as file: + file.write(response.content) + + with zipfile.ZipFile(zip_path, "r") as zip_ref: + zip_ref.extractall(temp_dir) + else: + raise Exception( + f"Failed to download release asset. Status code: {response.status_code}" + ) + + +def update_repo(repo_path, version, temp_dir): + repo = git.Repo(repo_path) + + # Stash any changes + repo.git.stash() + + # Create and checkout new branch + new_branch = f"release-{version}" + repo.git.checkout("-b", new_branch, "-t", "origin/master") + + # Remove all files under web/ directory + web_dir = os.path.join(repo_path, "web") + if os.path.exists(web_dir): + shutil.rmtree(web_dir) + + # Move content from temp_dir to web/ + shutil.move(temp_dir, web_dir) + + # Add changes and commit + repo.git.add(all=True) + commit_message = f"Update web content to release v{version}" + repo.git.commit("-m", commit_message) + + +def main(repo_path: str, version: str): + with tempfile.TemporaryDirectory() as temp_dir: + try: + download_and_extract(version, temp_dir) + update_repo(repo_path, version, temp_dir) + print(f"Successfully updated repo to release v{version}") + except Exception as e: + print(f"An error occurred: {str(e)}") + + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Usage: python script.py ") + sys.exit(1) + + repo_path = sys.argv[1] + version = sys.argv[2] + main(repo_path, version)