Skip to content

Add stable exit-code contract and CI/CD documentation#182

Open
mkrueger wants to merge 11 commits into
mainfrom
dev/mkrueger/setup-cosmosdb-shell-action
Open

Add stable exit-code contract and CI/CD documentation#182
mkrueger wants to merge 11 commits into
mainfrom
dev/mkrueger/setup-cosmosdb-shell-action

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Implements the exit-code contract and CI/CD documentation requested in #176, and includes the setup-cosmosdb-shell GitHub 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 returning 1:

Code Meaning
0 Success
1 General failure
2 Authentication/authorization failure (401/403, failed Entra credential)
3 Connection/network error (socket failure, 503, request timeout)
4 Command/script syntax error (unparseable input, unrecognized CLI argument)
  • New ShellExitCode class centralizes the contract with FromException and FromCommandState classifiers.
  • Program.cs maps CLI parse errors, connect failures, and command/script results to these codes.
  • The interactive REPL still exits 0.

Documentation

docs/ci.md is expanded into a full CI/CD guide covering:

  • GitHub Actions workflow example (copy-paste ready) with azure/login OIDC
  • The formal exit-code contract
  • Authentication patterns for CI: workload identity federation (OIDC), managed identity, account key / static token
  • Failure-handling guidance: retry patterns, JSON output parsing, azd post-provision hooks, and binary caching

Linked 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 code 4.

Also included on this branch

  • setup-cosmosdb-shell composite 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 errors
  • Exit-code and process tests pass (29 tests)

Addresses #176. Marketplace publishing under azure/setup-cosmosdb-shell (a separate repo) is documented but out of scope for this repo.

mkrueger added 2 commits July 16, 2026 11:48
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
@github-code-quality

github-code-quality Bot commented Jul 16, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in the dev/mkrueger/setup-c... branch remains at 61%, unchanged from the main branch.

Show a code coverage summary of the most impacted files.
File main 4573ab3 dev/mkrueger/setup-c... 48c9c31 +/-
D:\a\CosmosDBSh...hell\Program.cs 72% 75% +3%
D:\a\CosmosDBSh...hellExitCode.cs 0% 97% +97%

Updated July 20, 2026 07:02 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ShellExitCode and wires Program.cs to 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-shell composite 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.

Comment thread CosmosDBShell/Program.cs
Comment thread docs/ci.md Outdated
Comment thread .github/actions/setup-cosmosdb-shell/README.md
Comment thread .github/actions/setup-cosmosdb-shell/action.yml
Comment thread CosmosDBShell.Tests/Integration/ShellProcessTests.cs
- 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.
Copilot AI review requested due to automatic review settings July 16, 2026 12:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread docs/ci.md Outdated
Comment thread docs/ci.md Outdated
Comment thread CosmosDBShell.Tests/Runtime/ShellExitCodeTests.cs
- 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.
Copilot AI review requested due to automatic review settings July 16, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread docs/ci.md Outdated
Reword the OIDC section so endpoint-only connection is clearly the only requirement and the --connect-* options are optional for deterministic startup.
Copilot AI review requested due to automatic review settings July 16, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread .github/actions/setup-cosmosdb-shell/action.yml Outdated
Comment thread .github/actions/setup-cosmosdb-shell/action.yml
Comment thread .github/actions/setup-cosmosdb-shell/action.yml
Comment thread .github/actions/setup-cosmosdb-shell/action.yml
Comment thread .github/actions/setup-cosmosdb-shell/README.md Outdated
Comment thread CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellExitCode.cs
- 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.
Copilot AI review requested due to automatic review settings July 16, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread docs/ci.md Outdated
Comment thread .github/actions/setup-cosmosdb-shell/README.md
- 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.
Copilot AI review requested due to automatic review settings July 16, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread CosmosDBShell.Tests/Runtime/ShellExitCodeTests.cs Outdated
Use CosmosShell.Tests.Runtime to match the other tests under CosmosDBShell.Tests/Runtime.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread CosmosDBShell/Program.cs
Comment thread docs/ci.md Outdated
Copilot AI review requested due to automatic review settings July 16, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread .github/actions/setup-cosmosdb-shell/README.md
- 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.
Copilot AI review requested due to automatic review settings July 16, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread docs/ci.md Outdated
Reference the COSMOSDB_SHELL_FORMAT env var and the per-command -f/--format option instead of the unrelated filter command.
Copilot AI review requested due to automatic review settings July 16, 2026 14:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 20, 2026 06:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@mkrueger

Copy link
Copy Markdown
Collaborator Author

#173 already contains it.

@mkrueger mkrueger closed this Jul 20, 2026
@mkrueger mkrueger reopened this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants