@@ -21,13 +21,15 @@ def __init__(
2121 config : dict ,
2222 environment : DockerEnvironment ,
2323 game_context : GameContext ,
24+ push : bool = False ,
2425 ) -> None :
2526 self .config = config
2627 self .name = config ["name" ]
2728 self ._player_unique_id = str (uuid .uuid4 ())
2829 """Unique ID that doesn't clash even across multiple games. Used for git tags."""
2930 self .environment = environment
3031 self .game_context = game_context
32+ self .push = push
3133 self .logger = get_logger (
3234 self .name ,
3335 log_path = self .game_context .log_local / "players" / self .name / "player.log" ,
@@ -43,6 +45,17 @@ def __init__(
4345 "initial_commit_hash" : self ._get_commit_hash (),
4446 }
4547
48+ if self .push :
49+ self .logger .info ("Will push agent gameplay as branch to remote repository after each round" )
50+ token = os .getenv ("GITHUB_TOKEN" )
51+ if not token :
52+ raise ValueError ("GITHUB_TOKEN environment variable is required" )
53+ for cmd in [
54+ "git remote remove origin" ,
55+ f"git remote add origin https://x-access-token:{ token } @github.com/{ GH_ORG } /{ self .game_context .name } .git" ,
56+ ]:
57+ assert_zero_exit_code (self .environment .execute (cmd ), logger = self .logger )
58+
4659 # --- Main methods ---
4760
4861 def pre_run_hook (self , * , new_round : int ) -> None :
@@ -56,6 +69,13 @@ def post_run_hook(self, *, round: int) -> None:
5669 self ._commit ()
5770 self ._metadata ["diff" ][round ] = self ._get_round_diff (round )
5871 self ._metadata ["incremental_diff" ][round ] = self ._get_round_diff (round , incremental = True )
72+ if self .push :
73+ for cmd in [
74+ f"git push origin { self ._branch_name } " ,
75+ "git push origin --tags" ,
76+ ]:
77+ assert_zero_exit_code (self .environment .execute (cmd ), logger = self .logger )
78+ self .logger .info (f"Pushed { self .name } commit history to remote repository (branch { self ._branch_name } )" )
5979
6080 @abstractmethod
6181 def run (self ) -> None :
@@ -65,21 +85,6 @@ def get_metadata(self) -> dict:
6585 """Get metadata for the agent."""
6686 return self ._metadata
6787
68- def push (self ) -> None :
69- """Push codebase to a branch on the game's remote repository."""
70- token = os .getenv ("GITHUB_TOKEN" )
71- if not token :
72- raise ValueError ("GITHUB_TOKEN environment variable is required" )
73-
74- for cmd in [
75- "git remote remove origin" ,
76- f"git remote add origin https://x-access-token:{ token } @github.com/{ GH_ORG } /{ self .game_context .name } .git" ,
77- f"git push origin { self ._branch_name } " ,
78- "git push origin --tags" ,
79- ]:
80- assert_zero_exit_code (self .environment .execute (cmd ), logger = self .logger )
81- self .logger .info (f"Pushed { self .name } commit history to remote repository (branch { self ._branch_name } )" )
82-
8388 def reset_and_apply_patch (self , patch : str , * , base_commit : str = "" , filter_patch : bool = True ) -> None :
8489 """Clean all uncommitted changes. If base_commit is provided, reset to that commit.
8590 Then apply the patch to the codebase.
0 commit comments