Skip to content

Commit 1be1a42

Browse files
ptrthomasclaude
andcommitted
Add CLI self-update (karate update --item cli)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 48f9d5f commit 1be1a42

5 files changed

Lines changed: 312 additions & 13 deletions

File tree

CONTRIBUTING.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,96 @@ git tag -d v0.2.0 && git push origin --delete v0.2.0
162162

163163
Note: Deleting a tag does NOT delete the GitHub Release. Delete the release manually from the GitHub UI if needed.
164164

165+
## Testing CLI Self-Update Locally
166+
167+
The `karate update --item cli` command can be tested without a real release using `KARATE_MANIFEST_URL` to point at a local HTTP server. The [`karate-sh`](https://github.com/karatelabs/karate-sh) repo (expected at `../karate-sh`) contains the production `manifest.json`.
168+
169+
```bash
170+
# 1. Build the binary
171+
cargo build
172+
173+
# 2. Create a test directory and copy the binary
174+
mkdir -p /tmp/karate-update-test/serve /tmp/karate-update-test/bin
175+
cp target/debug/karate /tmp/karate-update-test/bin/karate
176+
177+
# 3. Package it as a release archive and get the SHA256
178+
tar czf /tmp/karate-update-test/serve/karate-cli.tar.gz \
179+
-C /tmp/karate-update-test/bin karate
180+
shasum -a 256 /tmp/karate-update-test/serve/karate-cli.tar.gz
181+
```
182+
183+
4. Create `/tmp/karate-update-test/serve/manifest.json` using the SHA256 from above (replace `YOUR_SHA256` and adjust the platform key for your machine):
184+
185+
```json
186+
{
187+
"schema_version": 1,
188+
"generated_at": "2026-01-01T00:00:00Z",
189+
"artifacts": {
190+
"karate-cli": {
191+
"description": "Karate CLI",
192+
"versions": {
193+
"0.2.0-test": {
194+
"channels": ["stable"],
195+
"released_at": "2026-01-01T00:00:00Z",
196+
"platforms": {
197+
"macos-aarch64": {
198+
"url": "http://localhost:9999/karate-cli.tar.gz",
199+
"sha256": "YOUR_SHA256"
200+
}
201+
}
202+
}
203+
}
204+
},
205+
"karate": {
206+
"description": "Karate Core",
207+
"versions": {
208+
"1.5.2": {
209+
"channels": ["stable"],
210+
"released_at": "2025-11-30T00:00:00Z",
211+
"url": "https://example.com/karate-1.5.2.jar",
212+
"sha256": "abc123"
213+
}
214+
}
215+
}
216+
},
217+
"channel_defaults": {
218+
"stable": { "karate-cli": "0.2.0-test", "karate": "1.5.2" }
219+
}
220+
}
221+
```
222+
223+
```bash
224+
# 5. Start a local HTTP server
225+
cd /tmp/karate-update-test/serve && python3 -m http.server 9999 &
226+
227+
# 6. Test the full self-update flow (runs the copied binary, not cargo run)
228+
KARATE_MANIFEST_URL=http://localhost:9999/manifest.json \
229+
KARATE_HOME=./home/.karate \
230+
/tmp/karate-update-test/bin/karate update --item cli
231+
232+
# 7. Verify the binary still works after replacement
233+
/tmp/karate-update-test/bin/karate version
234+
235+
# 8. Clean up
236+
kill $(lsof -ti:9999) 2>/dev/null
237+
rm -rf /tmp/karate-update-test
238+
```
239+
240+
Note: The dev binary always reports `0.1.0` (from `Cargo.toml`), so it will always see `0.2.0-test` as an update. In production, the version is injected at release build time.
241+
242+
You can also test just the check/display phase via `cargo run` (no binary replacement):
243+
244+
```bash
245+
KARATE_MANIFEST_URL=http://localhost:9999/manifest.json \
246+
KARATE_HOME=./home/.karate cargo run -- update --item cli
247+
```
248+
249+
## Related Repositories
250+
251+
The [`karate-sh`](https://github.com/karatelabs/karate-sh) website repo is expected at `../karate-sh` relative to this project. It contains:
252+
- `public/manifest.json` - The production manifest used by `karate setup`, `karate update`, and install scripts
253+
- Install scripts (`install.sh`, `install.ps1`)
254+
165255
## Important Notes
166256

167257
- **Never delete `~/.karate`** - Contains license files (`uuid.txt`, `karate.lic`)

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub struct UpdateArgs {
9090
#[arg(long, conflicts_with = "item")]
9191
pub all: bool,
9292

93-
/// Update specific item: jar, jre
93+
/// Update specific item: jar, jre, cli
9494
#[arg(long)]
9595
pub item: Option<String>,
9696

0 commit comments

Comments
 (0)