Skip to content

Commit f77625f

Browse files
committed
feat(ci): check only affected Rust packages
Replace full-workspace Rust pre-build checks with an affected-package selection flow. The new xtask maps changed Git paths to workspace packages, expands the selection to transitive workspace dependents, and falls back to the full workspace when a change is global or cannot be mapped safely. This reduces CI time for package-scoped changes while preserving coverage for shared inputs such as Cargo files, toolchain config, CI config, custom lints, xtask code, and other global build inputs. The affected check now runs: - isolated default-feature package builds - Clippy with all targets/features - carbide-lints with all targets/features Also add reviewer guidance for keeping the global-path fallback list up to date. Signed-off-by: Dmitry Porokh <dporokh@nvidia.com>
1 parent 0082abd commit f77625f

7 files changed

Lines changed: 930 additions & 25 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,12 @@ jobs:
11031103
steps:
11041104
- name: Checkout code
11051105
uses: actions/checkout@v4
1106+
with:
1107+
# actions/checkout fetches only one commit by default; a depth of 0 removes
1108+
# that limit and fetches the full history. The `check-affected`
1109+
# cargo-make task needs that history to find HEAD's common ancestor with
1110+
# origin/main.
1111+
fetch-depth: 0
11061112

11071113
# PostgreSQL is required because sqlx proc macros (sqlx::query!) connect to
11081114
# a local database at compile time to validate SQL queries and return types.
@@ -1114,11 +1120,13 @@ jobs:
11141120
sudo -u postgres psql -c "ALTER USER root WITH SUPERUSER;"
11151121
createdb root
11161122
1117-
- name: Run clippy
1118-
run: cargo make --no-workspace clippy-flow
1119-
1120-
- name: Run carbide lints
1121-
run: cargo make carbide-lints
1123+
# `check-affected` selects packages and replaces separate CI steps for
1124+
# Clippy, carbide-lints, and isolated default-feature builds. Formatting,
1125+
# workspace dependency, license, and ban checks remain global below.
1126+
- name: Run affected Rust checks
1127+
env:
1128+
AFFECTED_BASE: origin/main
1129+
run: cargo make --no-workspace check-affected
11221130

11231131
- name: Check TOML formatting
11241132
run: taplo fmt --check || echo "Please format toml files"
@@ -1135,9 +1143,6 @@ jobs:
11351143
- name: Check bans
11361144
run: cargo make --no-workspace check-bans
11371145

1138-
- name: Check isolated package builds
1139-
run: cargo xtask check-isolated-package-builds
1140-
11411146
- name: Check repository is clean
11421147
run: bash scripts/check-repo-clean.sh "Core pre-build checks"
11431148

AGENTS.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,27 @@ cargo make format-nightly # Also sort imports
124124
> `carbide-lints`. The stable toolchain pinned in `rust-toolchain.toml` is used
125125
> for everything else.
126126
127-
### Top-level Makefile (rest-api entrypoint)
127+
#### Affected-package CI
128+
129+
When reviewing changes that add, remove, rename, or repurpose shared Rust build
130+
inputs, verify that `is_global_path()` in
131+
`crates/xtask/src/affected_packages.rs` remains up to date. Currently matched
132+
shared inputs include the root Cargo files and `Cargo.lock`, cargo-make files,
133+
Rust toolchain configuration, `.cargo/`, CI configuration, custom lint and xtask
134+
code, and `include/`. Add any newly introduced or repurposed shared generated or
135+
configuration directories to the predicate. If a changed path cannot be mapped
136+
safely to exactly one workspace package, affected-package selection must fall
137+
back to the full workspace.
138+
139+
### Top-level Makefile entrypoints
128140

129141
A top-level [`Makefile`](Makefile) at the repo root provides a thin
130-
discoverable entrypoint for the `rest-api/` Go services. It just
131-
delegates to `rest-api/Makefile`.
142+
discoverable entrypoint for selected Core workflows and the `rest-api/` Go
143+
services.
132144

133145
```bash
134-
make help # default goal: list rest-* targets
146+
make help # default goal: list available targets
147+
make core/check-affected # check affected Rust packages and workspace dependents
135148
make rest-build # build rest-api Go binaries
136149
make rest-test # run rest-api unit tests
137150
make rest-lint # lint rest-api
@@ -142,8 +155,8 @@ make rest-kind-reset # spin up the local kind dev cluster (~10 min)
142155
make rest-api/<target> # pass any target through to rest-api/Makefile
143156
```
144157

145-
Core (Rust) tasks are not in this Makefile; use cargo and `cargo make`
146-
directly as documented above.
158+
Other Core (Rust) tasks use cargo and `cargo make` directly as documented
159+
above.
147160

148161
## Coding Conventions
149162

Makefile

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
# Top-level Makefile for the rest-api/ Go services.
17+
# Top-level Makefile for Core and rest-api workflows.
1818
#
19-
# Thin discoverable entrypoint that delegates to rest-api/Makefile.
20-
# rest-api/Makefile continues to work directly; this file is an
21-
# additive convenience layer.
19+
# Thin discoverable entrypoint that delegates Core tasks to cargo-make and Rest
20+
# tasks to rest-api/Makefile. Both underlying entrypoints continue to work
21+
# directly; this file is an additive convenience layer.
2222
#
2323
# Run `make help` (default goal) for the inventory of targets.
2424

2525
SHELL := /bin/bash
2626

2727
.DEFAULT_GOAL := help
2828

29+
AFFECTED_BASE ?= origin/main
30+
2931
# =============================================================================
3032
# Help (default goal)
3133
# =============================================================================
@@ -38,12 +40,23 @@ help: ## Show this help and exit (default goal)
3840
@echo "Container images (build from a clean clone):"
3941
@grep -E '^images[a-zA-Z0-9_-]*:.*## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "} {printf " %-26s %s\n", $$1, $$2}'
4042
@echo ""
43+
@echo "Core (Rust):"
44+
@grep -E '^core/check-affected:.*## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "} {printf " %-26s %s\n", $$1, $$2}'
45+
@echo ""
4146
@echo "Rest (Go services in rest-api/):"
4247
@grep -E '^rest-[a-zA-Z0-9_-]+:.*## ' $(MAKEFILE_LIST) | awk 'BEGIN{FS=":.*?## "} {printf " %-26s %s\n", $$1, $$2}'
4348
@echo " rest-api/<target> Pass any target through to rest-api/Makefile"
4449
@echo ""
4550
@echo " cat rest-api/Makefile See all rest-api/ targets directly"
4651

52+
# =============================================================================
53+
# Core (Rust; delegate to cargo-make)
54+
# =============================================================================
55+
56+
.PHONY: core/check-affected
57+
core/check-affected: ## Run Clippy, custom lints, and isolated builds for affected Rust packages
58+
AFFECTED_BASE="$(AFFECTED_BASE)" cargo make --no-workspace check-affected
59+
4760
# =============================================================================
4861
# Getting started (build host setup)
4962
# =============================================================================

Makefile.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,50 @@ workspace = false
828828
description = "Check that workspace packages build independently with default features"
829829
script = ["cargo xtask check-isolated-package-builds"]
830830

831+
[tasks.check-affected]
832+
workspace = false
833+
description = "Run compilation checks for changed Rust packages and their workspace dependents"
834+
script = '''
835+
set -eu
836+
837+
base="${AFFECTED_BASE:-origin/main}"
838+
affected_packages="$(cargo xtask affected-packages --base "${base}")"
839+
840+
if [ -z "${affected_packages}" ]; then
841+
echo "No affected Rust packages were selected" >&2
842+
exit 1
843+
fi
844+
845+
echo "Affected Rust packages:"
846+
printf ' %s\n' "${affected_packages}"
847+
848+
set --
849+
while IFS= read -r package; do
850+
[ -n "${package}" ] || continue
851+
set -- "$@" -p "${package}"
852+
done <<EOF
853+
${affected_packages}
854+
EOF
855+
856+
# These checks use different feature sets and compiler drivers. Keep their Cargo
857+
# artifacts separate so one check does not invalidate another check's cache.
858+
target_dir="${CARGO_TARGET_DIR:-${REPO_ROOT}/target}"
859+
860+
echo "Checking isolated builds for affected packages"
861+
CARGO_TARGET_DIR="${target_dir}/isolated-checks" \
862+
cargo xtask check-isolated-package-builds "$@"
863+
864+
echo "Running Clippy for affected packages"
865+
cargo make --no-workspace install-clippy
866+
CARGO_TARGET_DIR="${target_dir}/clippy" \
867+
cargo clippy --locked --all-targets --all-features "$@"
868+
869+
echo "Running carbide-lints for affected packages"
870+
cargo make --no-workspace setup-carbide-lints
871+
CARGO_TARGET_DIR="${target_dir}/carbide-lints" \
872+
cargo carbide-lints --all-targets --all-features "$@"
873+
'''
874+
831875
[tasks.check-licenses]
832876
workspace = false
833877
description = "Check cargo-deny against licenses we're using to validate that we're not introducing new licenses inadvertently"

0 commit comments

Comments
 (0)