Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions .github/workflows/workspace-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,22 @@ jobs:
# spec) — HowTo* are tutorial repos with no profile_release.yaml and
# aren't part of the release-fidelity surface. mode=smoke keeps the
# full workspace/tutorial sweep plus the Euclid pipeline.
#
# ORDERED names projects whose smoke_tests.txt is order-dependent: they
# become ONE matrix entry carrying the list (run via run_python.py
# --list) instead of one shard per scripts/<subdir>. The Euclid
# pipeline's scripts/tools/diagnose_latent.py replays fits that
# start_here.py and the top-level scripts/*.py produce earlier in the
# list; sharded per directory it ran alone and failed
# (cloud#39224774724, PyAutoHands#317).
ORDERED=""
if [ "$MODE" = "release" ]; then
PROJECTS="autofit autogalaxy autolens autofit_test autogalaxy_test autolens_test"
else
PROJECTS="autofit autogalaxy autolens autofit_test autogalaxy_test autolens_test howtogalaxy howtolens howtofit euclid"
ORDERED="--ordered euclid"
fi
matrix="$(python3 PyAutoHands/autohands/script_matrix.py $PROJECTS)"
matrix="$(python3 PyAutoHands/autohands/script_matrix.py $PROJECTS $ORDERED)"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"

generate_notebooks:
Expand Down Expand Up @@ -357,12 +367,25 @@ jobs:
pip install "nufftax>=0.6.1,<0.7.0"
- name: "Run Python scripts [mode=smoke, source-shadowed, smoke profile]"
if: needs.find_scripts.outputs.mode == 'smoke'
env:
SHARD_PROJECT: ${{ matrix.project.name }}
SHARD_DIRECTORY: ${{ matrix.project.directory }}
SHARD_SCRIPT_LIST: ${{ matrix.project.script_list }}
run: |
LIBS="$(pwd)/libs"
export PYTHONPATH="$LIBS/PyAutoNerves:$LIBS/PyAutoArray:$LIBS/PyAutoFit:$LIBS/PyAutoGalaxy:$LIBS/PyAutoLens:$(pwd)/PyAutoHands:$PYTHONPATH"
pushd workspace
# An ordered entry (script_matrix.py --ordered) carries its list and a
# directory relative to the workspace root ("."); its entries run in
# list order in one output dir. A per-directory shard (no list) keeps
# the historical scripts/<subdir> discovery run.
if [ -n "$SHARD_SCRIPT_LIST" ]; then
set -- "$SHARD_DIRECTORY" --list "$SHARD_SCRIPT_LIST"
else
set -- "scripts/$SHARD_DIRECTORY"
fi
python3 "$(pwd)/../PyAutoHands/autohands/run_python.py" \
"${{ matrix.project.name }}" "scripts/${{ matrix.project.directory }}" \
"$SHARD_PROJECT" "$@" \
--report-dir test-results
- name: "Run Python scripts [mode=release, wheels, release profile, no source on PYTHONPATH]"
if: needs.find_scripts.outputs.mode == 'release'
Expand All @@ -389,6 +412,9 @@ jobs:
# per-script in the workspace's own config/build/profile_smoke.yaml, rather
# than as a second run-wide number here (PyAutoHands#226).
BUILD_SCRIPT_TIMEOUT: "1800"
SHARD_PROJECT: ${{ matrix.project.name }}
SHARD_DIRECTORY: ${{ matrix.project.directory }}
SHARD_SCRIPT_LIST: ${{ matrix.project.script_list }}
run: |
# Deliberately NOT adding library source dirs to PYTHONPATH (closes
# Gap A) — `import autolens` etc. resolve to the pip-installed
Expand All @@ -408,15 +434,25 @@ jobs:
echo "::error::config/build/profile_release.yaml missing — no release profile defined for this workspace"
exit 1
fi
# Same shard shape as the smoke step (no project is ordered in
# release mode today; kept symmetric so one cannot drift).
if [ -n "$SHARD_SCRIPT_LIST" ]; then
set -- "$SHARD_DIRECTORY" --list "$SHARD_SCRIPT_LIST"
else
set -- "scripts/$SHARD_DIRECTORY"
fi
python3 "$(pwd)/../PyAutoHands/autohands/run_python.py" \
"${{ matrix.project.name }}" "scripts/${{ matrix.project.directory }}" \
"$SHARD_PROJECT" "$@" \
--report-dir test-results \
--env-config "$ENV_CONFIG"
- name: Upload script results
# The name's leg suffix is the shard's directory, or `ordered` for an
# ordered entry (script_matrix.py --ordered), whose directory is "." —
# one per project, so the (project, suffix) pair stays unique.
if: always()
uses: actions/upload-artifact@v4
with:
name: results-scripts-${{ matrix.project.name }}-${{ matrix.project.directory }}
name: results-scripts-${{ matrix.project.name }}-${{ matrix.project.script_list && 'ordered' || matrix.project.directory }}
path: workspace/test-results/
retention-days: 30
- name: Upload the per-script timings (scripts leg) under a globbable name
Expand Down Expand Up @@ -460,7 +496,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: smoke-timings-scripts-${{ matrix.project.name }}-${{ matrix.project.directory }}
name: smoke-timings-scripts-${{ matrix.project.name }}-${{ matrix.project.script_list && 'ordered' || matrix.project.directory }}
path: workspace/**/smoke_timings.json
if-no-files-found: ignore

Expand Down
88 changes: 84 additions & 4 deletions tests/test_workflow_wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ def test_validation_timing_artifact_names_carry_the_leg():
weekly run, so the name has to carry the (project, directory) pair the
script matrix keeps unique — exactly as the sibling `results-*` upload does.
"""
suffix = {
# An ordered entry's directory is "." (PyAutoHands#317), so the scripts
# leg names it `ordered`; per-directory shards keep their directory.
"scripts": "${{ matrix.project.script_list && 'ordered' || matrix.project.directory }}",
# The notebook leg never runs an ordered entry (euclid is gated off).
"notebooks": "${{ matrix.project.directory }}",
}
for job_name, leg in TIMING_LEGS:
name = _timing_step(job_name)["with"]["name"]
assert name == (
f"smoke-timings-{leg}-"
"${{ matrix.project.name }}-${{ matrix.project.directory }}"
)
assert name == f"smoke-timings-{leg}-${{{{ matrix.project.name }}}}-{suffix[leg]}"


def test_validation_timing_upload_cannot_fail_the_weekly_sweep():
Expand Down Expand Up @@ -388,10 +392,86 @@ def test_pipeline_is_selected_for_smoke_and_routes_to_its_checkout(tmp_path):
subprocess.run(["bash", "-ec", command], cwd=tmp_path,
env={**os.environ, "MODE": mode, "GITHUB_OUTPUT": str(output)}, check=True)
assert ("euclid" in output.read_text().split()) is expected
# euclid's smoke list is order-dependent: it must be one ordered shard,
# never per-directory (PyAutoHands#317) — and only where it is selected.
assert ("--ordered euclid" in output.read_text()) is expected
route = next(s["run"] for s in data["jobs"]["run_scripts"]["steps"] if s.get("id") == "ws")
route = route.replace("${{ matrix.project.name }}", "euclid")
output.write_text("")
subprocess.run(["bash", "-ec", route], env={**os.environ, "GITHUB_OUTPUT": str(output)}, check=True)
registry = yaml.safe_load((WORKFLOWS.parents[1] / "config/repos.yaml").read_text())
pipeline = registry["repos"]["pipelines"][0]["name"]
assert output.read_text().strip() == f"repo={pipeline}"


# --- ordered shards (PyAutoHands#317) --------------------------------------
#
# script_matrix.py --ordered emits ONE entry for an order-dependent project:
# {"name", "directory": ".", "script_list": "smoke_tests.txt"}. Both run steps
# must hand that list to run_python.py --list with the directory as given
# (relative to the workspace root, so root start_here.py and top-level
# scripts/*.py resolve), while per-directory shards keep "scripts/<dir>".

RUN_STEPS = (
"Run Python scripts [mode=smoke",
"Run Python scripts [mode=release",
)


def _run_step_argv(step_name, entry, tmp_path):
"""Execute a run step's shell against a stub run_python.py; return its argv."""
step = _step(_load("workspace-validation.yml")["jobs"]["run_scripts"], step_name)
env = {
**os.environ,
"SHARD_PROJECT": entry["name"],
"SHARD_DIRECTORY": entry["directory"],
"SHARD_SCRIPT_LIST": entry.get("script_list", ""),
}
for key, value in step.get("env", {}).items():
if "${{" not in str(value):
env[key] = str(value)
hands = tmp_path / "PyAutoHands/autohands"
hands.mkdir(parents=True, exist_ok=True)
argv_out = tmp_path / "argv.json"
(hands / "run_python.py").write_text(
"import json, sys; json.dump(sys.argv[1:], open(%r, 'w'))" % str(argv_out)
)
ws = tmp_path / "workspace"
(ws / "config/build").mkdir(parents=True, exist_ok=True)
(ws / "config/build/profile_release.yaml").write_text("defaults: {}\n")
subprocess.run(["bash", "-ec", step["run"]], cwd=tmp_path, env=env, check=True,
capture_output=True, text=True)
import json
return json.loads(argv_out.read_text())


def test_run_steps_read_the_shard_from_the_matrix_entry():
for name in RUN_STEPS:
env = _step(_load("workspace-validation.yml")["jobs"]["run_scripts"], name)["env"]
assert env["SHARD_PROJECT"] == "${{ matrix.project.name }}"
assert env["SHARD_DIRECTORY"] == "${{ matrix.project.directory }}"
assert env["SHARD_SCRIPT_LIST"] == "${{ matrix.project.script_list }}"


def test_ordered_entry_runs_its_list_from_the_workspace_root(tmp_path):
entry = {"name": "euclid", "directory": ".", "script_list": "smoke_tests.txt"}
for i, name in enumerate(RUN_STEPS):
argv = _run_step_argv(name, entry, tmp_path / str(i))
assert argv[:4] == ["euclid", ".", "--list", "smoke_tests.txt"]
assert "--report-dir" in argv


def test_per_directory_shard_keeps_its_historical_invocation(tmp_path):
entry = {"name": "autolens", "directory": "imaging"}
for i, name in enumerate(RUN_STEPS):
argv = _run_step_argv(name, entry, tmp_path / str(i))
assert argv[:2] == ["autolens", "scripts/imaging"]
assert "--list" not in argv


def test_ordered_results_artifact_name_is_valid_and_distinct():
upload = _step(_load("workspace-validation.yml")["jobs"]["run_scripts"], "Upload script results")
assert upload["with"]["name"] == (
"results-scripts-${{ matrix.project.name }}-"
"${{ matrix.project.script_list && 'ordered' || matrix.project.directory }}"
)
Loading