-
Notifications
You must be signed in to change notification settings - Fork 247
feat: track ModuleVersion and ConfigVersion in maester-config.json #1760
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
Open
SamErde
wants to merge
9
commits into
main
Choose a base branch
from
feat/TrackMaesterConfigVersion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7afc5ca
feat: track ModuleVersion and ConfigVersion in maester-config.json
SamErde 26e35da
fix: address Copilot review on PR #1760
SamErde 80dd357
fix: address Copilot review round 2 on PR #1760
SamErde 4c62a61
fix: address Copilot review round 3 on PR #1760
SamErde 2c91e32
fix: quote github.repository expansion in gh release view call
SamErde b63f381
Merge branch 'main' into feat/TrackMaesterConfigVersion
SamErde f542918
Merge branch 'main' into feat/TrackMaesterConfigVersion
SamErde 126aaba
Merge branch 'main' into feat/TrackMaesterConfigVersion
SamErde 607f169
fix: address config version review feedback
SamErde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Stamps the ModuleVersion and ConfigVersion fields at the top of a | ||
| maester-config.json file. | ||
|
|
||
| .DESCRIPTION | ||
| Reads and updates the JSON object directly, then writes UTF-8 without BOM. | ||
| Uses an explicit JSON depth when writing so future nested settings are not | ||
| truncated by the default ConvertTo-Json depth. | ||
|
|
||
| Both fields must already exist in the source file. The script does not | ||
| insert missing fields — if either is absent, it throws and asks the | ||
| caller to add them manually. This avoids fragile insertion logic and | ||
| makes schema changes explicit in source control. | ||
|
|
||
| ConfigVersion is a CalVer-style YYYY.MM.DD.N string derived from git | ||
| history of the config file: YYYY.MM.DD is the date of the most recent | ||
| commit to the file; N is the count of commits to the file on that date. | ||
| Auto-computed when -ConfigVersion is omitted (the normal CI path). | ||
|
|
||
| Requires sufficient git history to find the last commit touching the file, | ||
| so callers should run actions/checkout with fetch-depth: 0. | ||
| #> | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory)] [string] $ConfigPath, | ||
| [Parameter(Mandatory)] [string] $ModuleVersion, | ||
| [Parameter()] [string] $ConfigVersion | ||
| ) | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| if (-not (Test-Path -LiteralPath $ConfigPath)) { | ||
| throw "Config file not found: $ConfigPath" | ||
| } | ||
|
|
||
| if (-not $PSBoundParameters.ContainsKey('ConfigVersion')) { | ||
| # Resolve to a repo-relative path so git lookup works regardless of CWD | ||
| # or whether ConfigPath was passed as relative or absolute. | ||
| $resolvedConfigPath = (Resolve-Path -LiteralPath $ConfigPath).ProviderPath | ||
| $configDir = Split-Path -Parent $resolvedConfigPath | ||
| $repoRoot = (& git -C $configDir rev-parse --show-toplevel 2>$null) | ||
| if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($repoRoot)) { | ||
| throw "Could not determine ConfigVersion: $ConfigPath is not inside a git repository." | ||
| } | ||
| $repoRoot = $repoRoot.Trim() | ||
| $repoRelative = [System.IO.Path]::GetRelativePath($repoRoot, $resolvedConfigPath).Replace('\', '/') | ||
| $commitTimestamps = @(& git -C $repoRoot log --format=%ct -- $repoRelative) | ||
| if ($LASTEXITCODE -ne 0 -or $commitTimestamps.Count -eq 0) { | ||
| throw "Could not determine ConfigVersion: no git history found for $repoRelative in $repoRoot." | ||
| } | ||
| $utcDates = @($commitTimestamps | ForEach-Object { | ||
| [System.DateTimeOffset]::FromUnixTimeSeconds([long]$_).UtcDateTime.ToString('yyyy.MM.dd', [System.Globalization.CultureInfo]::InvariantCulture) | ||
| }) | ||
| $lastDate = $utcDates[0] | ||
| $sameDayCount = @($utcDates | Where-Object { $_ -eq $lastDate }).Count | ||
| $ConfigVersion = "$lastDate.$sameDayCount" | ||
| Write-Verbose "Computed ConfigVersion=$ConfigVersion (date $lastDate, $sameDayCount commit(s) that day)" | ||
| } | ||
|
|
||
| $content = Get-Content -LiteralPath $ConfigPath -Raw | ||
| try { | ||
| $config = $content | ConvertFrom-Json | ||
| } catch { | ||
| throw "Input file is not valid JSON: $_" | ||
| } | ||
|
|
||
| if (-not ($config.PSObject.Properties.Name -contains 'ModuleVersion')) { | ||
| throw "Required field ModuleVersion not found in $ConfigPath. Add `"ModuleVersion`": `"<version>`" as a top-level key before re-running." | ||
| } | ||
|
|
||
| if (-not ($config.PSObject.Properties.Name -contains 'ConfigVersion')) { | ||
| throw "Required field ConfigVersion not found in $ConfigPath. Add `"ConfigVersion`": `"`" as a top-level key before re-running." | ||
| } | ||
|
|
||
| $config.ModuleVersion = $ModuleVersion | ||
| $config.ConfigVersion = $ConfigVersion | ||
| $updatedContent = $config | ConvertTo-Json -Depth 10 -WarningAction Stop | ||
|
|
||
| try { $null = $updatedContent | ConvertFrom-Json } catch { throw "Output is not valid JSON after stamping: $_" } | ||
|
|
||
| $utf8NoBom = [System.Text.UTF8Encoding]::new($false) | ||
| $resolvedOutputPath = (Resolve-Path -LiteralPath $ConfigPath).ProviderPath | ||
| [System.IO.File]::WriteAllText($resolvedOutputPath, $updatedContent, $utf8NoBom) | ||
|
|
||
| Write-Host "Stamped ${ConfigPath}: ModuleVersion=$ModuleVersion, ConfigVersion=$ConfigVersion" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.