Skip to content

Commit bd2b950

Browse files
authored
Make pixi build testsuite more flexible (#53)
1 parent e85d08d commit bd2b950

File tree

5 files changed

+99
-19
lines changed

5 files changed

+99
-19
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Prevent Branch Override Merge
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
check-branch-override:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
12+
13+
- name: Set up pixi
14+
uses: prefix-dev/setup-pixi@main
15+
16+
- name: Check for branch override files
17+
run: pixi run check-branch-override

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ Also, check out the other Pixi tasks to run more tests on your local machine:
3131
pixi run test
3232
```
3333

34+
## Testing PR combinations in CI
35+
36+
To test a combination of PRs from this testsuite with PRs from [Pixi] or [pixi-build-backends]:
37+
38+
1. Create a `.env.ci` file with the following environment variables:
39+
```shell
40+
# Override pixi repository/branch
41+
PIXI_CI_REPO_NAME="your-username/pixi"
42+
PIXI_CI_REPO_BRANCH="your-feature-branch"
43+
44+
# Override build backends repository/branch
45+
BUILD_BACKENDS_CI_REPO_NAME="your-username/pixi-build-backends"
46+
BUILD_BACKENDS_CI_REPO_BRANCH="your-feature-branch"
47+
```
48+
2. The CI will use these overrides when downloading artifacts for testing
49+
3. **Important**: Remove `.env.ci` before merging to main (CI will prevent merge if present)
50+
51+
This allows you to test how your testsuite changes work with specific branches from the other repositories.
52+
3453

3554
[Pixi]: https://github.com/prefix-dev/pixi
3655
[pixi-build-backends]: https://github.com/prefix-dev/pixi-build-backends

pixi.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ test-specific-test = { cmd = "pytest -k '{{ test_substring }}'", args = [
4040
# Update one test channel by passing on value of `mappings.toml`
4141
# e.g. "multiple_versions_channel_1"
4242
build-repos = { cmd = "python scripts/build-repos.py", description = "Update and build external repositories (PIXI and BUILD_BACKENDS)" }
43+
check-branch-override = { cmd = "python scripts/check-branch-override.py", description = "Check for branch override files that shouldn't be merged" }
4344
download-artifacts = { cmd = "python scripts/download-artifacts.py" }
4445
update-lockfiles = { cmd = "python scripts/update-lockfiles.py {{ folder }}", args = [
4546
{ "arg" = "folder", "default" = "" },

scripts/check-branch-override.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to check for CI override files that shouldn't be merged to main.
4+
5+
This script ensures that .env.ci files used for testing PR combinations
6+
don't accidentally get merged to the main branch.
7+
"""
8+
9+
import sys
10+
from pathlib import Path
11+
12+
13+
def main() -> None:
14+
"""Check if CI override files exist and exit with error if found."""
15+
repo_root = Path(__file__).parent.parent
16+
override_file = repo_root / ".env.ci"
17+
18+
if override_file.exists():
19+
print("❌ ERROR: .env.ci file detected")
20+
print("This file is used for testing PR combinations and should not be merged to main")
21+
print("Please remove .env.ci from your branch")
22+
sys.exit(1)
23+
else:
24+
print("✅ No CI override files detected - safe to merge")
25+
sys.exit(0)
26+
27+
28+
if __name__ == "__main__":
29+
main()

scripts/download-artifacts.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
173185
def 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

262268
def 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

Comments
 (0)