diff --git a/docs/scripts/auto-generate-examples.py b/docs/scripts/auto-generate-examples.py index d613195c..0732a216 100644 --- a/docs/scripts/auto-generate-examples.py +++ b/docs/scripts/auto-generate-examples.py @@ -1,37 +1,5 @@ import os import re -# import subprocess - - -def current_git_branch(): - return "gemma2-cloud-run" - # try: - # # First, try to get the branch name from GitHub Actions environment variables - # if "GITHUB_REF" in os.environ: - # branch = os.environ["GITHUB_REF"].split("/")[-1] - # else: - # # If not in GitHub Actions, use git command - # result = subprocess.run( - # ["git", "rev-parse", "--abbrev-ref", "HEAD"], - # capture_output=True, - # text=True, - # check=True, - # ) - # branch = result.stdout.strip() - # - # # Check if the branch is 'HEAD' (detached state in CI) - # if branch == "HEAD": - # # Try to get the branch name from GitHub Actions specific environment variable - # if "GITHUB_HEAD_REF" in os.environ: - # branch = os.environ["GITHUB_HEAD_REF"] - # elif "GITHUB_REF" in os.environ: - # branch = os.environ["GITHUB_REF"].split("/")[-1] - # else: - # branch = "main" - # - # return branch - # except: # noqa: E722 - # return "main" def process_readme_files(): @@ -61,30 +29,27 @@ def process_file(root, file, dir): with open(file_path, "r") as f: content = f.read() - # Obtain the current checked out Git branch - git_branch = current_git_branch() - # For Juypter Notebooks, remove the comment i.e. `` but keep the metadata content = re.sub(r"", r"\1", content, flags=re.DOTALL) # Replace image and link paths content = re.sub( r"\(\./(imgs|assets)/([^)]*\.png)\)", - rf"(https://raw.githubusercontent.com/huggingface/Google-Cloud-Containers/{git_branch}/" + r"(https://raw.githubusercontent.com/huggingface/Google-Cloud-Containers/main/" + root + r"/\1/\2)", content, ) content = re.sub( r"\(\.\./([^)]+)\)", - rf"(https://github.com/huggingface/Google-Cloud-Containers/tree/{git_branch}/examples/" + r"(https://github.com/huggingface/Google-Cloud-Containers/tree/main/examples/" + dir + r"/\1)", content, ) content = re.sub( r"\(\.\/([^)]+)\)", - rf"(https://github.com/huggingface/Google-Cloud-Containers/tree/{git_branch}/" + r"(https://github.com/huggingface/Google-Cloud-Containers/tree/main/" + root + r"/\1)", content, @@ -129,7 +94,9 @@ def replacement(match): print("No relative paths found in the processed file.") # Calculate the example URL - example_url = f"https://github.com/huggingface/Google-Cloud-Containers/tree/{git_branch}/{root}" + example_url = ( + f"https://github.com/huggingface/Google-Cloud-Containers/tree/main/{root}" + ) if file.__contains__("ipynb"): example_url += "/vertex-notebook.ipynb"