@@ -170,22 +170,28 @@ def get_matching_artifact(
170
170
return None
171
171
172
172
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
+
173
185
def download_github_artifact (
174
186
github_token : str | None ,
175
187
output_dir : Path ,
176
188
repo : str ,
177
189
workflow : str ,
190
+ target_branch : str ,
178
191
run_id : int | None = None ,
179
192
) -> None :
180
193
# 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 ()
189
195
190
196
# Initialize GitHub client
191
197
gh = Github (github_token )
@@ -195,9 +201,9 @@ def download_github_artifact(
195
201
console .print (f"[green]Connected to repository: { repository .full_name } " )
196
202
197
203
# Find the artifact for our platform
198
- if repo == "prefix-dev /pixi" :
204
+ if repo . endswith ( " /pixi") :
199
205
artifact_name_pattern = f"pixi-{ current_platform } "
200
- elif repo == "prefix-dev /pixi-build-backends" :
206
+ elif repo . endswith ( " /pixi-build-backends") :
201
207
artifact_name_pattern = f"pixi-build-backends-{ current_platform } "
202
208
else :
203
209
raise ValueError (f"Unsupported repository: { repo } " )
@@ -226,9 +232,9 @@ def download_github_artifact(
226
232
227
233
console .print (f"[blue]Found workflow: { target_workflow .name } " )
228
234
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" )
232
238
# Check the past five runs until a suitable candidate is found
233
239
for selected_run in itertools .islice (runs , 3 ):
234
240
artifacts = selected_run .get_artifacts ()
@@ -260,8 +266,8 @@ def download_github_artifact(
260
266
261
267
262
268
def main () -> None :
263
- # Load environment variables from .env file
264
- load_dotenv ()
269
+ # Load environment files
270
+ load_env_files ()
265
271
266
272
parser = argparse .ArgumentParser (description = "Download artifacts from GitHub Actions" )
267
273
parser .add_argument (
@@ -281,13 +287,19 @@ def main() -> None:
281
287
282
288
args = parser .parse_args ()
283
289
284
- # Set repo and workflow based on repository choice
290
+ # Set repo and workflow based on repository choice, with CI overrides
285
291
if args .repo == "pixi" :
286
- repo = " prefix-dev/pixi"
292
+ repo = os . getenv ( "PIXI_CI_REPO_NAME" , " prefix-dev/pixi")
287
293
workflow = "CI"
294
+ target_branch = os .getenv ("PIXI_CI_REPO_BRANCH" , "main" )
288
295
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")
290
297
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 } " )
291
303
292
304
# Hardcode output directory to "artifacts"
293
305
output_dir = Path ("artifacts" )
@@ -302,7 +314,9 @@ def main() -> None:
302
314
sys .exit ()
303
315
304
316
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
+ )
306
320
console .print ("[green][SUCCESS] Download completed successfully!" )
307
321
sys .exit (0 )
308
322
except Exception as e :
0 commit comments