[DISCUSS] feat/template versioning #5508
Draft
+1,076
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Template Version Management for Azure Developer CLI
Overview
This package implements the CalVer (Calendar Versioning) functionality for Azure Developer CLI templates. It automatically creates and manages version files within templated projects, enabling better tracking, debugging, and reproducibility of templates.
Why Template Versioning?
Problem Statement
When users initialize projects from templates, there's no built-in mechanism to track which version of the template was used. This makes it challenging to:
Solution
The Template Version Manager introduces a standardized approach to version tracking by:
AZD_TEMPLATE_VERSION
file in the project directoryYYYY-MM-DD-<short-git-hash>
azure.yaml
for easier programmatic accessHow It Works
Version Format
YYYY-MM-DD
- The date when the template was initialized2025-07-21-713980be
Implementation Details
The version management is implemented as middleware in the CLI command pipeline. When any template-dependent command runs (like
azd init
,azd up
,azd deploy
, etc.), the middleware:AZD_TEMPLATE_VERSION
file existsazure.yaml
with atracking_id
field containing the versionThe middleware is designed to be non-invasive and only creates the version file once. Subsequent commands will use the existing version file if present.
Package Components
Key Files
template_version.go
- Core implementation of version manager functionalitytemplate_version_test.go
- Unit tests for version managementregistration.go
- IoC container registration for version managerKey Types
Manager
- Main service that handles version file operationsVersionInfo
- Struct representing parsed version informationKey Functions
EnsureTemplateVersion
- Main function that checks/creates version filesCreateVersionFile
- Creates the version file with proper format and permissionsReadVersionFile
- Reads and validates existing version filesGetShortCommitHash
- Retrieves the git hash for version creationParseVersionString
- Parses a version string into structured dataTesting It Yourself
Prerequisites
How to Test
Build the CLI with template versioning:
cd /path/to/azure-dev go build -o ./cli/azd/azd ./cli/azd
Initialize a new project from a template:
mkdir -p test-app cd test-app /path/to/azure-dev/cli/azd/azd init --template azure-samples/todo-nodejs-mongo-aca
Run a template-related command to trigger the middleware:
Verify the version file was created:
You should see output like:
2025-07-21-713980be
Check azure.yaml for tracking_id:
It should show:
tracking_id: 2025-07-21-713980be
Debugging
For verbose output, run commands with debug logging:
Code Example: Using the Template Version Manager
Benefits for the Team
Future Enhancements
Feedback and Contributions
Please provide feedback and suggestions for improving the template version management system. The current implementation is designed to be lightweight and unobtrusive while providing valuable metadata for project maintenance.
cc @spboyer @kristenwomack