Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
81a86bf
Considering the environment variable 'ModuleVersion' if it exists
raandree Jun 7, 2025
692c653
Added support for GitVersion which is a breaking change
raandree Jun 8, 2025
2b8f59e
Updated launch configs
raandree Jun 8, 2025
99479fa
Adapting tests to work with GitVersion 6
raandree Jun 9, 2025
6299f48
Updated changelog
raandree Jun 9, 2025
a41082d
Change deployment mode from ContinuousDelivery to ManualDeployment
raandree Jun 9, 2025
0123d68
Updated changelog
raandree Jun 9, 2025
4aa295c
Fixed typo
raandree Jun 9, 2025
47d551b
Merge branch 'main' into feature/gitversion6
raandree Jul 22, 2025
465ac5a
Changes according to the code review
raandree Jul 24, 2025
df5d0d2
Added test to check for environment variable
raandree Jul 24, 2025
2803e70
Merge branch 'main' into feature/gitversion6
raandree Jul 24, 2025
b8d2089
Merge branch 'main' into feature/gitversion6
raandree Aug 19, 2025
b5e990e
Fix Script Analyzer QA tests failing in various scripts (#540)
johlju Sep 2, 2025
566ae41
Add mac setup instructions to README (#532)
Mynster9361 Sep 5, 2025
cf68ca5
Fixed issue with changelog check (#541)
Ligtorn Sep 6, 2025
96ac6d8
fixing http.sslbackend schannel command because it failed
gaelcolas Jan 7, 2026
771695c
updating changelog
gaelcolas Jan 7, 2026
ba01456
Updating ChangeLog since v0.119.0 +semver:skip (#548)
gaelcolas Jan 8, 2026
b611786
fixing http.sslbackend schannel command because it failed
gaelcolas Jan 28, 2026
5e2beaa
Fix Gallery Preview Badge
dan-hughes Feb 11, 2026
a4282b1
Update PublishCodeCoverage to v2 (#552)
dan-hughes Mar 30, 2026
3a4c84d
New pack task using PSResourceGet (#555)
gaelcolas Mar 31, 2026
d103ae2
Moved large parts of the ReadMe to the Wiki (#488)
DennisL68 Mar 31, 2026
14fd4c8
Updated comment based help for Resolve-Dependency.ps1 (#537)
ahpooch Mar 31, 2026
1dd4128
Considering the environment variable 'ModuleVersion' if it exists
raandree Jun 7, 2025
4bf20fa
Added support for GitVersion which is a breaking change
raandree Jun 8, 2025
108a7c2
Updated launch configs
raandree Jun 8, 2025
b735a45
Adapting tests to work with GitVersion 6
raandree Jun 9, 2025
0f0e234
Updated changelog
raandree Jun 9, 2025
726a060
Change deployment mode from ContinuousDelivery to ManualDeployment
raandree Jun 9, 2025
2964b55
Fixed typo
raandree Jun 9, 2025
6482676
Changes according to the code review
raandree Jul 24, 2025
7cbcc04
Added test to check for environment variable
raandree Jul 24, 2025
95e5ff7
Merge branch 'feature/gitversion6' of https://github.com/raandree/Sam…
raandree Apr 18, 2026
29103ae
fix: correct GitVersion 6 config for version bump regexes and feature…
raandree Apr 18, 2026
3e471ce
```
raandree Apr 18, 2026
75aaff7
test: add stubs for gitversion in environment variable tests
raandree Apr 18, 2026
6498e50
fix: standardize formatting of RequiredModules.psd1 entries
raandree Apr 20, 2026
f823e38
fix(gitversion): skip AzDo pipeline variable writes when not running …
raandree Apr 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .build/tasks/GitVersion.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
task GitVersion -if (Get-Command -Name dotnet-gitversion.exe, gitversion.exe -ErrorAction SilentlyContinue) {

$command = if (Get-Command -Name gitversion.exe -ErrorAction SilentlyContinue)
{
Write-Host 'Using gitversion.exe...'
'gitversion.exe'
}
elseif (Get-Command -Name dotnet-gitversion -ErrorAction SilentlyContinue)
{
Write-Host 'Using dotnet-gitversion...'
'dotnet-gitversion'
}
else
{
Write-Error 'Neither gitversion.exe nor dotnet-gitversion is available.'
return
}

$gitVersionObject = & $command
Write-Host -------------- GitVersion Outout --------------
$gitVersionObject | Write-Host
Write-Host -----------------------------------------------

$gitVersionObject = $gitVersionObject | ConvertFrom-Json
$longestKeyLength = ($gitVersionObject | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | Sort-Object { $_.Length } | Select-Object -Last 1).Length
$gitVersionObject.PSObject.Properties.ForEach{
Write-Host -Object ("Setting Task Variable {0,-$longestKeyLength} with value '{1}'." -f $_.Name, $_.Value)
}

$isPreRelease = [bool]$gitVersionObject.PreReleaseLabel
$versionElements = $gitVersionObject.MajorMinorPatch

if ($isPreRelease)
{
if ($gitVersionObject.BranchName -eq 'main')
{
$nextPreReleaseNumber = $gitVersionObject.PreReleaseNumber
$paddedNextPreReleaseNumber = '{0:D4}' -f $nextPreReleaseNumber

$versionElements += $gitVersionObject.PreReleaseLabelWithDash
$versionElements += $paddedNextPreReleaseNumber
}
else
{
$versionElements += $gitVersionObject.PreReleaseLabelWithDash
$versionElements += '.' + $gitVersionObject.CommitsSinceVersionSource
}
}

$versionString = -join $versionElements
[System.Environment]::SetEnvironmentVariable('ModuleVersion', $versionString, 'Process')

Write-Host "Writing version string '$versionString' to build / environment variable 'VersionString'."
Write-Host "##vso[task.setvariable variable=VersionString;]$($versionString)"

Write-Host "Updating build number to '$versionString'."
Write-Host "##vso[build.updatebuildnumber]$($versionString)"
}
38 changes: 35 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,41 @@
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell: Interactive Session",
"type": "PowerShell",
"request": "launch"
"request": "launch",
"name": "Launch Build",
"script": "${workspaceRoot}/Build.ps1",
"args": [],
"cwd": "${workspaceRoot}/"
},
{
"type": "PowerShell",
"request": "launch",
"name": "Launch Build -ResolveDependency",
"script": "${workspaceRoot}/Build.ps1",
"args": ["-ResolveDependency"],
"cwd": "${workspaceRoot}"
},
{
"type": "PowerShell",
"request": "launch",
"name": "Launch Test",
"script": "${workspaceRoot}/Build.ps1",
"args": ["-Tasks test"],
"cwd": "${workspaceRoot}"
},
{
"name": "PowerShell Interactive Session",
"type": "PowerShell",
"request": "launch",
"cwd": ""
},
{
"name": "PowerShell: Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"cwd": "${file}"
}
]
}
}
19 changes: 15 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Added support for GitVersion 6 (Breaking Change).
- Updated `GitVersion.yml` config file.
- Removed the GitVersion task in Azure DevOps pipeline.
- Added a task to the Azure DevOps pipeline to Install GitVersion.
- Added a new build task to Sampler: `GitVersion`.
- Updated `Get-SamplerBuildVersion` to be compatible with GitVersion 6.
- Updated `Get-SamplerBuildVersion` Pester tests.
- Changed `README.md`.

### Changed

- Using full-qualified call for `Expand-Archive` ([#519](https://github.com/gaelcolas/Sampler/issues/519)).
- Fixed a variable scoping issue preventing Pester tests to be invoked after the
first build ([#523](https://github.com/gaelcolas/Sampler/issues/523)).
- Set GitVersion mode to [`Manual Deployment` ](https://gitversion.net/docs/reference/modes/manual-deployment).
> "Having not the necessity to deploy the build artifacts on every commit is
an indication of using the Manual Deployment mode. This mode can be used to
remain on the same pre-released version until it has been deployed dedicatedly.
- Updated `GitVersion.yml` config file to work with GitVersion 6.

## [0.118.3] - 2025-04-29

Expand Down
33 changes: 10 additions & 23 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
mode: ContinuousDelivery
next-version: 0.90
mode: ManualDeployment
next-version: 0.90.0
major-version-bump-message: '\s?(breaking|major|breaking\schange)'
minor-version-bump-message: '(adds?|features?|minor)\b'
patch-version-bump-message: '\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
assembly-informational-format: '{NuGetVersionV2}+Sha.{Sha}.Date.{CommitDate}'
branches:
master:
tag: preview
regex: ^main$
main:
label: preview
regex: ^master$|^main$
pull-request:
tag: PR
label: PR
feature:
tag: useBranchName
label: '{BranchName}'
increment: Minor
regex: f(eature(s)?)?[\/-]
source-branches: ['master']
source-branches: ['main']
hotfix:
tag: fix
label: fix
increment: Patch
regex: (hot)?fix(es)?[\/-]
source-branches: ['master']
source-branches: ['main']

ignore:
sha: []
merge-message-formats: {}


# feature:
# tag: useBranchName
# increment: Minor
# regex: f(eature(s)?)?[/-]
# source-branches: ['master']
# hotfix:
# tag: fix
# increment: Patch
# regex: (hot)?fix(es)?[/-]
# source-branches: ['master']
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,6 @@ _Guest Configuration_. This process will be replaced with a Plaster template.
Enable-ExperimentalFeature -Name GuestConfiguration.Pester
Enable-ExperimentalFeature -Name GuestConfiguration.SetScenario
Enable-ExperimentalFeature -Name PSDesiredStateConfiguration.InvokeDscResource -ErrorAction SilentlyContinue
env:
ModuleVersion: $(gitVersion.NuGetVersionV2)
```

1. Remove the job `Test_HQRM`.
Expand Down Expand Up @@ -1648,9 +1646,9 @@ default path in variable `BuildModuleOutput`.

### `ModuleVersion`

The module version of the built module. Defaults to the property `NuGetVersionV2`
The module version of the built module. Defaults to the property `ModuleVersion`
returned by the executable `gitversion`, or if the executable `gitversion`
is not available the the variable defaults to an empty string, and the
is not available the variable defaults to an empty string, and the
build module task will use the version found in the Module Manifest.

It is also possible to set the session environment variable `$env:ModuleVersion`
Expand Down
46 changes: 39 additions & 7 deletions Sampler/Public/Get-SamplerBuildVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Path to the Module Manifest that should determine the version if GitVersion is not available.

.PARAMETER ModuleVersion
Provide the Version to be splitted and do not rely on GitVersion or the Module's manifest.
Provide the Version to be split and do not rely on GitVersion or the Module's manifest.

.EXAMPLE
Get-SamplerBuildVersion -ModuleManifestPath source\MyModule.psd1
Expand All @@ -34,24 +34,56 @@ function Get-SamplerBuildVersion
$ModuleVersion
)

if (-not [string]::IsNullOrEmpty($env:ModuleVersion))
{
$ModuleVersion = $env:ModuleVersion
Comment thread
raandree marked this conversation as resolved.
Write-Verbose -Message "Using ModuleVersion from environment variable: $ModuleVersion"
}

if ([System.String]::IsNullOrEmpty($ModuleVersion))
{
Write-Verbose -Message 'Module version is not determined yet. Evaluating methods to get new module version.'

$gitVersionAvailable = Get-Command -Name 'gitversion' -ErrorAction 'SilentlyContinue'
$donetGitversionAvailable = Get-Command -Name 'dotnet-gitversion' -ErrorAction 'SilentlyContinue'
$gitVersionAvailable = Get-Command -Name gitversion -ErrorAction SilentlyContinue
$dotnetGitversionAvailable = Get-Command -Name 'dotnet-gitversion' -ErrorAction SilentlyContinue

# If dotnet-gitversion is available and gitversion is not, alias it to gitversion.
if ($donetGitversionAvailable -and -not $gitVersionAvailable)
if ($dotnetGitversionAvailable -and -not $gitVersionAvailable)
{
New-Alias -Name 'gitversion' -Value 'dotnet-gitversion' -Scope 'Script' -ErrorAction 'SilentlyContinue'
New-Alias -Name gitversion -Value dotnet-gitversion -Scope Script -ErrorAction SilentlyContinue
}

if ($gitVersionAvailable -or $donetGitversionAvailable)
if ($gitVersionAvailable -or $dotnetGitversionAvailable)
{
Write-Verbose -Message 'Using the version from GitVersion.'

$ModuleVersion = (gitversion | ConvertFrom-Json -ErrorAction 'Stop').NuGetVersionV2
$gitVersionObject = gitversion | ConvertFrom-Json -ErrorAction Stop
$isPreRelease = [bool]$gitVersionObject.PreReleaseLabel
$versionElements = $gitVersionObject.MajorMinorPatch

if ($isPreRelease)
{
if ($gitVersionObject.BranchName -eq 'main')
{
$nextPreReleaseNumber = $gitVersionObject.PreReleaseNumber
$paddedNextPreReleaseNumber = '{0:D4}' -f $nextPreReleaseNumber

$versionElements += $gitVersionObject.PreReleaseLabelWithDash
Comment thread
raandree marked this conversation as resolved.
Outdated
$versionElements += $paddedNextPreReleaseNumber
}
else
{
$versionElements += $gitVersionObject.PreReleaseLabelWithDash
$versionElements += '.' + $gitVersionObject.CommitsSinceVersionSource
}
}

$ModuleVersion = $versionElements -join '.'

Write-Verbose -Message (
"GitVersion returned the version '{0}'." -f $ModuleVersion
)

}
elseif (-not [System.String]::IsNullOrEmpty($ModuleManifestPath))
{
Expand Down
20 changes: 9 additions & 11 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ stages:
pool:
vmImage: 'windows-latest'
steps:
- pwsh: |
dotnet tool install --global GitVersion.Tool --version 5.*
$gitVersionObject = dotnet-gitversion | ConvertFrom-Json
$gitVersionObject.PSObject.Properties.ForEach{
Write-Host -Object "Setting Task Variable '$($_.Name)' with value '$($_.Value)'."
Write-Host -Object "##vso[task.setvariable variable=$($_.Name);]$($_.Value)"
}
Write-Host -Object "##vso[build.updatebuildnumber]$($gitVersionObject.FullSemVer)"
displayName: Calculate ModuleVersion (GitVersion)

- task: DotNetCoreCLI@2
inputs:
command: custom
custom: tool
arguments: install --global GitVersion.Tool
displayName: Install GitVersionTool

- task: PowerShell@2
name: package
displayName: 'Build & Package Module'
inputs:
filePath: './build.ps1'
arguments: '-ResolveDependency -tasks pack'
pwsh: true
env:
ModuleVersion: $(NuGetVersionV2)

- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifact'
inputs:
Expand Down
24 changes: 19 additions & 5 deletions tests/Unit/Public/Get-SamplerBuildVersion.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Describe 'Get-SamplerBuildVersion' {
Context 'When passing a module version' {
BeforeAll {
Mock -CommandName gitversion -MockWith {
return '{"NuGetVersionV2": "2.1.3"}'
return '{"MajorMinorPatch":"2.1.3"}'
}
}

Expand All @@ -130,7 +130,7 @@ Describe 'Get-SamplerBuildVersion' {
Context 'When passing a preview module version' {
BeforeAll {
Mock -CommandName gitversion -MockWith {
return '{"NuGetVersionV2": "2.1.3-preview0023"}'
return '{"MajorMinorPatch":"2.1.3","PreReleaseLabel":"preview","PreReleaseLabelWithDash":"-preview","PreReleaseNumber":23,"BranchName":"main","CommitsSinceVersionSource":50}'
}
}

Expand Down Expand Up @@ -216,7 +216,7 @@ Describe 'Get-SamplerBuildVersion' {
Context 'When passing a module version' {
BeforeAll {
Mock -CommandName gitversion -MockWith {
return '{"NuGetVersionV2": "2.1.3"}'
return '{"MajorMinorPatch":"2.1.3"}'
}
}

Expand All @@ -227,10 +227,10 @@ Describe 'Get-SamplerBuildVersion' {
}
}

Context 'When passing a preview module version' {
Context 'When passing a preview module version in main branch' {
BeforeAll {
Mock -CommandName gitversion -MockWith {
return '{"NuGetVersionV2": "2.1.3-preview0023"}'
return '{"MajorMinorPatch":"2.1.3","PreReleaseLabel":"preview","PreReleaseLabelWithDash":"-preview","PreReleaseNumber":23,"BranchName":"main","CommitsSinceVersionSource":50}'
}
}

Expand All @@ -240,6 +240,20 @@ Describe 'Get-SamplerBuildVersion' {
$result | Should -Be '2.1.3-preview0023'
}
}

Context 'When passing a preview module version in fix branch' {
BeforeAll {
Mock -CommandName gitversion -MockWith {
return '{"MajorMinorPatch":"2.1.3","PreReleaseLabel":"preview","PreReleaseLabelWithDash":"-preview","PreReleaseNumber":23,"BranchName":"fix/Something","CommitsSinceVersionSource":50}'
}
}

It 'Should return the correct module version' {
$result = Sampler\Get-SamplerBuildVersion -ModuleManifestPath $TestDrive

$result | Should -Be '2.1.3-preview.50'
}
}
}
}

Expand Down