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
22 changes: 18 additions & 4 deletions .github/workflows/ci.yml
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
docs_only: ${{ steps.changes.outputs.docs_only }}
tier3_platform: ${{ steps.changes.outputs.tier3_platform }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
Expand All @@ -37,6 +38,7 @@ jobs:
if ! git show "$BASE_SHA:scripts/classify_ci_changes.py" > "$classifier"; then
echo "::notice::Trusted classifier is not present on the base branch; running full CI."
echo "docs_only=false" >> "$GITHUB_OUTPUT"
echo "tier3_platform=true" >> "$GITHUB_OUTPUT"
exit 0
fi
python3 "$classifier" --base "$BASE_SHA" --head "$HEAD_SHA"
Expand Down Expand Up @@ -359,10 +361,13 @@ jobs:
"$RUNNER_TEMP/skillevaluator-wheel-3.12/bin/python" \
"$GITHUB_WORKSPACE/scripts/ci/smoke_harbor_verifier.py" --python "$task_python"

# This job tests operating-system behaviour of Tier 3, so on a pull request it
# runs only when the classifier says the change can affect it. It is skipped
# only on an explicit "false": a push to main leaves the output empty and runs it.
tier3-macos:
name: Tier 3 macOS contract and progress
needs: classify-changes
if: ${{ !cancelled() && needs.classify-changes.outputs.docs_only != 'true' }}
if: ${{ !cancelled() && needs.classify-changes.outputs.docs_only != 'true' && needs.classify-changes.outputs.tier3_platform != 'false' }}
runs-on: macos-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
Expand All @@ -384,11 +389,17 @@ jobs:
tests/test_tier3_progress.py
tests/test_tier3_result_display.py
tests/test_harbor_runtime_preflight.py
tests/embedding/test_catalog.py::TestCatalogPersistence::test_catalog_io_supports_root_owned_tmp_alias

# Tier 2 is platform-independent Python, and Linux and Windows run the same
# tests on every pull request. This job never failed for a macOS-specific
# reason, so it runs after merge only. Its one macOS-only test, the /tmp
# alias test, runs in the Tier 3 macOS job above on every pull request. The
# job stays defined, and is skipped on pull requests, so the required check
# of the same name still reports.
tier2-macos:
name: Tier 2 (macos-latest)
needs: classify-changes
if: ${{ !cancelled() && needs.classify-changes.outputs.docs_only != 'true' }}
if: ${{ github.event_name != 'pull_request' }}
runs-on: macos-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
Expand Down Expand Up @@ -553,10 +564,13 @@ jobs:
'@ | & $basePython -
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

# This job tests operating-system behaviour of Tier 3, so on a pull request it
# runs only when the classifier says the change can affect it. It is skipped
# only on an explicit "false": a push to main leaves the output empty and runs it.
native-windows-local-mode:
name: Native Windows local mode fails closed
needs: classify-changes
if: ${{ !cancelled() && needs.classify-changes.outputs.docs_only != 'true' }}
if: ${{ !cancelled() && needs.classify-changes.outputs.docs_only != 'true' && needs.classify-changes.outputs.tier3_platform != 'false' }}
runs-on: windows-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
Expand Down
81 changes: 75 additions & 6 deletions scripts/classify_ci_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,74 @@
DOC_FILES = frozenset({b"fern/docs.yml", b"CHANGELOG.md", b"README.md"})
KNOWN_STATUSES = frozenset(b"ACDMRTUXB")

# The Tier 3 platform jobs are the macOS sandbox tests and the native Windows
# local-mode check. They exist for operating-system behaviour, and that code
# lives under these source paths. The Linux jobs run the same test files, so a
# change anywhere else can only break those tests in a way Linux already shows.
SOURCE_ROOT = b"src/skillevaluator"
TESTS_ROOT = b"tests"
TIER3_PLATFORM_SOURCE = (b"src/skillevaluator/tier3", b"src/skillevaluator/utils")
# The test files the two jobs run. tests/test_ci_workflows.py checks this list
# against the jobs' commands in ci.yml.
TIER3_PLATFORM_TESTS = frozenset(
{
b"tests/embedding/test_catalog.py",
b"tests/test_harbor_local_mode.py",
b"tests/test_harbor_local_sandbox.py",
b"tests/test_harbor_runtime_preflight.py",
b"tests/test_local_mode_contract.py",
b"tests/test_tier3_progress.py",
b"tests/test_tier3_result_display.py",
b"tests/validators/test_rubric_eval.py",
}
)
# Shared by every test: fixtures the jobs' tests read, and anything pytest loads for them.
TIER3_PLATFORM_TEST_SUPPORT = b"tests/fixtures"


def _is_documentation(path: bytes) -> bool:
return path.startswith(DOC_PREFIXES) or path in DOC_FILES


def is_docs_only(paths: Sequence[bytes]) -> bool:
"""Return whether every changed path is documentation the docs lane covers."""
return bool(paths) and all(path.startswith(DOC_PREFIXES) or path in DOC_FILES for path in paths)
return bool(paths) and all(_is_documentation(path) for path in paths)


def _is_under(path: bytes, root: bytes) -> bool:
"""Whether ``path`` is ``root`` or inside it. A directory swapped for a file or link reports its bare name."""
return path == root or path.startswith(root + b"/")


def _is_test_module(path: bytes) -> bool:
name = path.rsplit(b"/", 1)[-1]
return (name.startswith(b"test_") and name.endswith(b".py")) or name.endswith(b"_test.py")


def _touches_tier3_platform(path: bytes) -> bool:
if _is_documentation(path):
return False
if path != SOURCE_ROOT and _is_under(path, SOURCE_ROOT):
# ``tier3`` also matches top-level modules such as ``tier3_environments.py``.
return any(path.startswith(prefix) for prefix in TIER3_PLATFORM_SOURCE)
if path != TESTS_ROOT and _is_under(path, TESTS_ROOT):
if _is_under(path, TIER3_PLATFORM_TEST_SUPPORT):
return True
if _is_test_module(path):
return path in TIER3_PLATFORM_TESTS
# A conftest, a helper module or other test data: it may be loaded by any test.
return path.endswith(b".py")
# Dependencies, CI configuration, scripts and anything else unrecognized.
return True


def is_tier3_platform_related(paths: Sequence[bytes]) -> bool:
"""Return whether a change can alter the result of the Tier 3 platform jobs.

The answer is ``True`` unless every changed path is known not to matter, so
an unrecognized path, or no paths at all, runs the jobs.
"""
return not paths or any(_touches_tier3_platform(path) for path in paths)


def parse_name_status_z(payload: bytes) -> list[bytes]:
Expand Down Expand Up @@ -94,13 +158,16 @@ def changed_paths(repo: Path, base: str, head: str) -> list[bytes]:
return parse_name_status_z(result.stdout)


def _write_result(docs_only: bool) -> None:
line = f"docs_only={'true' if docs_only else 'false'}"
def _write_result(docs_only: bool, tier3_platform: bool) -> None:
lines = "".join(
f"{name}={'true' if value else 'false'}\n"
for name, value in (("docs_only", docs_only), ("tier3_platform", tier3_platform))
)
output_path = os.environ.get("GITHUB_OUTPUT")
if output_path:
with Path(output_path).open("a", encoding="utf-8") as output:
output.write(f"{line}\n")
print(line)
output.write(lines)
print(lines, end="")


def _parser() -> argparse.ArgumentParser:
Expand All @@ -119,11 +186,13 @@ def main(argv: Sequence[str] | None = None) -> int:
if not paths:
raise ValueError("no changed paths found")
docs_only = is_docs_only(paths)
tier3_platform = is_tier3_platform_related(paths)
except (OSError, subprocess.CalledProcessError, ValueError) as error:
print(f"change classification failed; falling back to full CI: {error}", file=sys.stderr)
docs_only = False
tier3_platform = True

_write_result(docs_only)
_write_result(docs_only, tier3_platform)
return 0


Expand Down
Loading
Loading