From a225d4a82dc1b02bfa131d1a63d6435f6cda365b Mon Sep 17 00:00:00 2001 From: tercel Date: Tue, 1 Dec 2026 08:59:01 +0800 Subject: [PATCH] chore(ci): scope Surface workflows by component Signed-off-by: tercel --- .github/workflows/docs.yml | 31 +++++++++--- .github/workflows/pages.yml | 1 + .github/workflows/python.yml | 31 ++++++++++-- .github/workflows/rust.yml | 45 +++++++++++------ .github/workflows/typescript.yml | 21 +++++++- README.md | 16 ++++++ scripts/ci-components.py | 84 ++++++++++++++++++++++++++++++++ scripts/test_ci_components.py | 43 ++++++++++++++++ 8 files changed, 242 insertions(+), 30 deletions(-) create mode 100644 scripts/ci-components.py create mode 100644 scripts/test_ci_components.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 94450696..54f26473 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,34 +6,49 @@ on: - '*/docs/**' - '*/mkdocs.yml' - '.github/workflows/docs.yml' + - 'scripts/ci-components.py' + - 'scripts/test_ci_components.py' - 'scripts/build-docs.sh' - '*/scripts/gen_llms_full.py' - '*/README.md' - '*/CHANGELOG.md' - '*/llms.txt' + - '*/apcore-*-logo.svg' + # Pages already builds the complete site on main when documentation changes. push: branches: [main] paths: - - '*/docs/**' - - '*/mkdocs.yml' - '.github/workflows/docs.yml' - - 'scripts/build-docs.sh' - - '*/scripts/gen_llms_full.py' - - '*/README.md' - - '*/CHANGELOG.md' - - '*/llms.txt' + - 'scripts/ci-components.py' + - 'scripts/test_ci_components.py' workflow_dispatch: permissions: contents: read jobs: + changes: + runs-on: ubuntu-latest + outputs: + components: ${{ steps.select.outputs.components }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + persist-credentials: false + - name: Test component selection + run: python3 -m unittest discover -s scripts -p test_ci_components.py + - id: select + run: python3 scripts/ci-components.py docs + docs: + needs: changes + if: needs.changes.outputs.components != '[]' runs-on: ubuntu-latest strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] + component: ${{ fromJSON(needs.changes.outputs.components) }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 82248a36..8cadffa4 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -13,6 +13,7 @@ on: - '*/README.md' - '*/CHANGELOG.md' - '*/llms.txt' + - '*/apcore-*-logo.svg' workflow_dispatch: concurrency: diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 6e87c501..f68a3433 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -10,6 +10,7 @@ on: - 'uv.lock' - 'mcp/examples/management-reference/**' - '.github/workflows/python.yml' + - 'scripts/ci-components.py' pull_request: paths: *python-paths workflow_dispatch: @@ -21,16 +22,34 @@ env: CORE_REF: c89df2fcbe9224104151222006eeaa1b91f08d5e jobs: + changes: + runs-on: ubuntu-latest + outputs: + components: ${{ steps.select.outputs.components }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + persist-credentials: false + - id: select + run: python3 scripts/ci-components.py python + test: + needs: changes + if: needs.changes.outputs.components != '[]' name: Python ${{ matrix.version }} (${{ matrix.component }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] - version: ['3.12'] - include: - - component: toolkit + component: ${{ fromJSON(needs.changes.outputs.components) }} + version: ['3.12', '3.11'] + exclude: + - component: mcp + version: '3.11' + - component: a2a + version: '3.11' + - component: cli version: '3.11' defaults: run: @@ -93,12 +112,14 @@ jobs: "$legacy/bin/python" "$example/legacy_smoke.py" "$reference/bin/python" package: + needs: changes + if: needs.changes.outputs.components != '[]' name: Python distribution (${{ matrix.component }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] + component: ${{ fromJSON(needs.changes.outputs.components) }} defaults: run: working-directory: ${{ matrix.component }}/python diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d022d6bd..1f9cc1a8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,21 +3,16 @@ name: Rust surfaces on: push: branches: [main] - paths: + paths: &rust-paths - '*/rust/**' - '*/conformance/**' - 'Cargo.toml' - 'Cargo.lock' - '.github/workflows/rust.yml' + - 'scripts/ci-components.py' - 'scripts/verify-rust-surface.py' pull_request: - paths: - - '*/rust/**' - - '*/conformance/**' - - 'Cargo.toml' - - 'Cargo.lock' - - '.github/workflows/rust.yml' - - 'scripts/verify-rust-surface.py' + paths: *rust-paths workflow_dispatch: permissions: @@ -31,16 +26,34 @@ env: CORE_CRATE_SHA256: 058a6b8bdece7890ecebbf9d988efc5186f806de838b230cb7c77549d1965228 jobs: + changes: + runs-on: ubuntu-latest + outputs: + components: ${{ steps.select.outputs.components }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + persist-credentials: false + - id: select + run: python3 scripts/ci-components.py rust + source: - name: Rust source tests (${{ matrix.component }}) + needs: changes + if: needs.changes.outputs.components != '[]' + name: Rust source tests (${{ matrix.component }}, ${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] - os: [ubuntu-latest] - include: - - component: mcp + component: ${{ fromJSON(needs.changes.outputs.components) }} + os: [ubuntu-latest, windows-latest] + exclude: + - component: toolkit + os: windows-latest + - component: a2a + os: windows-latest + - component: cli os: windows-latest defaults: run: @@ -68,7 +81,7 @@ jobs: ~/.cargo/git ${{ matrix.component }}/rust/target key: ${{ runner.os }}-cargo-${{ matrix.component }}-${{ hashFiles('*/rust/Cargo.lock') }} - - run: cargo fmt --all -- --check + - run: cargo fmt --package apcore-${{ matrix.component }} -- --check - name: Check and test against the pinned Core and checkout Toolkit shell: bash env: @@ -79,12 +92,14 @@ jobs: "$GITHUB_WORKSPACE/.ci-apcore-core/rust" package: + needs: changes + if: needs.changes.outputs.components != '[]' name: Rust crate verification (${{ matrix.component }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] + component: ${{ fromJSON(needs.changes.outputs.components) }} defaults: run: working-directory: ${{ matrix.component }}/rust diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index fa5d5d11..051595e3 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -9,6 +9,7 @@ on: - 'pnpm-lock.yaml' - 'pnpm-workspace.yaml' - '.github/workflows/typescript.yml' + - 'scripts/ci-components.py' - 'scripts/verify-typescript-surface-package.sh' pull_request: paths: *typescript-paths @@ -21,13 +22,27 @@ env: CORE_REF: c89df2fcbe9224104151222006eeaa1b91f08d5e jobs: + changes: + runs-on: ubuntu-latest + outputs: + components: ${{ steps.select.outputs.components }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + persist-credentials: false + - id: select + run: python3 scripts/ci-components.py typescript + test: + needs: changes + if: needs.changes.outputs.components != '[]' name: TypeScript (${{ matrix.component }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] + component: ${{ fromJSON(needs.changes.outputs.components) }} defaults: run: working-directory: ${{ matrix.component }}/typescript @@ -111,12 +126,14 @@ jobs: if: matrix.component == 'toolkit' package: + needs: changes + if: needs.changes.outputs.components != '[]' name: npm distribution (${{ matrix.component }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - component: [toolkit, mcp, a2a, cli] + component: ${{ fromJSON(needs.changes.outputs.components) }} defaults: run: working-directory: ${{ matrix.component }}/typescript diff --git a/README.md b/README.md index 5088ff08..fa38d3cb 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,22 @@ Rust and TypeScript component lockfiles pin the independent package graphs. The distribution workflows verify component builds with these locks and the published manifests' registry dependencies. +## Continuous integration + +Source and distribution checks run for the affected language and component. +Changes to a component's `conformance/` directory run its Python, Rust, and +TypeScript checks. Toolkit implementation changes also run MCP, A2A, and CLI +for the same language. Changes to a language's workspace files run its full +component matrix. You can run each full matrix manually from GitHub Actions. + +Pull requests build the affected documentation sites. On `main`, the Pages +workflow builds and publishes the combined site. + +For Core candidate compatibility, manually run +[Core distribution verification](https://github.com/apstack/apcore/actions/workflows/packages.yml) +at the candidate commit. Supply its completed run ID to the +[Core candidate compatibility workflow](.github/workflows/core-candidate.yml). + ## Coordinated release candidates | Component | PyPI, npm, and crates.io | diff --git a/scripts/ci-components.py b/scripts/ci-components.py new file mode 100644 index 00000000..70ab9edc --- /dev/null +++ b/scripts/ci-components.py @@ -0,0 +1,84 @@ +"""Select affected Surface components from the GitHub Actions event diff.""" + +from __future__ import annotations + +import argparse +import json +import os +import subprocess +from pathlib import Path + +COMPONENTS = ("toolkit", "mcp", "a2a", "cli") +SHARED_INPUTS = { + "python": {"pyproject.toml", "uv.lock"}, + "rust": {"Cargo.toml", "Cargo.lock", "scripts/verify-rust-surface.py"}, + "typescript": {"pnpm-lock.yaml", "pnpm-workspace.yaml", "scripts/verify-typescript-surface-package.sh"}, + "docs": {"scripts/build-docs.sh"}, +} +DOC_FILES = {"mkdocs.yml", "README.md", "CHANGELOG.md", "llms.txt", "scripts/gen_llms_full.py"} + + +def changed_paths() -> list[str] | None: + """Return None when a complete diff is unavailable or the run is manual.""" + event_name = os.environ["GITHUB_EVENT_NAME"] + if event_name == "workflow_dispatch": + return None + + event = json.loads(Path(os.environ["GITHUB_EVENT_PATH"]).read_text(encoding="utf-8")) + if event_name == "pull_request": + pull_request = event["pull_request"] + revisions = pull_request["base"]["sha"] + "..." + pull_request["head"]["sha"] + elif event_name == "push": + revisions = event["before"] + ".." + event["after"] + else: + raise ValueError(f"Unsupported event: {event_name}") + + # Disabling rename detection includes both paths when a file moves between components. + result = subprocess.run( + ["git", "diff", "--name-only", "-z", "--no-renames", revisions, "--"], + capture_output=True, + check=False, + ) + if result.returncode != 0: + print("::warning::Could not compare event commits, so all components will run.") + return None + return [os.fsdecode(path) for path in result.stdout.split(b"\0") if path] + + +def select_components(scope: str, paths: list[str] | None) -> list[str]: + shared = SHARED_INPUTS[scope] | {".github/workflows/" + scope + ".yml", "scripts/ci-components.py"} + if paths is None or shared.intersection(paths): + return list(COMPONENTS) + + affected = set() + for path in paths: + component, _, relative = path.partition("/") + if component not in COMPONENTS: + continue + if scope == "docs": + if relative in DOC_FILES or relative == f"apcore-{component}-logo.svg" or relative.startswith("docs/"): + affected.add(component) + elif relative.startswith(scope + "/"): + # All release components use the checked-out Toolkit of their language. + if component == "toolkit": + return list(COMPONENTS) + affected.add(component) + elif relative.startswith("conformance/"): + affected.add(component) + elif scope == "python" and component == "mcp" and relative.startswith("examples/management-reference/"): + affected.add(component) + return [component for component in COMPONENTS if component in affected] + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("scope", choices=SHARED_INPUTS) + args = parser.parse_args() + components = select_components(args.scope, changed_paths()) + print("Components:", ", ".join(components) or "none") + with Path(os.environ["GITHUB_OUTPUT"]).open("a", encoding="utf-8") as output: + output.write(f"components={json.dumps(components)}\n") + + +if __name__ == "__main__": + main() diff --git a/scripts/test_ci_components.py b/scripts/test_ci_components.py new file mode 100644 index 00000000..2b3aaa16 --- /dev/null +++ b/scripts/test_ci_components.py @@ -0,0 +1,43 @@ +"""Regression tests for Surface CI routing.""" + +import runpy +import unittest +from pathlib import Path + +select_components = runpy.run_path(str(Path(__file__).with_name("ci-components.py")))["select_components"] +LANGUAGES = ("python", "rust", "typescript") +ALL_COMPONENTS = ["toolkit", "mcp", "a2a", "cli"] + + +class ComponentSelectionTests(unittest.TestCase): + def test_implementation_changes_stay_in_their_language(self) -> None: + for language in LANGUAGES: + with self.subTest(language=language): + self.assertEqual(select_components(language, [f"mcp/{language}/src/file"]), ["mcp"]) + self.assertEqual(select_components(language, [f"toolkit/{language}/src/file"]), ALL_COMPONENTS) + self.assertEqual(select_components(language, ["mcp/docs/index.md"]), []) + + def test_component_fixtures_run_all_its_languages(self) -> None: + for language in LANGUAGES: + with self.subTest(language=language): + self.assertEqual(select_components(language, ["a2a/conformance/fixtures/case.json"]), ["a2a"]) + self.assertEqual(select_components(language, ["toolkit/conformance/fixtures/case.json"]), ["toolkit"]) + + def test_shared_workspace_inputs_select_all_components_of_their_language(self) -> None: + for language, lock in zip(LANGUAGES, ("uv.lock", "Cargo.lock", "pnpm-lock.yaml"), strict=True): + with self.subTest(language=language): + self.assertEqual(select_components(language, [lock]), ALL_COMPONENTS) + + def test_selects_the_mcp_python_management_example(self) -> None: + self.assertEqual(select_components("python", ["mcp/examples/management-reference/example.py"]), ["mcp"]) + + def test_docs_are_routed_to_the_affected_sites(self) -> None: + self.assertEqual(select_components("docs", ["mcp/docs/index.md", "cli/apcore-cli-logo.svg"]), ["mcp", "cli"]) + self.assertEqual(select_components("docs", ["scripts/build-docs.sh"]), ALL_COMPONENTS) + self.assertEqual(select_components("docs", ["mcp/python/src/file.py"]), []) + + def test_manual_runs_missing_diffs_and_selector_changes_select_every_component(self) -> None: + for scope in (*LANGUAGES, "docs"): + with self.subTest(scope=scope): + self.assertEqual(select_components(scope, None), ALL_COMPONENTS) + self.assertEqual(select_components(scope, ["scripts/ci-components.py"]), ALL_COMPONENTS)