|
| 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 release PR for WarpX. |
| 11 | +# It is highly automated and does a few assumptions, e.g., that you |
| 12 | +# are releasing for the current month. |
| 13 | +# |
| 14 | +# You also need to have git and the GitHub CLI tool "gh" installed and properly |
| 15 | +# configured for it to work: |
| 16 | +# https://cli.github.com/ |
| 17 | +# |
| 18 | +import subprocess |
| 19 | +import sys |
| 20 | +from datetime import datetime |
| 21 | +from pathlib import Path |
| 22 | + |
| 23 | +# Maintainer Inputs ########################################################### |
| 24 | + |
| 25 | +print("""Hi there, this is a WarpX maintainer tool to ...\n. |
| 26 | +For it to work, you need write access on the source directory and |
| 27 | +you should be working in a clean git branch without ongoing |
| 28 | +rebase/merge/conflict resolves and without unstaged changes.""") |
| 29 | + |
| 30 | +# check source dir |
| 31 | +REPO_DIR = Path(__file__).parent.parent.parent.absolute() |
| 32 | +print(f"\nYour current source directory is: {REPO_DIR}") |
| 33 | + |
| 34 | +REPLY = input("Are you sure you want to continue? [y/N] ") |
| 35 | +print() |
| 36 | +if REPLY not in ["Y", "y"]: |
| 37 | + print("You did not confirm with 'y', aborting.") |
| 38 | + sys.exit(1) |
| 39 | + |
| 40 | +release_repo = input("What is the name of your git remote? (e.g., ax3l) ") |
| 41 | +commit_sign = input("How to sign the commit? (e.g., -sS) ") |
| 42 | + |
| 43 | + |
| 44 | +# Helpers ##################################################################### |
| 45 | + |
| 46 | + |
| 47 | +def concat_answers(answers): |
| 48 | + return "\n".join(answers) + "\n" |
| 49 | + |
| 50 | + |
| 51 | +# Stash current work ########################################################## |
| 52 | + |
| 53 | +subprocess.run(["git", "stash"], capture_output=True, text=True) |
| 54 | + |
| 55 | + |
| 56 | +# Git Branch ################################################################## |
| 57 | + |
| 58 | +WarpX_version_yr = f"{datetime.now().strftime('%y')}" |
| 59 | +WarpX_version_mn = f"{datetime.now().strftime('%m')}" |
| 60 | +WarpX_version = f"{WarpX_version_yr}.{WarpX_version_mn}" |
| 61 | +release_branch = f"release-{WarpX_version}" |
| 62 | +subprocess.run(["git", "checkout", "development"], capture_output=True, text=True) |
| 63 | +subprocess.run(["git", "fetch"], capture_output=True, text=True) |
| 64 | +subprocess.run(["git", "pull", "--ff-only"], capture_output=True, text=True) |
| 65 | +subprocess.run(["git", "branch", "-D", release_branch], capture_output=True, text=True) |
| 66 | +subprocess.run( |
| 67 | + ["git", "checkout", "-b", release_branch], capture_output=True, text=True |
| 68 | +) |
| 69 | + |
| 70 | + |
| 71 | +# AMReX New Version ########################################################### |
| 72 | + |
| 73 | +AMReX_version = f"{datetime.now().strftime('%y')}.{datetime.now().strftime('%m')}" |
| 74 | +answers = concat_answers(["y", AMReX_version, AMReX_version, "y"]) |
| 75 | + |
| 76 | +process = subprocess.Popen( |
| 77 | + [Path(REPO_DIR).joinpath("Tools/Release/updateAMReX.py")], |
| 78 | + stdin=subprocess.PIPE, |
| 79 | + stdout=subprocess.PIPE, |
| 80 | + stderr=subprocess.PIPE, |
| 81 | + text=True, |
| 82 | +) |
| 83 | + |
| 84 | +process.communicate(answers) |
| 85 | +del process |
| 86 | + |
| 87 | +# commit |
| 88 | +subprocess.run(["git", "add", "-u"], capture_output=True, text=True) |
| 89 | +subprocess.run( |
| 90 | + ["git", "commit", commit_sign, "-m", f"AMReX: {AMReX_version}"], text=True |
| 91 | +) |
| 92 | + |
| 93 | + |
| 94 | +# PICSAR New Version ########################################################## |
| 95 | + |
| 96 | +PICSAR_version = "24.09" |
| 97 | +answers = concat_answers(["y", PICSAR_version, PICSAR_version, "y"]) |
| 98 | + |
| 99 | +process = subprocess.Popen( |
| 100 | + [Path(REPO_DIR).joinpath("Tools/Release/updatePICSAR.py")], |
| 101 | + stdin=subprocess.PIPE, |
| 102 | + stdout=subprocess.PIPE, |
| 103 | + stderr=subprocess.PIPE, |
| 104 | + text=True, |
| 105 | +) |
| 106 | + |
| 107 | +process.communicate(answers) |
| 108 | +del process |
| 109 | + |
| 110 | +# commit |
| 111 | +subprocess.run(["git", "add", "-u"], capture_output=True, text=True) |
| 112 | +subprocess.run( |
| 113 | + ["git", "commit", commit_sign, "-m", f"PICSAR: {PICSAR_version}"], text=True |
| 114 | +) |
| 115 | + |
| 116 | + |
| 117 | +# pyAMReX New Version ######################################################### |
| 118 | + |
| 119 | +pyAMReX_version = f"{datetime.now().strftime('%y')}.{datetime.now().strftime('%m')}" |
| 120 | +answers = concat_answers(["y", pyAMReX_version, pyAMReX_version, "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 | +subprocess.run( |
| 136 | + ["git", "commit", commit_sign, "-m", f"pyAMReX: {pyAMReX_version}"], text=True |
| 137 | +) |
| 138 | + |
| 139 | + |
| 140 | +# WarpX New Version ########################################################### |
| 141 | + |
| 142 | +answers = concat_answers(["y", WarpX_version_yr, WarpX_version_mn, "", "", "y"]) |
| 143 | + |
| 144 | +process = subprocess.Popen( |
| 145 | + [Path(REPO_DIR).joinpath("Tools/Release/newVersion.sh")], |
| 146 | + stdin=subprocess.PIPE, |
| 147 | + stdout=subprocess.PIPE, |
| 148 | + stderr=subprocess.PIPE, |
| 149 | + text=True, |
| 150 | +) |
| 151 | + |
| 152 | +process.communicate(answers) |
| 153 | +del process |
| 154 | + |
| 155 | +# commit |
| 156 | +subprocess.run(["git", "add", "-u"], capture_output=True, text=True) |
| 157 | +subprocess.run( |
| 158 | + ["git", "commit", commit_sign, "-m", f"WarpX: {WarpX_version}"], text=True |
| 159 | +) |
| 160 | + |
| 161 | + |
| 162 | +# GitHub PR ################################################################### |
| 163 | + |
| 164 | +subprocess.run(["git", "push", "-u", release_repo, release_branch], text=True) |
| 165 | + |
| 166 | +subprocess.run( |
| 167 | + [ |
| 168 | + "gh", |
| 169 | + "pr", |
| 170 | + "create", |
| 171 | + "--title", |
| 172 | + f"Release {WarpX_version}", |
| 173 | + "--body", |
| 174 | + f"""Prepare the {datetime.now().strftime('%B')} release of WarpX: |
| 175 | +```bash |
| 176 | +# update dependencies |
| 177 | +./Tools/Release/updateAMReX.py |
| 178 | +./Tools/Release/updatePICSAR.py # no changes, still {PICSAR_version} |
| 179 | +./Tools/Release/updatepyAMReX.py |
| 180 | +# bump version number |
| 181 | +./Tools/Release/newVersion.sh |
| 182 | +``` |
| 183 | +
|
| 184 | +Following this workflow: https://warpx.readthedocs.io/en/latest/maintenance/release.html |
| 185 | +""", |
| 186 | + "--label", |
| 187 | + "component: documentation", |
| 188 | + "--label", |
| 189 | + "component: third party", |
| 190 | + "--web", |
| 191 | + ], |
| 192 | + text=True, |
| 193 | +) |
| 194 | + |
| 195 | + |
| 196 | +# Epilogue #################################################################### |
| 197 | + |
| 198 | +print("""Done. Please check your source, e.g. via |
| 199 | + git diff |
| 200 | +now and commit the changes if no errors occurred.""") |
0 commit comments