|
33 | 33 | import os
|
34 | 34 | import shutil
|
35 | 35 | import stat
|
| 36 | +import subprocess |
36 | 37 | import tarfile
|
37 | 38 | import zipfile
|
38 | 39 | import hashlib
|
@@ -201,10 +202,34 @@ def get_release_info(version):
|
201 | 202 | response.raise_for_status()
|
202 | 203 | return response.json()
|
203 | 204 |
|
| 205 | +def create_branch_and_commit(version, json_path): |
| 206 | + """Create a new branch and commit the changes to it.""" |
| 207 | + branch_name = f"update-esptool-{version}" |
| 208 | + commit_message = f"change(esptool): Upgrade to version {version}" |
| 209 | + |
| 210 | + try: |
| 211 | + # Create and checkout new branch |
| 212 | + subprocess.run(["git", "checkout", "-b", branch_name], check=True, capture_output=True, text=True) |
| 213 | + print(f"Created and switched to new branch: {branch_name}") |
| 214 | + |
| 215 | + # Stage the JSON file |
| 216 | + subprocess.run(["git", "add", str(json_path)], check=True, capture_output=True, text=True) |
| 217 | + print(f"Staged file: {json_path}") |
| 218 | + |
| 219 | + # Commit the changes |
| 220 | + subprocess.run(["git", "commit", "-m", commit_message], check=True, capture_output=True, text=True) |
| 221 | + print(f"Committed changes with message: {commit_message}") |
| 222 | + |
| 223 | + except subprocess.CalledProcessError as e: |
| 224 | + print(f"Git operation failed: {e}") |
| 225 | + print(f"Command output: {e.stderr if e.stderr else e.stdout}") |
| 226 | + raise |
| 227 | + |
204 | 228 | def main():
|
205 | 229 | parser = argparse.ArgumentParser(description="Repack esptool and update JSON metadata.")
|
206 | 230 | parser.add_argument("version", help="Version of the esptool (e.g. 5.0.dev1)")
|
207 | 231 | parser.add_argument("-l", "--local", dest="base_folder", help="Enable local build mode and set the base folder with unpacked artifacts")
|
| 232 | + parser.add_argument("-c", "--commit", action="store_true", help="Automatically create a new branch and commit the JSON file changes") |
208 | 233 | args = parser.parse_args()
|
209 | 234 |
|
210 | 235 | script_dir = Path(__file__).resolve().parent
|
@@ -232,5 +257,10 @@ def main():
|
232 | 257 | shutil.move(tmp_json_path, json_path)
|
233 | 258 | print(f"Done. JSON updated at {json_path}")
|
234 | 259 |
|
| 260 | + # Auto-commit if requested |
| 261 | + if args.commit: |
| 262 | + print("Auto-commit enabled. Creating branch and committing changes...") |
| 263 | + create_branch_and_commit(args.version, json_path) |
| 264 | + |
235 | 265 | if __name__ == "__main__":
|
236 | 266 | main()
|
0 commit comments