diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ea2373..a0d6715 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,21 +1,100 @@ -name: ci -on: [push, pull_request] +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + CORE_REPO: https://github.com/cflmy/marqdo-cli + CORE_SHA: 4bbefc92449ee480c8a2c89b0308feb4cda8d0e7 + jobs: test: + name: fmt + clippy + workspace tests runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.89" components: rustfmt, clippy + - uses: Swatinem/rust-cache@v2 - run: cargo fmt --all -- --check - - run: cargo clippy --all-targets --locked -- -D warnings + - run: cargo clippy --workspace --all-targets --locked -- -D warnings - run: cargo test --workspace --locked - - run: cargo build --release --locked - # A real core CLI is required for the integration lane; the pinned - # release archive and MARQDO_TEST_BIN are configured by the release - # environment. Without it, the optional integration tests report a skip. - - name: core CLI integration lane - if: env.MARQDO_TEST_BIN != '' - run: cargo test --test core_cli --test compile + + minimum-rust: + name: MSRV check (1.89) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.89 + - uses: Swatinem/rust-cache@v2 + - run: cargo check --locked --workspace --all-targets + + core-analysis: + name: real Analysis integration (pinned core CLI) + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Build pinned core CLI + run: | + set -eu + git clone --quiet "$CORE_REPO" /tmp/marqdo-cli + cd /tmp/marqdo-cli + git checkout --quiet "$CORE_SHA" + cargo build --release --locked -p marqdo-cli + - name: Run integration lane against the real binary + env: + MARQDO_TEST_BIN: /tmp/marqdo-cli/target/release/marqdo + run: | + /tmp/marqdo-cli/target/release/marqdo --version + cargo test --workspace --locked + - name: CLI smoke + run: cargo build --locked && target/debug/marqdo-knowledge --help >/dev/null + + release: + name: beta release archive + if: startsWith(github.ref, 'refs/tags/') + needs: [test, minimum-rust, core-analysis] + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Build pinned core CLI + run: | + set -eu + git clone --quiet "$CORE_REPO" /tmp/marqdo-cli + cd /tmp/marqdo-cli + git checkout --quiet "$CORE_SHA" + cargo build --release --locked -p marqdo-cli + - name: Package and cold-install smoke + env: + MARQDO_BIN: /tmp/marqdo-cli/target/release/marqdo + SOURCE_SHA: ${{ github.sha }} + run: | + scripts/package-release.sh + scripts/verify-release.sh + - name: Upload release archive + uses: actions/upload-artifact@v4 + with: + name: marqdo-knowledge-beta + path: | + dist/*.tar.gz + dist/*.sha256 + dist/RELEASE_INFO.json + - name: Publish GitHub prerelease + uses: softprops/action-gh-release@v2 + with: + prerelease: true + files: | + dist/*.tar.gz + dist/*.sha256 + dist/RELEASE_INFO.json + body_path: docs/releases/0.1.0-beta.1.md diff --git a/.woodpecker/main.yml b/.woodpecker/main.yml new file mode 100644 index 0000000..4f8e174 --- /dev/null +++ b/.woodpecker/main.yml @@ -0,0 +1,63 @@ +# Woodpecker CI pipeline for marqdo-knowledge. +# +# Mirrors the local lanes in scripts/ci.sh and the GitHub workflow. The core CLI +# is built from the pinned marqdo-cli commit because the Analysis contract is an +# external boundary; integration tests always run against that real binary. +when: + event: [push, pull_request, tag] + +steps: + test: + image: rust:1.100-bookworm + commands: + - apt-get update + - apt-get install -y --no-install-recommends ca-certificates + - rustup component add clippy rustfmt + - cargo fmt --all -- --check + - cargo clippy --workspace --all-targets --locked -- -D warnings + - cargo test --workspace --locked + + minimum-rust: + image: rust:1.89-bookworm + commands: + - apt-get update + - apt-get install -y --no-install-recommends ca-certificates build-essential + - cargo check --locked --workspace --all-targets + + core-analysis: + image: rust:1.100-bookworm + commands: + - apt-get update + - apt-get install -y --no-install-recommends ca-certificates git build-essential + - | + set -eu + core_sha=4bbefc92449ee480c8a2c89b0308feb4cda8d0e7 + work=$(mktemp -d) + git clone --quiet https://github.com/cflmy/marqdo-cli "$work/core" + ( cd "$work/core" && git checkout --quiet "$core_sha" \ + && cargo build --release --locked -p marqdo-cli ) + MARQDO_TEST_BIN="$work/core/target/release/marqdo" \ + cargo test --workspace --locked + - cargo build --locked + - target/debug/marqdo-knowledge --help >/dev/null + + release: + depends_on: [test, minimum-rust, core-analysis] + when: + event: [tag] + image: rust:1.100-bookworm + commands: + - apt-get update + - apt-get install -y --no-install-recommends ca-certificates git build-essential python3 + - | + set -eu + core_sha=4bbefc92449ee480c8a2c89b0308feb4cda8d0e7 + work=$(mktemp -d) + git clone --quiet https://github.com/cflmy/marqdo-cli "$work/core" + ( cd "$work/core" && git checkout --quiet "$core_sha" \ + && cargo build --release --locked -p marqdo-cli ) + export MARQDO_BIN="$work/core/target/release/marqdo" + SOURCE_SHA="$CI_COMMIT_SHA" scripts/package-release.sh + scripts/verify-release.sh + - cat dist/RELEASE_INFO.json + - cat dist/*.tar.gz.sha256 diff --git a/docs/ci.md b/docs/ci.md new file mode 100644 index 0000000..dd9b490 --- /dev/null +++ b/docs/ci.md @@ -0,0 +1,71 @@ +# CI/CD for marqdo-knowledge + +The pipeline mirrors the upstream `marqdo-cli` approach: one fast Rust contract +lane, one minimum-Rust lane, one lane that builds the pinned core CLI and runs +the real-Analysis integration tests, and a tag-only release lane that builds a +deterministic archive, cold-installs it through a real `marqdo` binary and +publishes the checksum. + +Configurations: + +- `.woodpecker/main.yml` — self-hosted Woodpecker (push, pull_request, tag). +- `.github/workflows/ci.yml` — GitHub Actions mirror (push, pull_request, tag). +- `scripts/ci.sh` — the same lanes locally (`test`, `minimum`, `core`, + `release`, `all`). +- `scripts/package-release.sh` — locked release build, archive, + `SOURCE_SHA`/`RELEASE_INFO.json`, SHA-256 checksum. +- `scripts/verify-release.sh` — cold install in an isolated + `MARQDO_TOOL_HOME`, dispatch, compile/query/check smoke, remove. + +## Pinned core boundary + +The core CLI is an external contract. CI does not use an already-installed +`marqdo`: it builds `cflmy/marqdo-cli` at +`4bbefc92449ee480c8a2c89b0308feb4cda8d0e7` (`3.0.0-rc.4`, Analysis revision 3) +and exports `MARQDO_TEST_BIN` for `tests/core_cli.rs` and +`tests/compile.rs`. Changing the pin requires re-running the tamper fixtures and +recording a new Analysis fixture artifact. + +## Gates executed by CI + +| Gate | Command | +|---|---| +| formatting | `cargo fmt --all -- --check` | +| lints | `cargo clippy --workspace --all-targets --locked -- -D warnings` | +| unit + integration tests | `cargo test --workspace --locked` | +| real core CLI boundary | `MARQDO_TEST_BIN= cargo test --workspace --locked` | +| minimum Rust | `cargo +1.89 check --locked --workspace --all-targets` | +| release build | `cargo build --release --locked` | +| package + cold install | `scripts/package-release.sh && scripts/verify-release.sh` | + +## Not gated by CI (explicit non-claims) + +- Real-model semantic quality benchmark (§8.3/§16) — needs a pinned model and + weights, not available to this repository's CI. +- Retrieval/performance benchmarks (§16) — need a frozen multi-domain dataset + and reference hardware. +- Windows/macOS native builds — the beta platform claim is Linux x86_64 only. +- Upstream batch `--documents` Analysis interface (U01) — the pinned core + exposes per-entry `check --emit`; this beta invokes it per entry. +- Incremental write-volume benchmark. + +These are recorded as NOT RUN in [`STATUS.md`](STATUS.md). A green pipeline is +evidence for the executed gates only; it is not evidence for those items. + +## Local reproduction + +```sh +# Fast lane +scripts/ci.sh test +# MSRV lane (installs 1.89 through rustup when absent) +scripts/ci.sh minimum +# Real Analysis lane: use an existing built core, or clone/build the pin +MARQDO_BIN=/path/to/marqdo scripts/ci.sh core +# Full release lane (build, package, cold-install smoke) +MARQDO_BIN=/path/to/marqdo scripts/ci.sh release +``` + +The release archive records `SOURCE_SHA`, `RELEASE_INFO.json` (version, +channel, target, API/Analysis/schema revisions, core baseline, rustc/cargo) and +the archive SHA-256. Checksums are integrity evidence, not publisher +authentication. diff --git a/docs/releasing.md b/docs/releasing.md new file mode 100644 index 0000000..f9d780f --- /dev/null +++ b/docs/releasing.md @@ -0,0 +1,80 @@ +# Releasing marqdo-knowledge + +This project is on the **beta** channel (`0.1.0-beta.N`). A beta release claims +only what the pipeline and recorded evidence establish. It does **not** claim +stable quality gates, and the development specification's §16 retrieval and +performance targets remain NOT RUN. + +The procedure mirrors `cflmy/marqdo-cli` `docs/releasing.md`: freeze one release +SHA, run every gate on that exact SHA, build the archive from it, cold-install +that archive through a real core CLI, then tag. Never package a different +checkout. + +## 1. Freeze the release SHA + +1. `git status --porcelain` is clean, `Cargo.lock` is committed, all builds use + `--locked`. +2. `Cargo.toml`, `packaging/tool.json` and `spec/knowledge.md` carry the same + tool version (currently `0.1.0-beta.1`). +3. `CHANGELOG.md`, `docs/releases/.md`, `docs/STATUS.md` and + `docs/ci.md` describe the same facts. No "implemented" claim without a test + or executed evidence; no NOT RUN item presented as passing. +4. The core CLI pin is unchanged or the Analysis fixtures were regenerated and + re-validated against the new pin. + +## 2. Gates on that SHA + +```sh +scripts/ci.sh test # fmt, clippy -D warnings, locked tests +scripts/ci.sh minimum # Rust 1.89 MSRV check +MARQDO_BIN=/path/to/marqdo scripts/ci.sh core # real Analysis boundary +cargo build --release --locked +``` + +The Woodpecker/GitHub pipelines run the same gates. A green local run is not a +substitute for the pipeline run recorded for the release commit, and vice versa. + +## 3. Build and verify the archive + +```sh +MARQDO_BIN=/path/to/marqdo scripts/ci.sh release +``` + +This runs `scripts/package-release.sh` (refuses a dirty tree or mismatched +`SOURCE_SHA`, emits `dist/marqdo-knowledge--.tar.gz`, +`.sha256` and `RELEASE_INFO.json`) and `scripts/verify-release.sh` (extracts the +archive in a clean directory, installs it into an isolated `MARQDO_TOOL_HOME`, +runs `knowledge --help`, compile/query/check smoke, removes the tool). + +Record the archive name and SHA-256 in the tag annotation and release page. Do +not commit build artifacts: `dist/` is ignored. + +## 4. Tag and publish (beta) + +```sh +git tag -a v0.1.0-beta.1 -m "marqdo-knowledge 0.1.0-beta.1; archive sha256 " +git push origin master --tags +``` + +The tag-only release lane uploads the archive, SHA-256 and `RELEASE_INFO.json`, +and publishes a prerelease using `docs/releases/.md` as the body. A tag +push must not introduce new source changes; if the tree changed, restart at step +1 with a new SHA. + +## 5. Beta exit conditions for this repository + +A beta release may be published with these documented gaps: + +- real-model semantic quality and §16 retrieval/performance benchmarks NOT RUN; +- Linux x86_64 only; +- upstream batch Analysis interface unavailable in the pinned core (per-entry + Analysis is used); +- incremental compiles rewrite projection rows in one transaction (write-volume + benchmark unmeasured); +- OKF bundle-root absolute links only have OKF semantics in `check --okf`; +- single-character CJK queries are bounded/truncated. + +They must be published as limitations, never omitted. Stable promotion requires +the full acceptance matrix and quality/performance gates in the development +specification on the exact release SHA, plus independent consumer and cold +install evidence; this document does not authorize a stable release. diff --git a/scripts/ci.sh b/scripts/ci.sh new file mode 100755 index 0000000..081f966 --- /dev/null +++ b/scripts/ci.sh @@ -0,0 +1,76 @@ +#!/bin/sh +# Local CI lanes mirroring .woodpecker/main.yml and .github/workflows/ci.yml. +# +# scripts/ci.sh test fmt + clippy + locked workspace tests +# scripts/ci.sh minimum MSRV check on Rust 1.89 (requires rustup) +# scripts/ci.sh core build the pinned core CLI + real-Analysis tests +# scripts/ci.sh release release build, package archive, cold-install smoke +# scripts/ci.sh all test + core (if available) + release +# +# Environment: +# MARQDO_BIN real core CLI binary (required for core/release lanes) +# CORE_SHA pinned marqdo-cli commit (default: rc.4 baseline) +# CORE_REPO marqdo-cli git URL (default: GitHub) +# ALLOW_DIRTY=1 permit packaging from a dirty tree (never used by CI) +set -eu +ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +CARGO="$ROOT/scripts/cargo.sh" +CORE_SHA=${CORE_SHA:-4bbefc92449ee480c8a2c89b0308feb4cda8d0e7} +CORE_REPO=${CORE_REPO:-https://github.com/cflmy/marqdo-cli} +LANE=${1:-all} + +cd "$ROOT" + +lane_test() { + echo "== lane: test ==" + "$CARGO" fmt --all -- --check + "$CARGO" clippy --all-targets --locked -- -D warnings + "$CARGO" test --workspace --locked +} + +lane_minimum() { + echo "== lane: minimum-rust ==" + if ! rustup toolchain list 2>/dev/null | grep -q '^1\.89'; then + rustup toolchain install 1.89 --profile minimal + fi + cargo +1.89 check --locked --workspace --all-targets +} + +lane_core() { + echo "== lane: core-analysis ==" + if [ -n "${MARQDO_BIN:-}" ] && [ -x "${MARQDO_BIN:-}" ]; then + echo "using MARQDO_BIN=$MARQDO_BIN" + else + CORE_DIR=$(mktemp -d) + trap 'rm -rf "$CORE_DIR"' EXIT + git clone --quiet "$CORE_REPO" "$CORE_DIR/marqdo-cli" + ( cd "$CORE_DIR/marqdo-cli" && git checkout --quiet "$CORE_SHA" \ + && cargo build --release --locked -p marqdo-cli ) + MARQDO_BIN="$CORE_DIR/marqdo-cli/target/release/marqdo" + export MARQDO_BIN + fi + "$MARQDO_BIN" --version + MARQDO_TEST_BIN="$MARQDO_BIN" "$CARGO" test --workspace --locked + "$CARGO" build --locked + "$ROOT/target/debug/marqdo-knowledge" check "$ROOT/examples/mixed" --json >/dev/null 2>&1 || true +} + +lane_release() { + echo "== lane: release ==" + "$CARGO" build --release --locked + "$ROOT/scripts/package-release.sh" + "$ROOT/scripts/verify-release.sh" +} + +case "$LANE" in + test) lane_test ;; + minimum) lane_minimum ;; + core) lane_core ;; + release) lane_release ;; + all) + lane_test + if [ -n "${MARQDO_BIN:-}" ]; then lane_core; else echo "skip: core lane needs MARQDO_BIN"; fi + lane_release + ;; + *) echo "usage: scripts/ci.sh test|minimum|core|release|all" >&2; exit 2 ;; +esac diff --git a/scripts/package-release.sh b/scripts/package-release.sh index 00a1e8d..8046a96 100755 --- a/scripts/package-release.sh +++ b/scripts/package-release.sh @@ -1,21 +1,59 @@ #!/bin/sh -# Build and package a release archive with tool.json and the binary entrypoint. +# Build a reproducible release archive from the exact current commit. +# +# Refuses a dirty tree (unless ALLOW_DIRTY=1), records SOURCE_SHA and +# RELEASE_INFO.json inside the bundle, and emits a sha256 checksum. CI sets +# SOURCE_SHA=CI_COMMIT_SHA; the value must match HEAD or packaging fails. set -eu ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' "$ROOT/Cargo.toml" | head -1) TARGET=${TARGET:-x86_64-unknown-linux-gnu} -DIST="$ROOT/dist/marqdo-knowledge-$VERSION-$TARGET" -rm -rf "$DIST" -mkdir -p "$DIST/bin" +SPEC_SHA=${SOURCE_SHA:-$(git -C "$ROOT" rev-parse HEAD)} +HEAD_SHA=$(git -C "$ROOT" rev-parse HEAD) +DIRTY=$(git -C "$ROOT" status --porcelain) + +if [ "${ALLOW_DIRTY:-0}" != "1" ] && [ -n "$DIRTY" ]; then + echo "package-release: working tree is dirty; commit or pass ALLOW_DIRTY=1" >&2 + exit 2 +fi +if [ "$SPEC_SHA" != "$HEAD_SHA" ]; then + echo "package-release: SOURCE_SHA $SPEC_SHA does not match HEAD $HEAD_SHA" >&2 + exit 2 +fi "$ROOT/scripts/cargo.sh" build --release --locked + +DIST="$ROOT/dist/marqdo-knowledge-$VERSION-$TARGET" +rm -rf "$DIST" +mkdir -p "$DIST/bin" "$DIST/docs" "$DIST/spec" "$DIST/docs/releases" cp "$ROOT/target/release/marqdo-knowledge" "$DIST/bin/marqdo-knowledge" chmod 755 "$DIST/bin/marqdo-knowledge" cp "$ROOT/packaging/tool.json" "$DIST/tool.json" -cp "$ROOT/README.md" "$ROOT/LICENSE-APACHE" "$DIST/" -mkdir -p "$DIST/docs" "$DIST/spec" -cp -r "$ROOT/docs/STATUS.md" "$ROOT/docs/architecture" "$DIST/docs/" -cp -r "$ROOT/spec/knowledge.md" "$DIST/spec/" +cp "$ROOT/README.md" "$ROOT/CHANGELOG.md" "$ROOT/LICENSE-APACHE" "$DIST/" +cp "$ROOT/docs/STATUS.md" "$DIST/docs/" +cp -r "$ROOT/docs/architecture" "$DIST/docs/" +cp -r "$ROOT/docs/releases/." "$DIST/docs/releases/" +cp "$ROOT/spec/knowledge.md" "$DIST/spec/" +printf '%s\n' "$SPEC_SHA" > "$DIST/SOURCE_SHA" +cat > "$DIST/RELEASE_INFO.json" < help -> compile -> query -> check -> remove. set -eu ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) MARQDO=${MARQDO_BIN:?set MARQDO_BIN to the core marqdo binary} VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' "$ROOT/Cargo.toml" | head -1) +TARGET=${TARGET:-x86_64-unknown-linux-gnu} +ARCHIVE="$ROOT/dist/marqdo-knowledge-$VERSION-$TARGET.tar.gz" -cd "$ROOT" -scripts/cargo.sh fmt --all -- --check -scripts/cargo.sh clippy --all-targets -- -D warnings -scripts/cargo.sh test --workspace --locked -scripts/cargo.sh build --release --locked - -# Cold tool install in an isolated tool home. +test -f "$ARCHIVE" +( cd "$ROOT/dist" && sha256sum -c "$(basename "$ARCHIVE").sha256" ) +WORK=$(mktemp -d) TOOL_HOME=$(mktemp -d) +trap 'rm -rf "$WORK" "$TOOL_HOME"' EXIT +tar -xzf "$ARCHIVE" -C "$WORK" +PKG="$WORK/marqdo-knowledge-$VERSION-$TARGET" export MARQDO_TOOL_HOME="$TOOL_HOME" -trap 'rm -rf "$TOOL_HOME"' EXIT -"$MARQDO" tool install "$ROOT/packaging" >/dev/null 2>&1 || { - # packaging/tool.json expects bin/marqdo-knowledge; stage it. - STAGE=$(mktemp -d) - mkdir -p "$STAGE/bin" - cp "$ROOT/packaging/tool.json" "$STAGE/tool.json" - cp "$ROOT/target/release/marqdo-knowledge" "$STAGE/bin/marqdo-knowledge" - "$MARQDO" tool install "$STAGE" -} + +"$MARQDO" tool install "$PKG" +"$MARQDO" tool list | grep -q knowledge "$MARQDO" knowledge --help >/dev/null -"$MARQDO" knowledge compile "$ROOT/examples/mixed" --json >/tmp/knowledge-compile.json -"$MARQDO" knowledge query '量子归一话' --root "$ROOT/examples/mixed" --format json >/tmp/knowledge-query.json -"$MARQDO" knowledge check "$ROOT/examples/mixed" --json >/tmp/knowledge-check.json +"$MARQDO" knowledge compile "$ROOT/examples/mixed" --json > "$WORK/compile.json" +"$MARQDO" knowledge query '归一化' --root "$ROOT/examples/mixed" --format json > "$WORK/query.json" +"$MARQDO" knowledge check "$ROOT/examples/mixed" --json > "$WORK/check.json" +python3 - "$WORK" <<'PY' +import json, sys +work = sys.argv[1] +compile_report = json.load(open(f"{work}/compile.json")) +query_report = json.load(open(f"{work}/query.json")) +check_report = json.load(open(f"{work}/check.json")) +assert compile_report["success"] and compile_report["payload"]["documents"] > 0 +assert query_report["success"] and len(query_report["hits"]) > 0 +assert check_report["success"] and check_report["payload"]["errors"] == 0 +assert check_report["payload"]["database"] == "current" +print( + "smoke: compile documents=%s query_hits=%s database=%s" + % ( + compile_report["payload"]["documents"], + len(query_report["hits"]), + check_report["payload"]["database"], + ) +) +PY "$MARQDO" tool remove knowledge -printf 'verify-release: ok (v%s, core %s)\n' "$VERSION" "$("$MARQDO" --version)" +if "$MARQDO" tool list | grep -q knowledge; then + echo "verify-release: tool was not removed" >&2 + exit 1 +fi +printf 'verify-release: ok (v%s, core %s, sha %s)\n' \ + "$VERSION" "$("$MARQDO" --version)" "$(cat "$PKG/SOURCE_SHA")"