Skip to content

Commit 2445c16

Browse files
committed
feat(esptool): Add auto commit to update script
1 parent ae5b6e7 commit 2445c16

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/scripts/update_esptool.py

100644100755
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import os
3434
import shutil
3535
import stat
36+
import subprocess
3637
import tarfile
3738
import zipfile
3839
import hashlib
@@ -201,10 +202,34 @@ def get_release_info(version):
201202
response.raise_for_status()
202203
return response.json()
203204

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+
204228
def main():
205229
parser = argparse.ArgumentParser(description="Repack esptool and update JSON metadata.")
206230
parser.add_argument("version", help="Version of the esptool (e.g. 5.0.dev1)")
207231
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")
208233
args = parser.parse_args()
209234

210235
script_dir = Path(__file__).resolve().parent
@@ -232,5 +257,10 @@ def main():
232257
shutil.move(tmp_json_path, json_path)
233258
print(f"Done. JSON updated at {json_path}")
234259

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+
235265
if __name__ == "__main__":
236266
main()

0 commit comments

Comments
 (0)