Skip to content

Commit 1e5f3c9

Browse files
committed
feat(neo4j): project analysis.json into a Neo4j property graph
Port the codeanalyzer-typescript v0.4.0 Neo4j feature to Python under the neo4j feature branch, with the same CLI arg entrypoints. - codeanalyzer/neo4j: catalog (schema source of truth), project (pure IR -> graph rows), cypher snapshot writer, incremental Bolt writer, and the output-agnostic rows intermediate. Lazy neo4j-driver import keeps it off the default json path. - CLI: --emit {json,neo4j,schema}, --app-name, --neo4j-uri/-user/-password/ -database; -i/--input now optional for --emit schema. - --emit neo4j writes a self-contained graph.cypher, or pushes incrementally to a live Neo4j over Bolt; --emit schema emits the version-stamped schema.json contract (checked in as schema.neo4j.json). - Tests: schema-conformance (always runs, anti-drift guard) + opt-in Neo4j Testcontainers bolt integration test (RUN_CONTAINER_TESTS=1). - packaging/install/codeanalyzer-installer.sh: curl|sh installer (uv/pipx/pip). - release.yml: sync schema.neo4j.json + publish schema.json and installer as release assets. README/CHANGELOG updates; schema-uml.drawio. Version 0.2.0.
1 parent 3b3e10e commit 1e5f3c9

21 files changed

Lines changed: 2298 additions & 192 deletions

.github/workflows/release.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,24 @@ jobs:
3232
run: uv sync --all-groups
3333

3434
- name: Install dependencies
35-
run: uv pip install -e .
35+
run: uv pip install -e ".[neo4j]"
36+
37+
# Keep the checked-in Neo4j schema contract in lockstep with the code being
38+
# released: regenerate schema.neo4j.json from source and commit it back to main.
39+
# Releases are cut from main HEAD, so this fast-forwards; best-effort if main moved.
40+
- name: Sync Neo4j schema contract (schema.neo4j.json)
41+
if: startsWith(github.ref, 'refs/tags/')
42+
run: |
43+
uv run codeanalyzer --emit schema > schema.neo4j.json
44+
if git diff --quiet schema.neo4j.json; then
45+
echo "Neo4j schema already current."
46+
else
47+
git config user.name "github-actions[bot]"
48+
git config user.email "github-actions[bot]@users.noreply.github.com"
49+
git add schema.neo4j.json
50+
git commit -m "docs: sync Neo4j schema contract for ${GITHUB_REF#refs/tags/}"
51+
git push origin HEAD:main || echo "::warning::could not push schema sync to main (diverged?)"
52+
fi
3653
3754
- name: Run tests
3855
id: test
@@ -51,6 +68,17 @@ jobs:
5168
- name: Build package
5269
run: uv build
5370

71+
# Platform-independent, version-locked release assets published alongside the
72+
# wheels/sdist: the Neo4j schema contract (so a consumer can validate
73+
# producer/consumer compatibility without installing the package) and the
74+
# cargo-dist-style install script.
75+
- name: Stage release assets (Neo4j schema + installer script)
76+
run: |
77+
mkdir -p release-assets
78+
uv run codeanalyzer --emit schema > release-assets/schema.json
79+
cp packaging/install/codeanalyzer-installer.sh release-assets/codeanalyzer-installer.sh
80+
ls -lh release-assets
81+
5482
- name: Get version from tag
5583
id: tag_name
5684
run: |
@@ -77,7 +105,9 @@ jobs:
77105
- name: Publish release on GitHub
78106
uses: softprops/action-gh-release@v1
79107
with:
80-
files: dist/*
108+
files: |
109+
dist/*
110+
release-assets/*
81111
body: |
82112
## Release Notes (from CHANGELOG.md)
83113

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.0] - 2026-06-20
9+
10+
### Added
11+
- **Neo4j property-graph output** (`--emit neo4j`). The same in-memory analysis (`PyApplication`) is projected to a labeled property graph, mirroring the `codeanalyzer-typescript` backend. Two writers:
12+
- **`graph.cypher` snapshot** (default) — a self-contained Cypher script (constraints + indexes, a scoped wipe of the project's prior subgraph, then batched `UNWIND … MERGE`). Load it with `cypher-shell < graph.cypher`. Needs no extra dependencies.
13+
- **Live Bolt push** (`--neo4j-uri`) — an **incremental** writer: only modules whose `content_hash` changed are rewritten, and on a full run modules whose source file vanished are pruned. Requires the optional `neo4j` driver (`pip install 'codeanalyzer-python[neo4j]'`).
14+
- **`--emit schema`** — emit the machine-readable, version-stamped Neo4j schema contract (`schema.json`: node labels, relationships, properties, constraints, indexes). Needs no project; bundled in every release as a GitHub Release asset and checked in as `schema.neo4j.json`. A `schema_version` (`1.0.0`) is stamped onto every graph's `:Application` node.
15+
- **New CLI options** mirroring the TypeScript analyzer's entrypoints: `--emit {json,neo4j,schema}`, `--app-name`, `--neo4j-uri`, `--neo4j-user`, `--neo4j-password`, `--neo4j-database`. `-i/--input` is now optional (not required for `--emit schema`).
16+
- **`codeanalyzer.neo4j`** package: `catalog` (the single source-of-truth schema catalog), `project` (pure IR → graph rows), `cypher` (snapshot writer), `bolt` (incremental writer), and `rows` (the output-agnostic intermediate).
17+
- **Schema conformance test** (`test/test_neo4j_schema.py`, always runs) — asserts the emitter never produces a label/relationship/property the catalog doesn't declare, and that the checked-in `schema.neo4j.json` is regenerated.
18+
- **Neo4j Testcontainers integration test** (`test/test_neo4j_bolt.py`, opt-in via `RUN_CONTAINER_TESTS=1`) — spins up a real Neo4j and asserts the pushed graph, idempotent re-push, vanished-declaration cleanup, and full-run orphan pruning.
19+
- **Install script** (`packaging/install/codeanalyzer-installer.sh`) — a `curl … | sh` installer that provisions the CLI via uv / pipx / pip, published as a release asset.
20+
- **`schema-uml.drawio`** — a clean UML of the `analysis.json` schema (the `PyApplication` containment tree).
21+
22+
### Changed
23+
- The release workflow now installs the `[neo4j]` extra, syncs `schema.neo4j.json` from source before publishing, and uploads the schema contract (`schema.json`) and installer script as GitHub Release assets.
24+
825
## [0.1.15] - 2026-05-15
926

1027
### Fixed

0 commit comments

Comments
 (0)