bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

commit d10febaf3b24ebb55f933b804c84e69626aa1e40
parent 1c96435c84120a5159a747ec199e35c47bc76832
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Sun,  4 Jan 2026 18:44:38 +0530

[2026-01-04] : .\{root} : Changed the automation and file_name of git_automation.py -> deploy_pipeline.py

Diffstat:
Adeploy_pipeline.py | 191+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/generate_index.py | 2+-
Dgit_automation.py | 84-------------------------------------------------------------------------------
3 files changed, 192 insertions(+), 85 deletions(-)

diff --git a/deploy_pipeline.py b/deploy_pipeline.py @@ -0,0 +1,190 @@ +import os +import subprocess +import shutil +from datetime import datetime + +# --- CONFIGURATION PATHS --- +BSC_REPO_ROOT = r"G:\bsc" +GENERATE_INDEX_SCRIPT = r"G:\bsc\docs\generate_index.py" +ARANAG_SITE_DESKTOP = r"C:\Users\PC\Desktop\aranag.site" +BSC_LOCAL_BACKUP = r"G:\bsc_local" +ARANAG_REPO_ROOT = r"G:\aranag" + +# Folders/Files to PRESERVE in G:\aranag when deleting +ARANAG_PRESERVE = [ + "ada-web", + "compiler", + "README.md", + "sitemap.xml", + ".firebase", + ".git" # Always preserve .git in a repo! +] + +def run_generate_index(): + print("\n--- Step 1: Generating Index HTML ---") + if os.path.exists(GENERATE_INDEX_SCRIPT): + try: + # Running the script as a separate process + subprocess.run(["python", GENERATE_INDEX_SCRIPT], check=True) + print("[Success] Index generation script executed.") + except subprocess.CalledProcessError: + print("[Error] Failed to run generate_index.py") + else: + print(f"[Error] Script not found at: {GENERATE_INDEX_SCRIPT}") + +def git_workflow_bsc(): + print("\n--- Step 2: Git Push (Primary Repo: bsc) ---") + + if not os.path.exists(BSC_REPO_ROOT): + print(f"[Error] Repository root not found: {BSC_REPO_ROOT}") + return + + os.chdir(BSC_REPO_ROOT) + + print("> git add .") + try: + subprocess.run(["git", "add", "."], check=True) + except subprocess.CalledProcessError: + print("[Error] 'git add' failed.") + return + + # Detect changes + try: + result = subprocess.run( + ["git", "diff", "--name-only", "--cached"], + capture_output=True, text=True, check=True + ) + changed_files = result.stdout.strip().splitlines() + except subprocess.CalledProcessError: + changed_files = [] + + if not changed_files: + print("[Info] No changes detected in 'bsc'. Skipping commit/push.") + return + + # Calculate path for commit message + changed_dirs = [os.path.dirname(f.replace('/', os.sep)) for f in changed_files] + + if not changed_dirs: + common_path = "" + else: + try: + common_path = os.path.commonpath(changed_dirs) + except ValueError: + common_path = "" + + path_str = f".\\{common_path}" if common_path else ".\\{root}" + + print(f"[Detected Changes in]: {path_str}") + user_message = input(f"Enter commit message for '{path_str}': ") + if not user_message: + print("Commit message cannot be empty. Aborting git push.") + return + + today = datetime.now().strftime("%Y-%m-%d") + full_commit_msg = f"[{today}] : {path_str} : {user_message}" + + print(f"> git commit -m \"{full_commit_msg}\"") + try: + subprocess.run(["git", "commit", "-m", full_commit_msg], check=True) + print("> git push") + subprocess.run(["git", "push"], check=True) + print("[Success] Pushed 'bsc' to remote.") + except subprocess.CalledProcessError as e: + print(f"[Error] Git command failed: {e}") + +def deploy_firebase(): + print("\n--- Step 3: Firebase Deploy ---") + if not os.path.exists(ARANAG_SITE_DESKTOP): + print(f"[Error] Firebase project path not found: {ARANAG_SITE_DESKTOP}") + return + + os.chdir(ARANAG_SITE_DESKTOP) + print(f"Deploying from: {ARANAG_SITE_DESKTOP}") + try: + # shell=True is often needed for firebase commands on Windows to find the executable + subprocess.run("firebase deploy --only hosting", shell=True, check=True) + print("[Success] Firebase deployment complete.") + except subprocess.CalledProcessError: + print("[Error] Firebase deploy failed.") + +def sync_bsc_local(): + print("\n--- Step 4: Syncing to G:\\bsc_local ---") + try: + # Delete existing content + if os.path.exists(BSC_LOCAL_BACKUP): + print(f"Cleaning {BSC_LOCAL_BACKUP}...") + # rmtree can sometimes fail on Windows due to read-only files, loop to retry if needed + shutil.rmtree(BSC_LOCAL_BACKUP, ignore_errors=True) + + # Copy fresh content + print(f"Copying from {BSC_REPO_ROOT} to {BSC_LOCAL_BACKUP}...") + shutil.copytree(BSC_REPO_ROOT, BSC_LOCAL_BACKUP, dirs_exist_ok=True) + print("[Success] bsc_local synced.") + except Exception as e: + print(f"[Error] Sync failed: {e}") + +def update_and_push_aranag(): + print("\n--- Step 5: Updating G:\\aranag & Pushing ---") + + if not os.path.exists(ARANAG_REPO_ROOT): + print(f"[Error] Path not found: {ARANAG_REPO_ROOT}") + return + + # 1. Delete contents except preserved + print("Cleaning G:\\aranag (preserving specific files)...") + for item in os.listdir(ARANAG_REPO_ROOT): + if item in ARANAG_PRESERVE: + continue + + item_path = os.path.join(ARANAG_REPO_ROOT, item) + try: + if os.path.isdir(item_path): + shutil.rmtree(item_path) + else: + os.remove(item_path) + except Exception as e: + print(f"Warning: Could not delete {item}: {e}") + + # 2. Copy from Desktop site to G:\aranag + print(f"Copying from {ARANAG_SITE_DESKTOP} to {ARANAG_REPO_ROOT}...") + try: + # dirs_exist_ok=True allows copying into existing folder structure + shutil.copytree(ARANAG_SITE_DESKTOP, ARANAG_REPO_ROOT, dirs_exist_ok=True) + except Exception as e: + print(f"[Error] Copy failed: {e}") + return + + # 3. Git Push G:\aranag + os.chdir(ARANAG_REPO_ROOT) + print("Git pushing G:\\aranag...") + + try: + subprocess.run(["git", "add", "."], check=True) + + # Check if there are changes + status = subprocess.run(["git", "status", "--porcelain"], capture_output=True, text=True) + if status.stdout.strip(): + commit_msg = f"Automated Update: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" + subprocess.run(["git", "commit", "-m", commit_msg], check=True) + subprocess.run(["git", "push"], check=True) + print("[Success] G:\\aranag updated and pushed.") + else: + print("[Info] No changes to push in G:\\aranag.") + + except subprocess.CalledProcessError as e: + print(f"[Error] Git operations on aranag failed: {e}") + +def main(): + print("=== STARTING AUTOMATION PIPELINE ===") + + run_generate_index() + git_workflow_bsc() + deploy_firebase() + sync_bsc_local() + update_and_push_aranag() + + print("\n=== PIPELINE FINISHED ===") + +if __name__ == "__main__": + main()+ \ No newline at end of file diff --git a/docs/generate_index.py b/docs/generate_index.py @@ -13,7 +13,7 @@ EXCLUDED_FILES = [ 'index.html', 'README.md', 'CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', 'SOCIAL_PREVIEW.md', 'LICENSE', 'main.js', 'package.json', 'SECURITY.md', 'server.js', 'template.html', 'generate_index.py', 'header.py', 'add_header.py', - 'Assignment.pdf', 'Assignment.docx', 'git_automation.py', 'tester.c' + 'Assignment.pdf', 'Assignment.docx', 'deploy_pipeline.py', 'tester.c' ] # --- End Configuration --- diff --git a/git_automation.py b/git_automation.py @@ -1,83 +0,0 @@ -import os -import subprocess -from datetime import datetime - -REPO_ROOT_DIRECTORY = r"G:\bsc" - -def main(): - print("--- Git Automation ---") - - if not os.path.exists(REPO_ROOT_DIRECTORY): - print(f"[Error] Repository root not found: {REPO_ROOT_DIRECTORY}") - return - - os.chdir(REPO_ROOT_DIRECTORY) - - print(f"\n> git add .") - try: - subprocess.run(["git", "add", "."], check=True) - except subprocess.CalledProcessError: - print("[Error] 'git add' failed.") - return - - try: - result = subprocess.run( - ["git", "diff", "--name-only", "--cached"], - capture_output=True, - text=True, - check=True - ) - changed_files = result.stdout.strip().splitlines() - except subprocess.CalledProcessError: - print("[Error] Could not determine changed files.") - return - - if not changed_files: - print("\n[Info] No changes detected to commit.") - return - - changed_dirs = [] - for f in changed_files: - normalized_path = f.replace('/', os.sep) - dirname = os.path.dirname(normalized_path) - changed_dirs.append(dirname) - - if not changed_dirs: - common_path = "" - else: - try: - common_path = os.path.commonpath(changed_dirs) - except ValueError: - common_path = "" - - if not common_path: - path_str = ".\\{root}" - else: - path_str = f".\\{common_path}" - - print(f"\n[Detected Changes in]: {path_str}") - - user_message = input(f"Enter commit message for '{path_str}': ") - if not user_message: - print("Commit message cannot be empty. Aborting.") - return - - today = datetime.now().strftime("%Y-%m-%d") - full_commit_msg = f"[{today}] : {path_str} : {user_message}" - - print(f"\n> git commit -m \"{full_commit_msg}\"") - try: - subprocess.run(["git", "commit", "-m", full_commit_msg], check=True) - except subprocess.CalledProcessError: - print("[Error] 'git commit' failed.") - return - - print("\n> git push") - try: - subprocess.run(["git", "push"], check=True) - print("\n[Success] Pushed to remote.") - except subprocess.CalledProcessError: - print("[Error] 'git push' failed.") - -if __name__ == "__main__": - main()- \ No newline at end of file
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror