Repository navigation
Add stable exit-code contract and CI/CD documentation - #182
Mike Krüger (mkrueger) wants to merge 11 commits into
Conversation
Composite action that resolves a release, downloads the per-runtime CosmosDBShell package, verifies its SHA256 digest, extracts the self-contained executable, caches it in the runner tool cache, and adds cosmosdbshell to PATH. Supports latest or a pinned version across Linux, macOS, and Windows on x64/arm64. Adds a CI/CD guide (docs/ci.md) and links it from the README. Addresses #178
Introduce ShellExitCode with a stable, machine-readable process exit-code contract for non-interactive runs: 0 success, 1 general failure, 2 authentication/authorization failure, 3 connection/network error, 4 command/script syntax error. Program.cs now maps CLI parse errors, connect failures, and command/script results to these codes instead of always returning 1. Document the contract, GitHub Actions usage, authentication patterns (OIDC, managed identity, key/token), and failure-handling guidance in docs/ci.md. Add unit tests for the classifier and end-to-end process tests for the syntax exit code. Update CHANGELOG. Addresses #176
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the Show a code coverage summary of the most impacted files.
Updated |
There was a problem hiding this comment.
Pull request overview
Adds a stable, machine-readable exit-code contract for non-interactive CosmosDBShell runs and introduces CI/CD-focused documentation and tooling (including an in-repo setup action) to make the shell easier to consume from automation.
Changes:
- Introduces
ShellExitCodeand wiresProgram.csto return stable exit codes for CLI parse errors, connection failures, and command/script execution results. - Adds a full CI/CD guide (GitHub Actions examples, auth patterns, retries, JSON parsing) and links it from the README and changelog.
- Adds a
setup-cosmosdb-shellcomposite GitHub Action plus unit/process tests for exit-code behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds a docs link to the new CI/CD guide. |
| docs/ci.md | New CI/CD guide documenting installation, auth patterns, exit codes, and scripting guidance. |
| CosmosDBShell/Program.cs | Maps key non-interactive failure modes to stable exit codes via ShellExitCode. |
| CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellExitCode.cs | Centralized exit-code contract and classifiers (FromException, FromCommandState). |
| CosmosDBShell.Tests/Runtime/ShellExitCodeTests.cs | Unit tests for exception/state-to-exit-code classification. |
| CosmosDBShell.Tests/Integration/ShellProcessTests.cs | Process-level assertions for syntax/argument exit-code behavior. |
| CHANGELOG.md | Documents the new exit-code contract and links to CI/CD guide. |
| .github/actions/setup-cosmosdb-shell/README.md | Documents usage and behavior of the composite setup action. |
| .github/actions/setup-cosmosdb-shell/action.yml | Implements the composite action to download/cache/install the shell from releases. |
- Map all CLI/argument validation failures (invalid --otel endpoint, mutually-exclusive -c/-k, invalid --mcp port) to the syntax exit code; classify MCP runtime failures via ShellExitCode.FromException. - Add a gh preflight check to the setup action with an actionable self-hosted-runner message. - Recommend pinning the action ref (tag/commit) in the action README and docs/ci.md. - Add a process test asserting a malformed --otel endpoint returns exit code 4.
- Pin actions/checkout to v4 in both docs/ci.md workflow examples. - Add a RequestFailedException 503/408/504 connection-error unit test for the exit-code classifier.
Reword the OIDC section so endpoint-only connection is clearly the only requirement and the --connect-* options are optional for deterministic startup.
- action.yml: use github.token fallback via expressions (input default cannot evaluate expressions); drop the warning when a release asset has no digest. - action README: soften SHA256 verification wording to reflect optional digest. - ShellExitCode: classify Cosmos-like OperationCanceledException timeouts as ConnectionError, with unit tests.
- docs/ci.md: clarify that only the -c/-k/stdin-free REPL always exits 0, and that -k preserves the initial command's exit code. - action README: document PowerShell and gh runner prerequisites for self-hosted runners.
Use CosmosShell.Tests.Runtime to match the other tests under CosmosDBShell.Tests/Runtime.
- Program.cs: set GeneralFailure exit code when the initial --connect is cancelled so CI detects aborted startup. - docs/ci.md: clarify REPL exits 0 only when reached and ending normally; startup failures still set non-zero codes. - action README: correct the token input default (empty) and document the github.token fallback.
Reference the COSMOSDB_SHELL_FORMAT env var and the per-command -f/--format option instead of the unrelated filter command.
|
#173 already contains it. |
Fold the composite GitHub Action and docs/ci.md into the deterministic-output PR. Align the exit-code table with the unified 0-6 ShellExitCode contract, drop COSMOSDB_SHELL_FORMAT guidance, and link README/navigation/CHANGELOG.
|
Superseded by #173. The exit-code contract now lives on #173 as a unified 0–6 map via Closing this PR to avoid thrashing |
|
Closing as superseded by #173 (deterministic output + unified 0-6 exit codes + setup action/CI docs). |
…setup action (#173) ## Description Implements the deterministic machine-output contract (Wave 1, P0 / #155) plus the stable process exit-code contract and CI install path requested in #176 / #177. Supersedes #182 by folding its remaining extras (`setup-cosmosdb-shell` action + `docs/ci.md`) onto this branch with the unified exit map. The shell can be safely consumed by CI/CD pipelines, automation tools, and agentic wrappers without output corruption or ambiguous failure states. ## Key Changes ### 1. Global output controls - **`--output` (`-o`)** global option with four formats: `user`, `json`, `table`, `csv` (aliases `js`, `tbl`). Tokens are case-insensitive and canonicalized in one place. - **`--quiet` (`-q`)** global option that suppresses banners, connection logs, and other informational chatter. - **Per-command `--format`** is honored alongside the global option; when a command sets it explicitly it wins, otherwise the session default (from `--output`) is applied once at print time. - **`COSMOSDB_SHELL_FORMAT`** remains supported as a format-only fallback, checked after `--output`/`--format` when neither is supplied. Unlike `--output`, setting it never enters machine mode on its own (no banner/color suppression), so it's safe to export in an interactive shell profile. See `docs/navigation.md`/README for the precedence order. ### 2. Output-rendering architecture (the core refactor) Replaced the old single `IsPrinted` "already printed" flag with a two-delegate rendering model on `CommandState`: - **`RenderUser`** — optional human-facing renderer. Invoked **only** for `user` format on an interactive terminal; never for redirected, piped, or machine-mode output. - **`RenderTabular`** — optional `TabularData` provider that feeds **both** CSV and Table from one source. - A structured `Result` (`ShellJson` / `ShellText`) is always available for `json`/machine consumption independent of the interactive renderer. - **~30 commands migrated** to this model (`list`, `dir`, `info`, `sproc`, `udf`, `trigger`, `throughput`, `bucket`, `theme`, `connect`, `disconnect`, `help`, `watch`, delete/create family, `pwd`, `cls`, `exit`, `edit`, `ftab`, `filter`, and more). ### 3. Centralized policy - **`OutputPolicy`** — shared machine-mode / structured-format decisions for startup and runtime. - **`OutputFormats.TryParse`** — canonical format vocabulary/aliases. - Structured vs human: `json`/`csv` are machine formats; `user`/`table` are human-facing. ### 4. Unified process exit codes (`ShellExitCode`) Classification is centralized in `ShellExitCode.FromException` / `FromCommandState` (used by `ErrorCommandState`, `ParserErrorCommandState`, and `Program`): | Code | Constant | Meaning | | ---- | -------- | ------- | | `0` | `Success` | OK | | `1` | `GeneralFailure` | Catch-all | | `2` | `UsageError` | CLI parse, script syntax, bad/unknown args | | `3` | `AuthFailure` | `401`/`403`, `AuthenticationFailed`, `CredentialUnavailable` | | `4` | `ConnectionError` | HTTP/socket/timeout, `503`/`408`/`504`, Cosmos timeout messages | | `5` | `NotFound` | `404` | | `6` | `Throttled` | `429` / RU budget exceeded | Public contract: existing codes are never repurposed; new categories get new codes. Codes propagate to `%ERRORLEVEL%` / `$LASTEXITCODE`. ### 5. Machine-mode protections - Entered by `--quiet`, structured `--output json|csv`, or bare `-c` (defaults to JSON). - ANSI disabled; structured formats behave as quiet so STDOUT stays clean. - Startup/execution errors emit `{"status":"error","error":"..."}` on **STDERR** in machine mode (honors `2>` redirection). ### 6. CI install path (ported from #182) - **`.github/actions/setup-cosmosdb-shell`** composite action: download/cache self-contained release binary, add `cosmosdbshell` to `PATH` (no .NET SDK on the runner). - **`docs/ci.md`** — install guide, exit-code contract (0–6), CI auth patterns, retry guidance. - README / navigation links to the CI guide and setup action. ## Tests - **`OutputPolicyTests`** / expanded **`OutputFormatTests`** - **`ShellExitCodeTests`** — unit coverage for the 0–6 classifier (auth vs connection, not-found, throttle, usage, wrappers) - **`ShellProcessTests`** — process-level exit codes, ANSI-free STDOUT, JSON-on-STDERR - **`OutputRedirectionTests`** — stdout/stderr redirection in machine mode ## Docs - `docs/navigation.md` — machine mode + exit table - `docs/ci.md` — CI install, auth, failure handling - `README.md` — `--output`/`--quiet`, exit table, setup action - `.github/actions/setup-cosmosdb-shell/README.md` - `CHANGELOG.md` Unreleased entries ## Validation - [x] `-c` / structured `--output json|csv` produce parseable machine output; bare `-c` defaults to JSON - [x] No ANSI in machine modes - [x] Stable exit codes 0–6 (usage=2, auth=3, connection=4, not-found=5, throttle=6) - [x] Parser / bad CLI args → exit 2 - [x] Connection failure in machine mode → exit 4 + JSON on STDERR - [x] Setup action + CI docs land on this PR; #182 superseded ## Supersedes Closes the remaining scope of #182 (setup action + CI docs). Exit-code numbering here **replaces** #182's earlier 0–4 map — do not merge #182 after this. ## Follow-ups already applied on branch - `RenderTabular` cleared at statement boundaries - `connect <endpoint>` success payload normalized to `{ "connected": true, "endpoint": "..." }` - Merged latest `main`; welcome command reconciled with `RenderUser` - Unified `ShellExitCode` helper (auth ≠ connection; keep NotFound/Throttled)
## Summary - stamp the changelog for `1.1.190-preview` on 2026-08-25 - add the missing entries for MCP destructive-command confirmation, preview startup warnings, framework-dependent NuGet packaging, and CodeQL default setup - move the MCP elicitation entry from the historical `1.1.136-preview` section into this release - remove the superseded #182 reference ## Validation - `git diff --check origin/main...HEAD` - audited merged PRs since `1.1.150-preview`
Implements the exit-code contract and CI/CD documentation requested in #177, and includes the
setup-cosmosdb-shellGitHub Action from the earlier work on this branch.Exit-code contract (#176)
Non-interactive runs (
-c,-k, or a script piped on stdin) now return stable, machine-readable process exit codes instead of always returning1:012401/403, failed Entra credential)3503, request timeout)4ShellExitCodeclass centralizes the contract withFromExceptionandFromCommandStateclassifiers.Program.csmaps CLI parse errors, connect failures, and command/script results to these codes.0.Documentation
docs/ci.mdis expanded into a full CI/CD guide covering:azure/loginOIDCLinked from the README docs list.
Tests
ShellExitCodeTests— unit coverage for the classifier (auth, connection, syntax, general, nested exceptions, command-state mapping).ShellProcessTests— end-to-end assertions that an unterminated string and an unrecognized CLI argument both exit with code4.Also included on this branch
setup-cosmosdb-shellcomposite GitHub Action (.github/actions/setup-cosmosdb-shell/) that downloads, verifies, caches, and PATH-adds the shell across Linux/macOS/Windows runners.Validation
dotnet build CosmosDBShell.sln— 0 warnings, 0 errorsAddresses #177. Marketplace publishing under
azure/setup-cosmosdb-shell(a separate repo) is documented but out of scope for this repo.