From 897fd38066d4909f15e4f12067de715374c911d7 Mon Sep 17 00:00:00 2001 From: Erfan Yousefi Date: Wed, 24 Jun 2026 23:52:44 +0200 Subject: [PATCH] build: add Makefile as the single entry point for dev/CI/release One make interface that runs the same commands locally and in CI. - `make validate` = fmt-check -> check -> test -> release build (the pre-PR gate). - `make ci` (alias) is now what .github/workflows/ci.yml runs; release.yml's validate stage runs `make validate` and its per-target build/package runs `make package TARGET=` (byte-identical artifact: krust-.tar.gz containing krust-/{krust,README.md,LICENSE}). - Convenience targets: fmt, check, clippy, test, build(-release), run, clean, package; lab-{up,load,contexts,crds,churn,down} wrap scripts/scale; and bench/bench-contexts/soak/discover/metrics wrap the headless harnesses. - cargo is resolved robustly (PATH, then a Homebrew keg-only rustup, else plain cargo) and its dir is put on PATH so external subcommands (cargo-fmt, cargo-clippy) and rustc resolve even when rustup is keg-only. - dist/ (package output) gitignored. Docs (contributor guide, AGENTS, README) point at `make validate`. Verified locally: make validate green (85 tests), make package produces the release tarball, cargo resolves with no keg on PATH. CI running `make ci` on this PR is the cross-environment proof. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/ci.yml | 13 +---- .github/workflows/release.yml | 24 ++------ .gitignore | 3 + AGENTS.md | 12 ++-- Makefile | 106 ++++++++++++++++++++++++++++++++++ README.md | 3 + docs/contributor-guide.md | 9 +-- 7 files changed, 130 insertions(+), 40 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d4927a..ef77a03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,14 +26,5 @@ jobs: - name: Cache Rust artifacts uses: Swatinem/rust-cache@v2 - - name: cargo fmt --all -- --check - run: cargo fmt --all -- --check - - - name: cargo check --locked - run: cargo check --locked - - - name: cargo test --locked - run: cargo test --locked - - - name: cargo build --release --locked - run: cargo build --release --locked + - name: Validate (make ci) + run: make ci diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index adc0d6d..305f4f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,13 +83,8 @@ jobs: - name: Cache Rust artifacts uses: Swatinem/rust-cache@v2 - - name: Validate (fmt/check/test/build) - run: | - set -euo pipefail - cargo fmt --all -- --check - cargo check --locked - cargo test --locked - cargo build --release --locked + - name: Validate (make validate) + run: make validate - name: Resolve next semver id: version @@ -253,19 +248,8 @@ jobs: - name: Cache Rust artifacts uses: Swatinem/rust-cache@v2 - - name: Build release binary - run: cargo build --release --locked --target ${{ matrix.target }} - - - name: Package artifact - shell: bash - run: | - set -euo pipefail - TARGET='${{ matrix.target }}' - PKG="krust-${TARGET}" - mkdir -p "dist/${PKG}" - cp "target/${TARGET}/release/krust" "dist/${PKG}/krust" - cp README.md LICENSE "dist/${PKG}/" - tar -C dist -czf "dist/${PKG}.tar.gz" "${PKG}" + - name: Build + package artifact (make package) + run: make package TARGET=${{ matrix.target }} - name: Upload build artifact uses: actions/upload-artifact@v4 diff --git a/.gitignore b/.gitignore index 538a476..d47688e 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ target # Scale-lab generated kubeconfig (embeds kwok cluster certs — never commit) scripts/scale/kubeconfig-scale.yaml + +# Release packaging output (`make package`) +/dist diff --git a/AGENTS.md b/AGENTS.md index 49dd782..d2869f3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,11 +9,13 @@ Agent behavior must prioritize snappiness and controlled API pressure over feature breadth. ## Mandatory Change Pipeline -After every code change, run validation in this order: -1. `cargo fmt --all` -2. `cargo check` -3. `cargo test` -4. `cargo build --release` +After every code change, run `make validate` — it runs, in order: +1. `cargo fmt --all -- --check` +2. `cargo check --locked` +3. `cargo test --locked` +4. `cargo build --release --locked` + +This is the same target CI runs (`make ci`). Use `make fmt` to auto-format. Rules: - If tests fail, do not proceed to release build until fixed. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a7652f8 --- /dev/null +++ b/Makefile @@ -0,0 +1,106 @@ +# krust Makefile — one entry point for local dev, CI, and release packaging. +# Targets mirror the commands in .github/workflows/{ci,release}.yml so `make` runs the +# exact same pipeline on your machine and on CI. +# +# make # list targets +# make validate # the full pre-PR / CI gate (fmt-check + check + test + release build) +# make package # build + tar a release artifact for the host (or TARGET=) +# make lab-up lab-load lab-contexts # stand up the kwok scale lab +# make bench | soak | discover | metrics # verification harnesses against the lab + +# Resolve cargo: PATH first, then a Homebrew keg-only rustup install (macOS), else plain `cargo`. +CARGO ?= $(shell command -v cargo 2>/dev/null || command -v /opt/homebrew/opt/rustup/bin/cargo 2>/dev/null || echo cargo) +RUSTC ?= $(shell command -v rustc 2>/dev/null || command -v /opt/homebrew/opt/rustup/bin/rustc 2>/dev/null || echo rustc) +# Put cargo's directory on PATH so external subcommands (cargo-fmt, cargo-clippy) and rustc resolve +# even with a Homebrew keg-only rustup that isn't otherwise on PATH. +export PATH := $(dir $(CARGO)):$(PATH) + +# Host target triple, used by `package` when TARGET is not supplied. +TARGET ?= $(shell $(RUSTC) -vV 2>/dev/null | sed -n 's/^host: //p') + +# Defaults for the lab harness targets. +SCALE_KUBECONFIG ?= scripts/scale/kubeconfig-scale.yaml +KRUST_BIN := target/release/krust + +.DEFAULT_GOAL := help + +.PHONY: help fmt fmt-check check clippy test build build-release validate ci run clean \ + package lab-up lab-load lab-contexts lab-crds lab-churn lab-down \ + bench bench-contexts soak discover metrics + +help: ## List available targets + @awk 'BEGIN{FS=":.*?## "}/^[a-zA-Z0-9_-]+:.*?## /{printf " \033[36m%-16s\033[0m %s\n",$$1,$$2}' $(MAKEFILE_LIST) + +# ---- core dev pipeline (identical commands to CI) ------------------------------------- +fmt: ## Format all code + $(CARGO) fmt --all + +fmt-check: ## Check formatting without writing + $(CARGO) fmt --all -- --check + +check: ## Type-check (locked) + $(CARGO) check --locked + +clippy: ## Lint with clippy (locked, warnings as errors) — not part of the CI gate + $(CARGO) clippy --locked --all-targets -- -D warnings + +test: ## Run the test suite (locked) + $(CARGO) test --locked + +build: ## Debug build + $(CARGO) build --locked + +build-release: ## Optimized release build + $(CARGO) build --release --locked + +validate: ## Full gate run sequentially: fmt-check -> check -> test -> release build + $(MAKE) fmt-check + $(MAKE) check + $(MAKE) test + $(MAKE) build-release + +ci: validate ## Alias invoked by GitHub Actions + +run: ## Run krust locally (pass args via ARGS="--context foo") + $(CARGO) run -- $(ARGS) + +clean: ## Remove build artifacts and generated dist/ + $(CARGO) clean + rm -rf dist + +# ---- release packaging (mirrors .github/workflows/release.yml) ------------------------ +package: ## Build + tar a release artifact for TARGET (default: host triple) + @test -n "$(TARGET)" || { echo "could not determine TARGET (rustc not found); pass TARGET="; exit 1; } + $(CARGO) build --release --locked --target $(TARGET) + @PKG="krust-$(TARGET)"; \ + rm -rf "dist/$$PKG"; mkdir -p "dist/$$PKG"; \ + cp "target/$(TARGET)/release/krust" "dist/$$PKG/krust"; \ + cp README.md LICENSE "dist/$$PKG/"; \ + tar -C dist -czf "dist/$$PKG.tar.gz" "$$PKG"; \ + echo "packaged dist/$$PKG.tar.gz" + +# ---- kwok scale lab (scripts/scale) --------------------------------------------------- +lab-up: ## Create the kwok scale cluster + scripts/scale/up.sh +lab-load: ## Load fake nodes/namespaces/pods (tune with KRUST_* env) + scripts/scale/load.sh +lab-contexts: ## Generate the multi-context kubeconfig + scripts/scale/contexts.sh +lab-crds: ## Install the sample CRD + custom resources + scripts/scale/crds.sh +lab-churn: ## Run the churn generator (Ctrl-C to stop) + scripts/scale/churn.sh +lab-down: ## Tear down the kwok cluster + generated kubeconfig + scripts/scale/down.sh + +# ---- verification harnesses (need the lab + a release build) -------------------------- +bench: build-release ## Bench the hot paths against the lab + $(KRUST_BIN) --kubeconfig $(SCALE_KUBECONFIG) --bench +bench-contexts: build-release ## Multi-context memory test (N=20 by default) + $(KRUST_BIN) --kubeconfig $(SCALE_KUBECONFIG) --bench --bench-contexts $(or $(N),20) +soak: build-release ## Soak under churn (SECS=210 by default) + $(KRUST_BIN) --kubeconfig $(SCALE_KUBECONFIG) --soak-secs $(or $(SECS),210) +discover: build-release ## Dynamic discovery catalog (RES= to also list one) + $(KRUST_BIN) --kubeconfig $(SCALE_KUBECONFIG) --discover $(if $(RES),--discover-resource $(RES),) +metrics: build-release ## Live metrics probe (CTX=, else the lab) + $(KRUST_BIN) $(if $(CTX),--context $(CTX),--kubeconfig $(SCALE_KUBECONFIG)) --readonly --metrics diff --git a/README.md b/README.md index ca291b6..03099cb 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ sudo install krust-x86_64-unknown-linux-gnu/krust /usr/local/bin/krust cargo install --git https://github.com/ErfanY/krust.git --locked krust ``` +For local development, `make` (no args) lists targets; `make validate` runs the full CI gate +(fmt/check/test/release build) and `make package` builds a release tarball. + ## Quick Start ```bash diff --git a/docs/contributor-guide.md b/docs/contributor-guide.md index a7a1d89..bb09d59 100644 --- a/docs/contributor-guide.md +++ b/docs/contributor-guide.md @@ -36,12 +36,13 @@ cargo run -- --context ## Required Validation Before PR ```bash -cargo fmt --all -cargo check --locked -cargo test --locked -cargo build --release --locked +make validate # fmt-check -> check -> test -> release build (identical to CI) ``` +`make validate` is exactly what GitHub Actions runs (`make ci`), so a green local run matches CI. +`make` (no args) lists all targets. Individual steps are also available: `make fmt`, `make check`, +`make test`, `make build-release`, `make clippy`. + ## Code Review Focus Review for: