Created
January 30, 2025 15:44
-
-
Save llaughlin/b63da19d4065aba1e655b89a7a41023e to your computer and use it in GitHub Desktop.
Directory.Packages.props version changes
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
# Define paths and branches | |
$packagesPropsPath = "Directory.Packages.props" | |
$currentBranch = (git rev-parse --abbrev-ref HEAD) | |
$commits = (git log --format="%h %p" -n 1).Split(" ") | |
$currentCommit = $commits[0] | |
$currentCommitBody = (git log --format=%s -n 1 $currentCommit) | |
$previousCommit = $commits[1] | |
$previousCommitBody = (git log --format=%s -n 1 $previousCommit) | |
Write-Host -NoNewline -ForegroundColor Cyan "Comparing versions between " | |
Write-Host -NoNewline -ForegroundColor Blue "$currentBranch ($currentCommitBody)" | |
Write-Host -NoNewline -ForegroundColor Cyan " and " | |
Write-Host -NoNewline -ForegroundColor Green "$previousCommit ($previousCommitBody)" | |
Write-Host -ForegroundColor Cyan "" | |
# Function to read package versions from a branch | |
function Get-PackageVersions { | |
param($commit) | |
Write-Host -NoNewline -ForegroundColor DarkGray ("Checking out commit ") | |
Write-Host -NoNewline -ForegroundColor Magenta ("$commit (" + (git log --format=%s -n 1 $commit) + ")") | |
write-host "" | |
git checkout $commit --quiet | |
[xml]$packagesProps = Get-Content -Path $packagesPropsPath | |
$packageVersions = @() | |
foreach ($package in $packagesProps.Project.ItemGroup.PackageVersion) { | |
$packageVersions += [PSCustomObject]@{ | |
PackageName = $package.Include | |
Version = $package.Version | |
} | |
} | |
return $packageVersions | |
} | |
# Get current branch package versions | |
$currentVersions = Get-PackageVersions -commit $currentCommit | Sort-Object PackageName | |
# Get previous commit package versions | |
$previousCommitVersions = Get-PackageVersions -commit $previousCommit | |
# Compare versions and output changes | |
Write-Output "" | |
Write-Output "| Package Name | Current Version | Previous Version |" | |
Write-Output "|--------------|----------------:|-----------------:|" | |
foreach ($currentPackage in $currentVersions) { | |
$otherPackage = $previousCommitVersions | Where-Object { $_.PackageName -eq $currentPackage.PackageName } | |
if ($otherPackage) { | |
if ($currentPackage.Version -ne $otherPackage.Version) { | |
Write-Output "| $($currentPackage.PackageName) | $($currentPackage.Version) | $($otherPackage.Version) |" | |
} | |
} else { | |
Write-Output "| $($currentPackage.PackageName) | $($currentPackage.Version) | Not Found |" | |
} | |
} | |
# Switch back to the original branch | |
Write-Host -NoNewline -ForegroundColor DarkGray "Checking out original branch " | |
Write-Host -NoNewline -ForegroundColor Blue "$currentBranch" | |
git checkout $currentBranch --quiet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment