@@ -170,22 +170,28 @@ def get_matching_artifact(
170170 return None
171171
172172
173+ def load_env_files () -> None :
174+ """Load both .env and .env.ci files if they exist."""
175+ project_root = Path (__file__ ).parent .parent
176+ env_file = project_root / ".env"
177+ env_ci_file = project_root / ".env.ci"
178+
179+ for env in [env_file , env_ci_file ]:
180+ if env .exists ():
181+ load_dotenv (env )
182+ console .print (f"[green]Loaded environment variables from { env_file } " )
183+
184+
173185def download_github_artifact (
174186 github_token : str | None ,
175187 output_dir : Path ,
176188 repo : str ,
177189 workflow : str ,
190+ target_branch : str ,
178191 run_id : int | None = None ,
179192) -> None :
180193 # Get current platform
181- if repo == "prefix-dev/pixi" :
182- current_platform = get_current_platform ()
183- console .print (f"[blue]Detected platform: { current_platform } " )
184- elif repo == "prefix-dev/pixi-build-backends" :
185- current_platform = get_current_platform ()
186- console .print (f"[blue]Detected platform: { current_platform } " )
187- else :
188- raise ValueError (f"Unsupported repository: { repo } " )
194+ current_platform = get_current_platform ()
189195
190196 # Initialize GitHub client
191197 gh = Github (github_token )
@@ -195,9 +201,9 @@ def download_github_artifact(
195201 console .print (f"[green]Connected to repository: { repository .full_name } " )
196202
197203 # Find the artifact for our platform
198- if repo == "prefix-dev /pixi" :
204+ if repo . endswith ( " /pixi") :
199205 artifact_name_pattern = f"pixi-{ current_platform } "
200- elif repo == "prefix-dev /pixi-build-backends" :
206+ elif repo . endswith ( " /pixi-build-backends") :
201207 artifact_name_pattern = f"pixi-build-backends-{ current_platform } "
202208 else :
203209 raise ValueError (f"Unsupported repository: { repo } " )
@@ -226,9 +232,9 @@ def download_github_artifact(
226232
227233 console .print (f"[blue]Found workflow: { target_workflow .name } " )
228234
229- # Get latest workflow run from main branch
230- console .print ("[blue]Finding latest workflow run from main branch" )
231- runs = target_workflow .get_runs (branch = "main" , event = "push" )
235+ # Get latest workflow run from target branch
236+ console .print (f "[blue]Finding latest workflow run from { target_branch } branch" )
237+ runs = target_workflow .get_runs (branch = target_branch , event = "push" )
232238 # Check the past five runs until a suitable candidate is found
233239 for selected_run in itertools .islice (runs , 3 ):
234240 artifacts = selected_run .get_artifacts ()
@@ -260,8 +266,8 @@ def download_github_artifact(
260266
261267
262268def main () -> None :
263- # Load environment variables from .env file
264- load_dotenv ()
269+ # Load environment files
270+ load_env_files ()
265271
266272 parser = argparse .ArgumentParser (description = "Download artifacts from GitHub Actions" )
267273 parser .add_argument (
@@ -281,13 +287,19 @@ def main() -> None:
281287
282288 args = parser .parse_args ()
283289
284- # Set repo and workflow based on repository choice
290+ # Set repo and workflow based on repository choice, with CI overrides
285291 if args .repo == "pixi" :
286- repo = " prefix-dev/pixi"
292+ repo = os . getenv ( "PIXI_CI_REPO_NAME" , " prefix-dev/pixi")
287293 workflow = "CI"
294+ target_branch = os .getenv ("PIXI_CI_REPO_BRANCH" , "main" )
288295 elif args .repo == "pixi-build-backends" :
289- repo = " prefix-dev/pixi-build-backends"
296+ repo = os . getenv ( "BUILD_BACKENDS_CI_REPO_NAME" , " prefix-dev/pixi-build-backends")
290297 workflow = "Testsuite"
298+ target_branch = os .getenv ("BUILD_BACKENDS_CI_REPO_BRANCH" , "main" )
299+
300+ # Show override info if non-default values are being used
301+ if target_branch != "main" or repo != f"prefix-dev/{ args .repo } " :
302+ console .print (f"[yellow]CI overrides active: using { repo } branch { target_branch } " )
291303
292304 # Hardcode output directory to "artifacts"
293305 output_dir = Path ("artifacts" )
@@ -302,7 +314,9 @@ def main() -> None:
302314 sys .exit ()
303315
304316 try :
305- download_github_artifact (github_token , output_dir , repo , workflow , args .run_id )
317+ download_github_artifact (
318+ github_token , output_dir , repo , workflow , target_branch , args .run_id
319+ )
306320 console .print ("[green][SUCCESS] Download completed successfully!" )
307321 sys .exit (0 )
308322 except Exception as e :
0 commit comments