1+ import os
12import subprocess # nosec
23from typing import Optional
34
@@ -22,15 +23,18 @@ def setup(commit_owner: str, commit_email: str, homebrew_owner: str, homebrew_ta
2223 """
2324 logger = woodchips .get (LOGGER_NAME )
2425
26+ homebrew_tap_path = Git ._get_homebrew_tap_path (homebrew_tap )
27+
2528 commands = [
2629 [
2730 'git' ,
2831 'clone' ,
2932 '--depth=1' ,
3033 f'https://x-access-token:{ GITHUB_TOKEN } @github.com/{ homebrew_owner } /{ homebrew_tap } .git' ,
34+ homebrew_tap_path ,
3135 ],
32- ['git' , '-C' , homebrew_tap , 'config' , 'user.name' , f'"{ commit_owner } "' ],
33- ['git' , '-C' , homebrew_tap , 'config' , 'user.email' , commit_email ],
36+ ['git' , '-C' , homebrew_tap_path , 'config' , 'user.name' , f'"{ commit_owner } "' ],
37+ ['git' , '-C' , homebrew_tap_path , 'config' , 'user.email' , commit_email ],
3438 ]
3539
3640 for command in commands :
@@ -41,22 +45,25 @@ def setup(commit_owner: str, commit_email: str, homebrew_owner: str, homebrew_ta
4145 @staticmethod
4246 def add (homebrew_tap : str ):
4347 """Adds assets to a git commit."""
44- command = ['git' , '-C' , homebrew_tap , 'add' , '.' ]
48+ homebrew_tap_path = Git ._get_homebrew_tap_path (homebrew_tap )
49+ command = ['git' , '-C' , homebrew_tap_path , 'add' , '.' ]
4550 Git ._run_git_subprocess (command , 'Assets added to git commit successfully.' )
4651
4752 @staticmethod
4853 def commit (homebrew_tap : str , repo_name : str , version : str ):
4954 """Commits assets to the Homebrew tap (repo)."""
55+ homebrew_tap_path = Git ._get_homebrew_tap_path (homebrew_tap )
5056 # fmt: off
51- command = ['git' , '-C' , homebrew_tap , 'commit' , '-m' , f'chore: brew formula update for { repo_name } { version } ' ] # noqa
57+ command = ['git' , '-C' , homebrew_tap_path , 'commit' , '-m' , f'chore: brew formula update for { repo_name } { version } ' ] # noqa
5258 # fmt: on
5359 Git ._run_git_subprocess (command , 'Assets committed successfully.' )
5460
5561 @staticmethod
5662 def push (homebrew_tap : str , homebrew_owner : str ):
5763 """Pushes assets to the remote Homebrew tap (repo)."""
64+ homebrew_tap_path = Git ._get_homebrew_tap_path (homebrew_tap )
5865 # fmt: off
59- command = ['git' , '-C' , homebrew_tap , 'push' , f'https://x-access-token:{ GITHUB_TOKEN } @github.com/{ homebrew_owner } /{ homebrew_tap } .git' ] # noqa
66+ command = ['git' , '-C' , homebrew_tap_path , 'push' , f'https://x-access-token:{ GITHUB_TOKEN } @github.com/{ homebrew_owner } /{ homebrew_tap } .git' ] # noqa
6067 # fmt: on
6168 Git ._run_git_subprocess (command , f'Assets pushed successfully to { homebrew_tap } .' )
6269
@@ -80,3 +87,9 @@ def _run_git_subprocess(command: list[str], debug_message: Optional[str] = None)
8087 except Exception as error :
8188 logger .critical (error )
8289 raise
90+
91+ @staticmethod
92+ def _get_homebrew_tap_path (homebrew_tap : str ) -> str :
93+ """Returns the path to the Homebrew tap."""
94+ os .makedirs ('/tmp/homebrew-releaser' , exist_ok = True )
95+ return os .path .join ('/tmp' , 'homebrew-releaser' , homebrew_tap )
0 commit comments