kv-cli 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. kv_cli-0.9.0/.github/workflows/action-selftest.yml +127 -0
  2. kv_cli-0.9.0/.github/workflows/ci.yml +77 -0
  3. kv_cli-0.9.0/.github/workflows/release.yml +152 -0
  4. kv_cli-0.9.0/.github/workflows/wheels.yml +215 -0
  5. kv_cli-0.9.0/.gitignore +7 -0
  6. kv_cli-0.9.0/.pre-commit-hooks.yaml +19 -0
  7. kv_cli-0.9.0/CHANGELOG.md +1037 -0
  8. kv_cli-0.9.0/Cargo.lock +1403 -0
  9. kv_cli-0.9.0/Cargo.toml +33 -0
  10. kv_cli-0.9.0/LICENSE +21 -0
  11. kv_cli-0.9.0/Makefile +62 -0
  12. kv_cli-0.9.0/PKG-INFO +373 -0
  13. kv_cli-0.9.0/README.md +357 -0
  14. kv_cli-0.9.0/action/annotate.sh +67 -0
  15. kv_cli-0.9.0/action/audit.sh +65 -0
  16. kv_cli-0.9.0/action/install.sh +98 -0
  17. kv_cli-0.9.0/action/summary.sh +70 -0
  18. kv_cli-0.9.0/action/upload.sh +60 -0
  19. kv_cli-0.9.0/action.yml +114 -0
  20. kv_cli-0.9.0/docs/adr/0001-contract-distribution.md +361 -0
  21. kv_cli-0.9.0/docs/adr/0002-tenancy.md +173 -0
  22. kv_cli-0.9.0/docs/adr/0003-active-contributor.md +749 -0
  23. kv_cli-0.9.0/docs/adr/0004-membership-and-roles.md +234 -0
  24. kv_cli-0.9.0/docs/adr/0005-api-tokens.md +310 -0
  25. kv_cli-0.9.0/docs/adr/fixtures/0003-worked-example.json +277 -0
  26. kv_cli-0.9.0/docs/ci.md +122 -0
  27. kv_cli-0.9.0/docs/configuration.md +73 -0
  28. kv_cli-0.9.0/docs/contract-pinning.md +20 -0
  29. kv_cli-0.9.0/docs/development.md +39 -0
  30. kv_cli-0.9.0/docs/frameworks.md +32 -0
  31. kv_cli-0.9.0/docs/how-it-works.md +32 -0
  32. kv_cli-0.9.0/docs/json-payload.md +17 -0
  33. kv_cli-0.9.0/docs/media/kv-cli-demo.svg +17 -0
  34. kv_cli-0.9.0/docs/rules/KV001.md +66 -0
  35. kv_cli-0.9.0/docs/rules/KV002.md +74 -0
  36. kv_cli-0.9.0/docs/rules/KV003.md +59 -0
  37. kv_cli-0.9.0/examples/dump.rs +32 -0
  38. kv_cli-0.9.0/packaging/homebrew/formula.sh +78 -0
  39. kv_cli-0.9.0/pyproject.toml +37 -0
  40. kv_cli-0.9.0/samples/compliant.py +24 -0
  41. kv_cli-0.9.0/samples/configs/.env.example +5 -0
  42. kv_cli-0.9.0/samples/configs/.env.production +5 -0
  43. kv_cli-0.9.0/samples/configs/airflow.cfg +8 -0
  44. kv_cli-0.9.0/samples/configs/secrets.toml +5 -0
  45. kv_cli-0.9.0/samples/configs/settings.json +9 -0
  46. kv_cli-0.9.0/samples/credentials.py +33 -0
  47. kv_cli-0.9.0/samples/deploy.py +92 -0
  48. kv_cli-0.9.0/samples/frameworks/airflow_dag.py +32 -0
  49. kv_cli-0.9.0/samples/frameworks/databricks_dlt.py +16 -0
  50. kv_cli-0.9.0/samples/frameworks/dbt_model.py +7 -0
  51. kv_cli-0.9.0/samples/frameworks/flink_job.py +14 -0
  52. kv_cli-0.9.0/samples/frameworks/polars_etl.py +8 -0
  53. kv_cli-0.9.0/samples/frameworks/profiles.yml +19 -0
  54. kv_cli-0.9.0/samples/frameworks/snowpark_proc.py +22 -0
  55. kv_cli-0.9.0/samples/notebooks/exploration.ipynb +35 -0
  56. kv_cli-0.9.0/schema/contract.v1.json +762 -0
  57. kv_cli-0.9.0/schema/findings.v1.json +481 -0
  58. kv_cli-0.9.0/src/audit.rs +2558 -0
  59. kv_cli-0.9.0/src/config.rs +1605 -0
  60. kv_cli-0.9.0/src/configscan.rs +425 -0
  61. kv_cli-0.9.0/src/fix.rs +679 -0
  62. kv_cli-0.9.0/src/frameworks.rs +326 -0
  63. kv_cli-0.9.0/src/jinja.rs +221 -0
  64. kv_cli-0.9.0/src/main.rs +1808 -0
  65. kv_cli-0.9.0/src/notebook.rs +189 -0
  66. kv_cli-0.9.0/src/payload.rs +557 -0
  67. kv_cli-0.9.0/src/python.rs +1493 -0
  68. kv_cli-0.9.0/src/yamlscan.rs +643 -0
  69. kv_cli-0.9.0/tests/cli.rs +1616 -0
  70. kv_cli-0.9.0/tests/common/mod.rs +179 -0
  71. kv_cli-0.9.0/tests/corpus/.gitattributes +3 -0
  72. kv_cli-0.9.0/tests/corpus/baseline.tsv +10 -0
  73. kv_cli-0.9.0/tests/corpus/cases/config/.env.example +3 -0
  74. kv_cli-0.9.0/tests/corpus/cases/config/airflow.cfg +10 -0
  75. kv_cli-0.9.0/tests/corpus/cases/config/camel.json +10 -0
  76. kv_cli-0.9.0/tests/corpus/cases/config/camel.json.expect +4 -0
  77. kv_cli-0.9.0/tests/corpus/cases/config/ci.yml +23 -0
  78. kv_cli-0.9.0/tests/corpus/cases/config/profiles.yml +10 -0
  79. kv_cli-0.9.0/tests/corpus/cases/config/secrets.toml +7 -0
  80. kv_cli-0.9.0/tests/corpus/cases/config/settings.json +10 -0
  81. kv_cli-0.9.0/tests/corpus/cases/config/settings.json.expect +4 -0
  82. kv_cli-0.9.0/tests/corpus/cases/notebooks/analysis.ipynb +45 -0
  83. kv_cli-0.9.0/tests/corpus/cases/notebooks/analysis.ipynb.expect +4 -0
  84. kv_cli-0.9.0/tests/corpus/cases/python/edge/bom.py +1 -0
  85. kv_cli-0.9.0/tests/corpus/cases/python/edge/crlf.py +6 -0
  86. kv_cli-0.9.0/tests/corpus/cases/python/edge/latin1.py +4 -0
  87. kv_cli-0.9.0/tests/corpus/cases/python/edge/syntax_error.py +5 -0
  88. kv_cli-0.9.0/tests/corpus/cases/python/edge/tabs.py +2 -0
  89. kv_cli-0.9.0/tests/corpus/cases/python/frameworks/airflow.py +14 -0
  90. kv_cli-0.9.0/tests/corpus/cases/python/frameworks/databricks.py +16 -0
  91. kv_cli-0.9.0/tests/corpus/cases/python/frameworks/dbt_model.py +2 -0
  92. kv_cli-0.9.0/tests/corpus/cases/python/frameworks/flink.py +10 -0
  93. kv_cli-0.9.0/tests/corpus/cases/python/frameworks/snowpark.py +16 -0
  94. kv_cli-0.9.0/tests/corpus/cases/python/kv001_scope.py +79 -0
  95. kv_cli-0.9.0/tests/corpus/cases/python/kv002_forms.py +47 -0
  96. kv_cli-0.9.0/tests/corpus/cases/python/kv002_values.py +19 -0
  97. kv_cli-0.9.0/tests/corpus/cases/python/kv003_infra.py +19 -0
  98. kv_cli-0.9.0/tests/corpus/edge.rs +1000 -0
  99. kv_cli-0.9.0/tests/corpus/matrix/names.tsv +34 -0
  100. kv_cli-0.9.0/tests/corpus/matrix/values.tsv +14 -0
  101. kv_cli-0.9.0/tests/corpus.rs +776 -0
  102. kv_cli-0.9.0/tests/fixtures/gate-test-kovallent.yml +26 -0
  103. kv_cli-0.9.0/tests/fixtures/payload-v0.7.2.json +722 -0
@@ -0,0 +1,127 @@
1
+ name: Action self-test
2
+
3
+ # Runs this repository's composite Action (`uses: ./`) the way a customer's
4
+ # workflow would, on each OS the release ships for. samples/ must exit 1
5
+ # (findings) and samples/compliant.py must exit 0. More runs pin the gate's
6
+ # other outcomes: an empty expect-contract exits 2, a wrong one exits 3, and
7
+ # strict: false still runs on every shell (exit 0).
8
+
9
+ on:
10
+ pull_request:
11
+ paths:
12
+ - action.yml
13
+ - action/**
14
+ - samples/**
15
+ - .github/workflows/action-selftest.yml
16
+ push:
17
+ branches: [main]
18
+ paths:
19
+ - action.yml
20
+ - action/**
21
+ - samples/**
22
+ - .github/workflows/action-selftest.yml
23
+ workflow_dispatch:
24
+
25
+ permissions:
26
+ contents: read
27
+ # The compliant run exercises the best-effort upload, which requests an
28
+ # OIDC token. Fork pull requests get none; the upload then warns and skips.
29
+ id-token: write
30
+
31
+ concurrency:
32
+ group: action-selftest-${{ github.ref }}
33
+ cancel-in-progress: true
34
+
35
+ env:
36
+ # The release the Action installs. `uses: ./` has no tag to default to.
37
+ KV_VERSION: v0.7.0
38
+ # Fingerprint of kv-cli's built-in default contract, which samples/ uses
39
+ # because no .kovallent.yaml sits above it. Adding one changes this value.
40
+ SAMPLES_CONTRACT: a6edcff00199c1cf
41
+
42
+ jobs:
43
+ selftest:
44
+ name: Action on ${{ matrix.os }}
45
+ runs-on: ${{ matrix.os }}
46
+ strategy:
47
+ fail-fast: false
48
+ matrix:
49
+ os: [ubuntu-latest, macos-latest, windows-latest]
50
+ steps:
51
+ - uses: actions/checkout@v4
52
+
53
+ - name: samples/ (expect exit 1, findings)
54
+ id: findings
55
+ uses: ./
56
+ continue-on-error: true
57
+ with:
58
+ version: ${{ env.KV_VERSION }}
59
+ paths: samples/
60
+ expect-contract: ${{ env.SAMPLES_CONTRACT }}
61
+
62
+ - name: samples/compliant.py (expect exit 0), with an upload that cannot succeed
63
+ id: compliant
64
+ uses: ./
65
+ continue-on-error: true
66
+ with:
67
+ version: ${{ env.KV_VERSION }}
68
+ paths: samples/compliant.py
69
+ expect-contract: ${{ env.SAMPLES_CONTRACT }}
70
+ # .invalid never resolves (RFC 2606), so the token never leaves the
71
+ # runner. The upload must warn and leave the result at 0.
72
+ upload-url: https://upload.kovallent.invalid/v1/runs
73
+
74
+ - name: Empty expect-contract (expect exit 2, tool error)
75
+ id: unset
76
+ uses: ./
77
+ continue-on-error: true
78
+ with:
79
+ version: ${{ env.KV_VERSION }}
80
+ paths: samples/compliant.py
81
+ expect-contract: ''
82
+
83
+ - name: Wrong expect-contract (expect exit 3, contract drift)
84
+ id: drift
85
+ uses: ./
86
+ continue-on-error: true
87
+ with:
88
+ version: ${{ env.KV_VERSION }}
89
+ paths: samples/compliant.py
90
+ expect-contract: '0000000000000000'
91
+
92
+ # strict: false leaves the --strict argument array empty, which is the
93
+ # case bash 3.2 (macOS /bin/bash) mishandles under `set -u` if unguarded.
94
+ - name: strict false (expect exit 0)
95
+ id: lenient
96
+ uses: ./
97
+ continue-on-error: true
98
+ with:
99
+ version: ${{ env.KV_VERSION }}
100
+ paths: samples/compliant.py
101
+ expect-contract: ${{ env.SAMPLES_CONTRACT }}
102
+ strict: 'false'
103
+
104
+ - name: Check each run's outcome and exit code
105
+ shell: bash
106
+ env:
107
+ FINDINGS: ${{ steps.findings.outcome }}/${{ steps.findings.outputs.exit-code }}
108
+ COMPLIANT: ${{ steps.compliant.outcome }}/${{ steps.compliant.outputs.exit-code }}
109
+ UNSET: ${{ steps.unset.outcome }}/${{ steps.unset.outputs.exit-code }}
110
+ DRIFT: ${{ steps.drift.outcome }}/${{ steps.drift.outputs.exit-code }}
111
+ LENIENT: ${{ steps.lenient.outcome }}/${{ steps.lenient.outputs.exit-code }}
112
+ run: |
113
+ fail=0
114
+ check() {
115
+ if [ "$2" = "$3" ]; then
116
+ echo "ok $1: $2"
117
+ else
118
+ echo "::error title=Action self-test::$1: expected $3 (outcome/exit-code), got $2"
119
+ fail=1
120
+ fi
121
+ }
122
+ check "samples/" "$FINDINGS" "failure/1"
123
+ check "samples/compliant.py" "$COMPLIANT" "success/0"
124
+ check "empty expect-contract" "$UNSET" "failure/2"
125
+ check "wrong expect-contract" "$DRIFT" "failure/3"
126
+ check "strict false" "$LENIENT" "success/0"
127
+ exit "$fail"
@@ -0,0 +1,77 @@
1
+ name: CI
2
+
3
+ # Every pull request and every push to main runs the same gate as
4
+ # `make check`: formatting, clippy with warnings as errors, and the full test
5
+ # suite - unit, end-to-end against the compiled binary, and the labelled
6
+ # corpus. Tests run on each platform the release workflow ships for.
7
+
8
+ on:
9
+ pull_request:
10
+ push:
11
+ branches: [main]
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ # A newer push to the same branch or pull request supersedes the old run.
17
+ concurrency:
18
+ group: ci-${{ github.ref }}
19
+ cancel-in-progress: true
20
+
21
+ env:
22
+ CARGO_TERM_COLOR: always
23
+
24
+ jobs:
25
+ lint:
26
+ name: fmt + clippy
27
+ runs-on: ubuntu-latest
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+
31
+ - uses: dtolnay/rust-toolchain@stable
32
+ with:
33
+ components: rustfmt, clippy
34
+
35
+ - uses: Swatinem/rust-cache@v2
36
+
37
+ - name: Formatting
38
+ run: cargo fmt --check
39
+
40
+ - name: Clippy
41
+ run: cargo clippy --all-targets -- -D warnings
42
+
43
+ # The release workflow writes the Homebrew formula with this script;
44
+ # a broken one would only show up at release time otherwise.
45
+ - name: Homebrew formula
46
+ run: |
47
+ for t in aarch64-apple-darwin x86_64-apple-darwin aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu; do
48
+ printf '%064d kv-cli-%s.tar.gz\n' 0 "$t"
49
+ done > SHA256SUMS
50
+ packaging/homebrew/formula.sh 0.0.0 SHA256SUMS > kv-cli.rb
51
+ ruby -c kv-cli.rb
52
+
53
+ test:
54
+ name: test (${{ matrix.os }})
55
+ runs-on: ${{ matrix.os }}
56
+ strategy:
57
+ # Report every platform, rather than cancelling the rest on the first
58
+ # failure: a Windows-only failure is exactly what this job is for.
59
+ fail-fast: false
60
+ matrix:
61
+ os: [ubuntu-latest, macos-latest, windows-latest]
62
+ steps:
63
+ - uses: actions/checkout@v4
64
+
65
+ - uses: dtolnay/rust-toolchain@stable
66
+
67
+ # tree-sitter's grammar is C; caching saves recompiling it every run.
68
+ - uses: Swatinem/rust-cache@v2
69
+
70
+ - name: Tests
71
+ run: cargo test --all-targets
72
+
73
+ # The tests already gate on the corpus; this prints its precision and
74
+ # recall table in the log for anyone reviewing a detection change.
75
+ - name: Corpus report
76
+ if: matrix.os == 'ubuntu-latest'
77
+ run: cargo test --test corpus -- --nocapture
@@ -0,0 +1,152 @@
1
+ name: Release kv-cli Binaries
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ build:
13
+ name: Build ${{ matrix.target }}
14
+ runs-on: ${{ matrix.os }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ include:
19
+ - target: x86_64-unknown-linux-gnu
20
+ os: ubuntu-latest
21
+ # Graviton / ARM CI runners, and a prerequisite for ARM Linux
22
+ # wheels or Homebrew on ARM Linux later.
23
+ - target: aarch64-unknown-linux-gnu
24
+ os: ubuntu-latest
25
+ cross: true
26
+ - target: aarch64-apple-darwin
27
+ os: macos-latest
28
+ # macos-13 was GitHub's last Intel image and is retired. All
29
+ # current macOS runners are arm64, so Intel is cross-compiled —
30
+ # both Apple targets ship in the same Xcode toolchain.
31
+ - target: x86_64-apple-darwin
32
+ os: macos-latest
33
+ - target: x86_64-pc-windows-msvc
34
+ os: windows-latest
35
+
36
+ steps:
37
+ - name: Checkout Code
38
+ uses: actions/checkout@v4
39
+
40
+ - name: Verify tag matches Cargo.toml
41
+ shell: bash
42
+ run: |
43
+ tag="${GITHUB_REF_NAME#v}"
44
+ crate=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
45
+ if [ "$tag" != "$crate" ]; then
46
+ echo "::error::tag v$tag does not match Cargo.toml version $crate"
47
+ exit 1
48
+ fi
49
+
50
+ - name: Install Rust Toolchain
51
+ uses: dtolnay/rust-toolchain@stable
52
+ with:
53
+ targets: ${{ matrix.target }}
54
+
55
+ # tree-sitter's grammar is C, so a cross build needs a cross cc,
56
+ # not just the Rust target.
57
+ - name: Install cross linker (Linux aarch64)
58
+ if: matrix.cross
59
+ run: |
60
+ sudo apt-get update
61
+ sudo apt-get install -y gcc-aarch64-linux-gnu
62
+ {
63
+ echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc"
64
+ echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc"
65
+ } >> "$GITHUB_ENV"
66
+
67
+ - name: Build Binary
68
+ run: cargo build --release --target ${{ matrix.target }}
69
+
70
+ - name: Package Binary
71
+ shell: bash
72
+ run: |
73
+ mkdir -p dist
74
+ bin=kv-cli
75
+ if [ "${{ runner.os }}" = "Windows" ]; then bin=kv-cli.exe; fi
76
+ tar -czf "dist/kv-cli-${{ matrix.target }}.tar.gz" \
77
+ -C "target/${{ matrix.target }}/release" "$bin"
78
+
79
+ - name: Upload Artifact
80
+ uses: actions/upload-artifact@v4
81
+ with:
82
+ name: kv-cli-${{ matrix.target }}
83
+ path: dist/*.tar.gz
84
+
85
+ # One release job instead of five racing to create the same release —
86
+ # and the only place SHA256SUMS can be computed over the full set.
87
+ release:
88
+ needs: build
89
+ runs-on: ubuntu-latest
90
+ steps:
91
+ - name: Download All Artifacts
92
+ uses: actions/download-artifact@v4
93
+ with:
94
+ pattern: kv-cli-*
95
+ merge-multiple: true
96
+ path: dist
97
+
98
+ - name: Generate Checksums
99
+ run: cd dist && sha256sum *.tar.gz | tee SHA256SUMS
100
+
101
+ - name: Publish Release
102
+ uses: softprops/action-gh-release@v2
103
+ with:
104
+ files: |
105
+ dist/*.tar.gz
106
+ dist/SHA256SUMS
107
+
108
+ # `brew install kovallent/tap/kv-cli` installs what this job writes. It
109
+ # runs after the release is public, so the formula never points at an
110
+ # archive that does not exist yet. A prerelease tag (v0.7.0-rc.1) is not
111
+ # what `brew upgrade` should install, so it is skipped.
112
+ homebrew:
113
+ needs: release
114
+ if: ${{ !contains(github.ref_name, '-') }}
115
+ runs-on: ubuntu-latest
116
+ steps:
117
+ - name: Require the tap token
118
+ env:
119
+ TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
120
+ run: |
121
+ if [ -z "$TOKEN" ]; then
122
+ echo "::error::HOMEBREW_TAP_TOKEN is not set, so brew users stay on the previous release. See docs/development.md."
123
+ exit 1
124
+ fi
125
+
126
+ - name: Checkout Code
127
+ uses: actions/checkout@v4
128
+
129
+ - name: Checkout the tap
130
+ uses: actions/checkout@v4
131
+ with:
132
+ repository: kovallent/homebrew-tap
133
+ token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
134
+ path: tap
135
+
136
+ - name: Update the formula
137
+ run: |
138
+ version="${GITHUB_REF_NAME#v}"
139
+ curl -sSfL -o SHA256SUMS \
140
+ "https://github.com/${GITHUB_REPOSITORY}/releases/download/${GITHUB_REF_NAME}/SHA256SUMS"
141
+ mkdir -p tap/Formula
142
+ packaging/homebrew/formula.sh "$version" SHA256SUMS > tap/Formula/kv-cli.rb
143
+ cd tap
144
+ git config user.name "github-actions[bot]"
145
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
146
+ git add Formula/kv-cli.rb
147
+ if git diff --cached --quiet; then
148
+ echo "formula already at $version"
149
+ else
150
+ git commit -m "kv-cli $version"
151
+ git push
152
+ fi
@@ -0,0 +1,215 @@
1
+ name: Wheels
2
+
3
+ # Builds kv-cli as Python wheels, one per platform, and publishes them to PyPI,
4
+ # so `pip install kv-cli` and `uv tool install kv-cli` install the binary with
5
+ # no Rust toolchain. Each wheel holds the compiled binary only (maturin
6
+ # `bindings = "bin"`, tag py3-none-<platform>); nothing is downloaded at
7
+ # install time.
8
+ #
9
+ # Separate from release.yml, so a PyPI outage cannot fail a GitHub release.
10
+
11
+ on:
12
+ push:
13
+ tags:
14
+ - 'v*'
15
+ pull_request:
16
+ paths:
17
+ - pyproject.toml
18
+ - Cargo.toml
19
+ - .github/workflows/wheels.yml
20
+ workflow_dispatch:
21
+ inputs:
22
+ target:
23
+ description: Package index to publish to
24
+ type: choice
25
+ options:
26
+ - testpypi
27
+ - pypi
28
+ default: testpypi
29
+
30
+ permissions:
31
+ contents: read
32
+
33
+ concurrency:
34
+ group: wheels-${{ github.ref }}
35
+ # Never cancel a run that may be publishing.
36
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
37
+
38
+ jobs:
39
+ guard:
40
+ name: tag matches Cargo.toml
41
+ if: startsWith(github.ref, 'refs/tags/')
42
+ runs-on: ubuntu-latest
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+
46
+ - name: Compare the tag with Cargo.toml's version
47
+ run: |
48
+ tag="${GITHUB_REF_NAME#v}"
49
+ crate=$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')
50
+ if [ "$tag" != "$crate" ]; then
51
+ echo "::error::tag $GITHUB_REF_NAME does not match Cargo.toml version $crate"
52
+ exit 1
53
+ fi
54
+ echo "tag $GITHUB_REF_NAME matches Cargo.toml version $crate"
55
+
56
+ wheels:
57
+ name: wheel (${{ matrix.name }})
58
+ runs-on: ${{ matrix.os }}
59
+ strategy:
60
+ # Report every platform rather than cancelling the rest on the first
61
+ # failure.
62
+ fail-fast: false
63
+ matrix:
64
+ include:
65
+ - name: linux x86-64 manylinux
66
+ os: ubuntu-latest
67
+ target: x86_64-unknown-linux-gnu
68
+ manylinux: auto
69
+ smoke: true
70
+ - name: linux arm64 manylinux
71
+ os: ubuntu-latest
72
+ target: aarch64-unknown-linux-gnu
73
+ manylinux: auto
74
+ - name: linux x86-64 musllinux
75
+ os: ubuntu-latest
76
+ target: x86_64-unknown-linux-musl
77
+ manylinux: musllinux_1_2
78
+ - name: linux arm64 musllinux
79
+ os: ubuntu-latest
80
+ target: aarch64-unknown-linux-musl
81
+ manylinux: musllinux_1_2
82
+ - name: macos arm64
83
+ os: macos-latest
84
+ target: aarch64-apple-darwin
85
+ smoke: true
86
+ # macos-13 was GitHub's last Intel image and is retired. All current
87
+ # macOS runners are arm64, so Intel is cross-compiled - both Apple
88
+ # targets ship in the same Xcode toolchain.
89
+ - name: macos x86-64
90
+ os: macos-latest
91
+ target: x86_64-apple-darwin
92
+ - name: windows x86-64
93
+ os: windows-latest
94
+ target: x86_64-pc-windows-msvc
95
+ smoke: true
96
+
97
+ steps:
98
+ - uses: actions/checkout@v4
99
+
100
+ # On Linux this builds inside a manylinux or musllinux container, which
101
+ # carries the C cross-compiler that tree-sitter's grammar needs.
102
+ - name: Build the wheel
103
+ uses: PyO3/maturin-action@v1
104
+ with:
105
+ target: ${{ matrix.target }}
106
+ manylinux: ${{ matrix.manylinux }}
107
+ args: --release --locked --out dist
108
+
109
+ - name: Set up Python
110
+ if: matrix.smoke
111
+ uses: actions/setup-python@v5
112
+ with:
113
+ python-version: '3.12'
114
+
115
+ # Installs from dist/ only, never from an index, so this tests the
116
+ # wheel this job built and nothing else.
117
+ - name: Smoke-test the wheel
118
+ if: matrix.smoke
119
+ shell: bash
120
+ run: |
121
+ python -m venv .smoke
122
+ bin=.smoke/bin
123
+ if [ -d .smoke/Scripts ]; then bin=.smoke/Scripts; fi
124
+ "$bin/python" -m pip install --no-index --only-binary=:all: --find-links dist kv-cli
125
+
126
+ crate=$(python -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')
127
+ version=$("$bin/kv-cli" --version)
128
+ echo "$version"
129
+ if [ "$version" != "kv-cli $crate" ]; then
130
+ echo "::error::installed binary reports '$version', expected 'kv-cli $crate'"
131
+ exit 1
132
+ fi
133
+
134
+ # Must exit 0: samples/compliant.py always audits clean.
135
+ "$bin/kv-cli" audit samples/compliant.py
136
+
137
+ "$bin/kv-cli" schema > schema-out.json
138
+ python -c 'import json, sys; json.load(open(sys.argv[1]))' schema-out.json
139
+ echo "kv-cli schema printed valid JSON"
140
+
141
+ - name: Upload the wheel
142
+ uses: actions/upload-artifact@v4
143
+ with:
144
+ name: dist-${{ matrix.target }}
145
+ path: dist/*.whl
146
+ if-no-files-found: error
147
+
148
+ sdist:
149
+ name: sdist
150
+ runs-on: ubuntu-latest
151
+ steps:
152
+ - uses: actions/checkout@v4
153
+
154
+ - name: Build the sdist
155
+ uses: PyO3/maturin-action@v1
156
+ with:
157
+ command: sdist
158
+ args: --out dist
159
+
160
+ # A platform without a wheel builds from the sdist, so check that it
161
+ # builds - e.g. that the files the binary embeds are in it.
162
+ - name: Build a wheel from the sdist
163
+ run: |
164
+ python3 -m venv "$RUNNER_TEMP/sdist-check"
165
+ "$RUNNER_TEMP/sdist-check/bin/pip" wheel --no-deps dist/*.tar.gz -w "$RUNNER_TEMP/sdist-wheel"
166
+ ls -l "$RUNNER_TEMP/sdist-wheel"
167
+
168
+ - name: Upload the sdist
169
+ uses: actions/upload-artifact@v4
170
+ with:
171
+ name: dist-sdist
172
+ path: dist/*.tar.gz
173
+ if-no-files-found: error
174
+
175
+ # One publish job, so a partial upload of some platforms never happens.
176
+ # Trusted publishing: PyPI issues a short-lived token for this workflow and
177
+ # environment, so no PyPI token is stored anywhere. A tag publishes to PyPI.
178
+ # A manual run publishes to the index chosen by `target` - PyPI only from a
179
+ # tag, so a manual run can never publish an untagged version there.
180
+ publish:
181
+ name: publish
182
+ needs: [guard, wheels, sdist]
183
+ if: >-
184
+ always()
185
+ && needs.wheels.result == 'success'
186
+ && needs.sdist.result == 'success'
187
+ && (needs.guard.result == 'success' || needs.guard.result == 'skipped')
188
+ && (
189
+ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
190
+ || (github.event_name == 'workflow_dispatch'
191
+ && (inputs.target == 'testpypi' || startsWith(github.ref, 'refs/tags/v')))
192
+ )
193
+ runs-on: ubuntu-latest
194
+ environment:
195
+ name: pypi
196
+ url: ${{ (github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi') && 'https://test.pypi.org/p/kv-cli' || 'https://pypi.org/p/kv-cli' }}
197
+ permissions:
198
+ id-token: write
199
+ steps:
200
+ - name: Download the wheels and the sdist
201
+ uses: actions/download-artifact@v4
202
+ with:
203
+ pattern: dist-*
204
+ merge-multiple: true
205
+ path: dist
206
+
207
+ - name: List the files to upload
208
+ run: ls -l dist
209
+
210
+ - name: Publish
211
+ uses: pypa/gh-action-pypi-publish@release/v1
212
+ with:
213
+ repository-url: ${{ (github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi') && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
214
+ # TestPyPI runs can repeat for one version; PyPI uploads cannot.
215
+ skip-existing: ${{ github.event_name == 'workflow_dispatch' && inputs.target == 'testpypi' }}
@@ -0,0 +1,7 @@
1
+ /target
2
+ **/*.rs.bk
3
+ *.pdb
4
+ .env
5
+ .DS_Store
6
+ # kv-cli fix backups hold the original source, credentials included.
7
+ *.kvbak
@@ -0,0 +1,19 @@
1
+ - id: kv-cli
2
+ name: kv-cli contract audit
3
+ description: Audit Python pipelines, notebooks and config files for contract breaches, hardcoded secrets, and pinned infrastructure.
4
+ entry: kv-cli audit
5
+ language: rust
6
+ # Mirrors the default `scan.include`. A `files` pattern rather than
7
+ # `types_or`: pre-commit tags a generic `.cfg` (e.g. airflow.cfg) only as
8
+ # `text`, so no list of types can select it.
9
+ types: [text]
10
+ files: '(\.(py|ipynb|ya?ml|toml|ini|cfg|json|env)|(^|/)\.env(\.[^/]*)?)$'
11
+
12
+ - id: kv-cli-contract
13
+ name: kv-cli contract check
14
+ description: Validate .kovallent.yaml when it changes - every problem with its line, without scanning code.
15
+ entry: kv-cli contract check
16
+ language: rust
17
+ # Only the contract itself; each changed one is passed by name, so a
18
+ # contract in a subfolder is checked too.
19
+ files: '(^|/)\.kovallent\.yaml$'