-
Notifications
You must be signed in to change notification settings - Fork 664
Enhance branch label configuration with environment variable support #4746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Added the ability to use environment variable placeholders in branch labels, allowing for dynamic label generation in CI/CD scenarios. Introduced fallback values for environment variables and updated related tests to ensure correct processing of these new features. Updated the GetBranchSpecificLabel method to handle environment variables even when regex does not match, maintaining backward compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for environment variable placeholders in branch labels, enabling dynamic label generation in CI/CD scenarios. The implementation allows users to use {env:VARIABLE_NAME} syntax with optional fallback values ({env:VARIABLE_NAME ?? "fallback"}) in label configurations.
Key changes:
- Extended
GetBranchSpecificLabelto accept an optionalIEnvironmentparameter and process environment variable placeholders - Updated
NextVersionCalculatorto injectIEnvironmentand pass it toGetBranchSpecificLabel - Added comprehensive test coverage for environment variable processing in labels
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/GitVersion.Core/Extensions/ConfigurationExtensions.cs | Added optional IEnvironment parameter to GetBranchSpecificLabel methods and logic to process environment variable placeholders after regex processing |
| src/GitVersion.Core/VersionCalculation/VersionCalculators/NextVersionCalculator.cs | Added IEnvironment dependency injection and passes it to GetBranchSpecificLabel call |
| src/GitVersion.Configuration.Tests/Configuration/ConfigurationExtensionsTests.cs | Added five new test cases covering environment variable processing with and without regex, with fallback values, and edge cases |
| docs/input/docs/reference/configuration.md | Added documentation and examples for environment variable placeholder syntax in labels |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Consolidated the handling of environment variables in branch label generation by introducing a dedicated method, ProcessEnvironmentVariables. This change simplifies the code and maintains backward compatibility while ensuring that environment variables are processed consistently, even when regex does not match.
…rmatWith Added a static object, EmptyFormatSource, to serve as a non-null source parameter when processing environment variables in the FormatWith method. This change simplifies the handling of environment variables by ensuring that no unnecessary properties are required when only using env: placeholders.
…es not match we confirm a different label is used
…l-request' 7 times.
|
|
Getting a strange error on the Windows .net9.0 tests. The tests pass then an exception is thrown during calculating code coverage. From the logs: I'm not sure how to resolve this issue. |
@W0GER Thank you very much for your contribution. It could be a sporadic error. A retry has solved it. |
|
I have some points you need to address for this feature:
Hope that makes sense to you. Please let me know if you have any questions. |



Added the ability to use environment variable placeholders in branch labels, allowing for dynamic label generation in CI/CD scenarios. Introduced fallback values for environment variables and updated related tests to ensure correct processing of these new features. Updated the GetBranchSpecificLabel method to handle environment variables even when regex does not match, maintaining backward compatibility.
Description
Implementation Steps
Backward Compatibility
Related Issue
Resolves #4745
Motivation and Context
Allow labels to include environment variables so that labels can include things like the github_headref for pull requests.
This solves the issue of not being able to add the branch name on versions generated in workflows running on pull requests.
How Has This Been Tested?
Screenshots (if appropriate):
Checklist: