|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright 2025 The WarpX Community |
| 4 | +# |
| 5 | +# This file is part of WarpX. |
| 6 | +# |
| 7 | +# Authors: Axel Huebl |
| 8 | +# |
| 9 | + |
| 10 | +# This file is a maintainer tool to open a weekly dependency update PR for WarpX. |
| 11 | +# |
| 12 | +# You also need to have git and the GitHub CLI tool "gh" installed and properly |
| 13 | +# configured for it to work: |
| 14 | +# https://cli.github.com/ |
| 15 | +# |
| 16 | +import subprocess |
| 17 | +import sys |
| 18 | +from pathlib import Path |
| 19 | + |
| 20 | +# Maintainer Inputs ########################################################### |
| 21 | + |
| 22 | +print("""Hi there, this is a WarpX maintainer tool to ...\n. |
| 23 | +For it to work, you need write access on the source directory and |
| 24 | +you should be working in a clean git branch without ongoing |
| 25 | +rebase/merge/conflict resolves and without unstaged changes.""") |
| 26 | + |
| 27 | +# check source dir |
| 28 | +REPO_DIR = Path(__file__).parent.parent.parent.absolute() |
| 29 | +print(f"\nYour current source directory is: {REPO_DIR}") |
| 30 | + |
| 31 | +REPLY = input("Are you sure you want to continue? [y/N] ") |
| 32 | +print() |
| 33 | +if REPLY not in ["Y", "y"]: |
| 34 | + print("You did not confirm with 'y', aborting.") |
| 35 | + sys.exit(1) |
| 36 | + |
| 37 | +update_repo = input("What is the name of your git remote? (e.g., ax3l) ") |
| 38 | +commit_sign = input("How to sign the commit? (e.g., -sS) ") |
| 39 | + |
| 40 | + |
| 41 | +# Helpers ##################################################################### |
| 42 | + |
| 43 | + |
| 44 | +def concat_answers(answers): |
| 45 | + return "\n".join(answers) + "\n" |
| 46 | + |
| 47 | + |
| 48 | +# Stash current work ########################################################## |
| 49 | + |
| 50 | +subprocess.run(["git", "stash"], capture_output=True, text=True) |
| 51 | + |
| 52 | + |
| 53 | +# Git Branch ################################################################## |
| 54 | + |
| 55 | +update_branch = "topic-amrexWeekly" |
| 56 | +subprocess.run(["git", "checkout", "development"], capture_output=True, text=True) |
| 57 | +subprocess.run(["git", "fetch"], capture_output=True, text=True) |
| 58 | +subprocess.run(["git", "pull", "--ff-only"], capture_output=True, text=True) |
| 59 | +subprocess.run(["git", "branch", "-D", update_branch], capture_output=True, text=True) |
| 60 | +subprocess.run(["git", "checkout", "-b", update_branch], capture_output=True, text=True) |
| 61 | + |
| 62 | + |
| 63 | +# AMReX New Version ########################################################### |
| 64 | + |
| 65 | +answers = concat_answers(["y", "", "", "y"]) |
| 66 | + |
| 67 | +process = subprocess.Popen( |
| 68 | + [Path(REPO_DIR).joinpath("Tools/Release/updateAMReX.py")], |
| 69 | + stdin=subprocess.PIPE, |
| 70 | + stdout=subprocess.PIPE, |
| 71 | + stderr=subprocess.PIPE, |
| 72 | + text=True, |
| 73 | +) |
| 74 | + |
| 75 | +process.communicate(answers) |
| 76 | +del process |
| 77 | + |
| 78 | +# commit |
| 79 | +subprocess.run(["git", "add", "-u"], capture_output=True, text=True) |
| 80 | +amrex_diff = subprocess.run(["git", "diff", "--cached"], capture_output=True, text=True) |
| 81 | +print("AMReX Commit...") |
| 82 | +subprocess.run( |
| 83 | + ["git", "commit", commit_sign, "-m", "AMReX: Weekly Update"], |
| 84 | + capture_output=True, |
| 85 | + text=True, |
| 86 | +) |
| 87 | + |
| 88 | + |
| 89 | +# PICSAR New Version ########################################################## |
| 90 | + |
| 91 | +PICSAR_version = "24.09" |
| 92 | +answers = concat_answers(["y", PICSAR_version, PICSAR_version, "y"]) |
| 93 | + |
| 94 | +process = subprocess.Popen( |
| 95 | + [Path(REPO_DIR).joinpath("Tools/Release/updatePICSAR.py")], |
| 96 | + stdin=subprocess.PIPE, |
| 97 | + stdout=subprocess.PIPE, |
| 98 | + stderr=subprocess.PIPE, |
| 99 | + text=True, |
| 100 | +) |
| 101 | + |
| 102 | +process.communicate(answers) |
| 103 | +del process |
| 104 | + |
| 105 | +# commit |
| 106 | +subprocess.run(["git", "add", "-u"], capture_output=True, text=True) |
| 107 | +picsar_diff = subprocess.run( |
| 108 | + ["git", "diff", "--cached"], capture_output=True, text=True |
| 109 | +) |
| 110 | +print("PICSAR Commit...") |
| 111 | +subprocess.run( |
| 112 | + ["git", "commit", commit_sign, "-m", "PICSAR: Weekly Update"], |
| 113 | + capture_output=True, |
| 114 | + text=True, |
| 115 | +) |
| 116 | + |
| 117 | + |
| 118 | +# pyAMReX New Version ######################################################### |
| 119 | + |
| 120 | +answers = concat_answers(["y", "", "", "y"]) |
| 121 | + |
| 122 | +process = subprocess.Popen( |
| 123 | + [Path(REPO_DIR).joinpath("Tools/Release/updatepyAMReX.py")], |
| 124 | + stdin=subprocess.PIPE, |
| 125 | + stdout=subprocess.PIPE, |
| 126 | + stderr=subprocess.PIPE, |
| 127 | + text=True, |
| 128 | +) |
| 129 | + |
| 130 | +process.communicate(answers) |
| 131 | +del process |
| 132 | + |
| 133 | +# commit |
| 134 | +subprocess.run(["git", "add", "-u"], capture_output=True, text=True) |
| 135 | +pyamrex_diff = subprocess.run( |
| 136 | + ["git", "diff", "--cached"], capture_output=True, text=True |
| 137 | +) |
| 138 | +print("pyAMReX Commit...") |
| 139 | +subprocess.run( |
| 140 | + ["git", "commit", commit_sign, "-m", "pyAMReX: Weekly Update"], |
| 141 | + capture_output=True, |
| 142 | + text=True, |
| 143 | +) |
| 144 | + |
| 145 | +# GitHub PR ################################################################### |
| 146 | + |
| 147 | +subprocess.run(["git", "push", "-f", "-u", update_repo, update_branch], text=True) |
| 148 | + |
| 149 | +amrex_changes = " (no changes)" if amrex_diff.stdout == "" else "" |
| 150 | +picsar_changes = " (no changes)" if picsar_diff.stdout == "" else "" |
| 151 | +pyamrex_changes = " (no changes)" if pyamrex_diff.stdout == "" else "" |
| 152 | + |
| 153 | +subprocess.run( |
| 154 | + [ |
| 155 | + "gh", |
| 156 | + "pr", |
| 157 | + "create", |
| 158 | + "--title", |
| 159 | + "AMReX/pyAMReX/PICSAR: Weekly Update", |
| 160 | + "--body", |
| 161 | + f"""Weekly update to latest AMReX{amrex_changes}. |
| 162 | +Weekly update to latest pyAMReX{pyamrex_changes}. |
| 163 | +Weekly update to latest PICSAR{picsar_changes}. |
| 164 | +
|
| 165 | +```console |
| 166 | +./Tools/Release/updateAMReX.py |
| 167 | +./Tools/Release/updatepyAMReX.py |
| 168 | +./Tools/Release/updatePICSAR.py |
| 169 | +``` |
| 170 | +""", |
| 171 | + "--label", |
| 172 | + "component: documentation", |
| 173 | + "--label", |
| 174 | + "component: third party", |
| 175 | + "--web", |
| 176 | + ], |
| 177 | + text=True, |
| 178 | +) |
| 179 | + |
| 180 | + |
| 181 | +# Epilogue #################################################################### |
| 182 | + |
| 183 | +print("""Done. Please check your source, e.g. via |
| 184 | + git diff |
| 185 | +now and commit the changes if no errors occurred.""") |
0 commit comments