[Feature] Add composable calculate and output commands to the src CLI
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with src/GitVersion.App/ArgumentParser.cs, Arguments.cs, and GitVersionApp.cs to trace command parsing and dispatch, then read GitVersionOutputTool.cs and VersionVariableSerializer.cs for existing output behavior. Run the relevant parser and output checks as you map the calculation and snapshot paths. Done means both commands work in a two-process pipeline, validate input before side effects, preserve existing root behavior, and meet the listed acceptance criteria.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
The established src/ CLI has a POSIX/System.CommandLine parser and the v7 calculation/output configuration layout, but it still calculates versions and applies outputs through one root invocation. It has no calculate or output subcommands.
In his September 7 review of #5160, @asbjornu wrote:
Accompanying new
gitversion calculateandgitversion outputcommands, I support these configuration changes! 👍🏼
Add those commands to the parser in src/, with a usable JSON pipeline. This is a bounded part of #2275; the experimental new-cli/ tree is outside this issue.
Proposed behavior
gitversion calculate --config GitVersion.yml > version.json
gitversion output --input version.json --show-variable FullSemVer
gitversion output --input version.json --output buildserver
gitversion calculate | gitversion output --update-project-files 'src/**/*.csproj'
gitversion calculate | gitversion output --output dotenv
Use the existing POSIX output flags for the first delivery. A wholesale switch to the older proposal's --type/--property vocabulary is outside this scope.
calculate
- Emit the complete existing variables JSON object and a newline to stdout.
- Reuse existing repository preparation, version calculation, cache handling and cross-process coordination.
- Accept the existing repository, configuration, authentication, logging, diagnostic and calculation-control options where applicable.
- Never emit build-agent commands, update a build number, or modify AssemblyInfo/project/WiX files.
- Reject output/update flags, variable selection, formatting and configuration-display options, including when placed before the command. Use shell redirection to save calculation JSON.
- Preserve supported configuration-version selection independently of parser selection.
output
- Consume a complete variables JSON object from redirected stdin, or
--input <file>. Explicit file input takes precedence and does not read stdin;--input -explicitly selects stdin. - Fail promptly with usage guidance when invoked interactively without input.
- Work outside a Git repository without constructing a Git backend, calculating, preparing/fetching/normalizing, accessing the version cache, or acquiring the calculation mutex.
- Reuse existing JSON/file/buildserver/dotenv output, variable selection, formatting, AssemblyInfo/project/WiX updates, target-directory handling and glob resolution.
- Preserve
GitVersion_prefixes and existing build-agent selection. Dotenv emits text; it does not change the parent shell's environment. - Validate options, the complete input and required configuration before any output side effects. Invalid input must leave files and build-agent outputs untouched.
- Retain existing incompatible-option checks and JSON/file defaults. Reject calculation/repository/authentication/diagnostic options even when specified before the command.
- Resolve explicit relative input/config/output paths against the invocation directory; use the selected target directory for update discovery and globbing.
- Use exit code 0 for success and 1 for errors. Keep diagnostics on stderr and stdout limited to the selected payload or provider protocol.
Configuration-stage contract
Assembly, informational and custom formatting currently happens in VariableProvider before serialization. The incoming JSON should remain an authoritative snapshot: output must not silently recalculate or reinterpret these values.
Proposed first-delivery policy:
- Keep materialized version fields unchanged during output. Changing their configuration requires rerunning
calculate. - Resolve
update-build-numberfor build-server output using existing preset → file → runtime-override precedence. - Support
--configand the relevant runtime override (output.update-build-numberfor v7, corresponding public key for supported v6 configuration mode). Reject unrelated runtime configuration overrides onoutput. - Discover the four supported configuration filenames in the selected target directory, or use an explicit file. Do not search for a Git root. With no discovered file, use preset defaults; reject an explicitly missing file or ambiguous discovery.
- Document that other settings in an accepted configuration file do not reformat the snapshot.
- Avoid configuration loading when the selected output does not need it and no explicit configuration was requested.
Moving all formatting to a separate stage or changing the JSON envelope is a larger follow-up, not a prerequisite for these commands.
Implementation outline
- Add explicit combined-root/calculate/output execution intent to argument mapping; retain combined-root behavior as the default.
- Register both commands in
ArgumentParser, with intentional option scopes and checks for root-supplied options. Keep help and recursive--cli-schemainformational. - Separate calculation plus JSON serialization from output side effects, preserving existing mutex/cache behavior.
- Dispatch snapshot output through a focused executor before resolving the normal lazy Git executor.
- Reuse
GitVersionOutputTool, existing serializers and configuration resolution. Add a small testable input seam if needed. - Harden JSON-input validation without breaking existing serializer/file callers or introducing incompatible reflection/AOT behavior.
- Update CLI arguments, output, migration and CLI-schema documentation.
Relevant starting points:
src/GitVersion.App/ArgumentParser.cssrc/GitVersion.App/Arguments.cssrc/GitVersion.App/GitVersionApp.cssrc/GitVersion.App/GitVersionToolRunner.cssrc/GitVersion.Core/Core/GitVersionCalculateTool.cssrc/GitVersion.Core/VersionCalculation/VariableProvider.cssrc/GitVersion.Output/GitVersionOutputTool.cssrc/GitVersion.Output/Serializer/VersionVariableSerializer.cssrc/GitVersion.Configuration/ConfigurationProvider.cs
The current serializer assumes constructor keys exist. Validate object shape, required fields, scalar types, duplicate/case-colliding keys and trailing documents before exposing arbitrary stdin. Initially support full JSON from this v7 CLI, including numeric/string/null values and optional provenance fields; do not advertise arbitrary partial or older JSON compatibility without defining it.
Acceptance criteria
- Both commands are implemented in
src/and compose through a real two-process pipe. -
calculateproduces the same full variables as existing calculation for representative histories/configurations, with no output side effects. -
outputsucceeds outside Git; throwing dependency factories prove that Git/calculation services are never constructed. - File and stdin input round-trip current JSON, including optional fields. Malformed, partial, duplicate-key, wrong-shape and concatenated input fails before writes.
- JSON/file/dotenv/buildserver, selection/formatting and file updates retain existing behavior and variable prefixes.
- Build-number true/false, configuration precedence, directory-only discovery, missing-file/ambiguity errors and snapshot-format preservation are covered.
- Relative paths, quoted globs, same input/destination file, write failures and interactive missing input are covered.
- Logs, warnings and errors do not contaminate payload stdout, including under build-agent environments and verbose logging.
- Before/after-command option placement, rejected options, positional path conflicts and directories named
calculate/outputhave explicit tested behavior. - Root combined execution, configuration commands, legacy parser and MSBuild callers retain their behavior. These subcommands are not added to the legacy parser.
- Help and complete recursive
--cli-schemaexpose the commands and work outside Git without reading stdin or executing operations. - Relevant parser, routing, process, output and configuration checks pass; supported Git backends retain calculation parity.
- Documentation explains the stage boundaries and examples.
Input/configuration errors must cause zero side effects. Multi-target output can retain today's sequential-write behavior: a later I/O failure may leave earlier successful writes completed; cross-file transactions are outside scope.
Related work and boundaries
- #2275 — broader command-based CLI design; this issue does not close its full scope.
- #5158 / #5132 — versioned calculation/output configuration.
- #5160 / #5134 — configuration documentation and the linked review request.
No changes to new-cli/, version-calculation semantics, plugin architecture, normalize, config init/show, parent-environment mutation or wholesale flag naming are proposed. No new dependency is expected.
Implementation has not started. Deliver both working commands together with their pipeline, tests and documentation; parser aliases alone do not satisfy this issue.
Codex responding on behalf of @arturcic.
- Ngôn ngữ chính
- C#
- Star
- 3.1k
- Fork
- 661
- Merge trung bình
- 7 giờ 4 phút
- Pull request đã merge (30 ngày)
- 77
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của GitTools/GitVersion
-
[ISSUE]: Mainline: version on main falls back to 0.0.x when a branch named in a merge message still existsCó thể đã có người làm @arturcic đã nhận 40 ngày trước. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
GitTools/GitVersion#5405 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
GitTools/GitVersion#5267 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
GitTools/GitVersion#5188 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change pinned
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
GitTools/GitVersion#5137 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change configuration
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
GitTools/GitVersion#5136 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của GitTools/GitVersion
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
area/backend type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
umbraco/Umbraco-CMS#24668 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Pri3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
MicrosoftDocs/windows-dev-docs#6205 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ErikEJ/EFCorePowerTools#3570 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày