Skip to content

Commit 41f1d83

Browse files
author
Github Actions
committed
Refactor PSBuild module to improve Git command execution by ensuring proper quoting in various functions. This change enhances the reliability of versioning and commit operations, and improves the clarity of the commit range logic.
1 parent 37eb631 commit 41f1d83

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

scripts/PSBuild.psm1

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,6 @@ function Get-BuildConfiguration {
162162
}
163163
}
164164

165-
$config | ConvertTo-Json | Write-InformationStream -Tags "Get-BuildConfiguration"
166-
167165
return $config
168166
}
169167

@@ -253,15 +251,15 @@ function Get-VersionType {
253251
)
254252
$excludeString = $EXCLUDE_PATTERNS -join ' '
255253

256-
$codeChanges = "git log --topo-order --perl-regexp --regexp-ignore-case --format=format:%H --committer=`"$EXCLUDE_BOTS`" --author=`"$EXCLUDE_BOTS`" --grep=`"$EXCLUDE_PRS`" --invert-grep $Range -- '*/*.*' $excludeString" | Invoke-ExpressionWithLogging -Tags "Get-VersionType"
254+
$codeChanges = "git log --topo-order --perl-regexp --regexp-ignore-case --format=format:%H --committer=`"$EXCLUDE_BOTS`" --author=`"$EXCLUDE_BOTS`" --grep=`"$EXCLUDE_PRS`" --invert-grep `"$Range`" -- '*/*.*' `"$excludeString`"" | Invoke-ExpressionWithLogging -Tags "Get-VersionType"
257255

258256
if ($codeChanges) {
259257
$versionType = "minor"
260258
$reason = "Found code changes requiring at least a minor version"
261259
}
262260

263261

264-
$messages = "git log --format=format:%s $Range" | Invoke-ExpressionWithLogging -Tags "Get-VersionType"
262+
$messages = "git log --format=format:%s `"$Range`"" | Invoke-ExpressionWithLogging -Tags "Get-VersionType"
265263

266264
foreach ($message in $messages) {
267265
$versionTags = @{
@@ -380,13 +378,11 @@ function Get-VersionInfoFromGit {
380378

381379
# Determine version increment type
382380
Write-Information "$($script:lineEnding)Getting first commit..." -Tags "Get-VersionInfoFromGit"
383-
Write-Information "Running: git rev-list HEAD" -Tags "Get-VersionInfoFromGit"
384-
$output = git rev-list HEAD
385-
Write-Information "git rev-list HEAD output:$script:lineEnding$output" -Tags "Get-VersionInfoFromGit"
386-
$firstCommit = $output[-1]
381+
$firstCommit = "git rev-list HEAD" | Invoke-ExpressionWithLogging -Tags "Get-VersionInfoFromGit"
382+
$firstCommit = $firstCommit[-1]
387383
Write-Information "First commit: $firstCommit" -Tags "Get-VersionInfoFromGit"
388384

389-
$commitRange = "$firstCommit...$CommitHash"
385+
$commitRange = "$firstCommit..$CommitHash"
390386
Write-Information "$($script:lineEnding)Analyzing commit range: $commitRange" -Tags "Get-VersionInfoFromGit"
391387
$incrementInfo = Get-VersionType -Range $commitRange
392388
$incrementType = $incrementInfo.Type
@@ -788,11 +784,11 @@ function Get-VersionNotes {
788784
# Set up the git log command range
789785
$range = $rangeTo
790786
if ($rangeFrom -ne "") {
791-
$range = "$rangeFrom...$rangeTo"
787+
$range = "$rangeFrom..$rangeTo"
792788
}
793789

794790
# Get commit messages with authors - common logic for all cases
795-
$commits = "git log --pretty=format:`"%s ([@%aN](https://github.com/%aN))`" --perl-regexp --regexp-ignore-case --grep=`"$EXCLUDE_PRS`" --invert-grep --committer=`"$EXCLUDE_BOTS`" --author=`"$EXCLUDE_BOTS`" $range | Sort-Object | Get-Unique" | Invoke-ExpressionWithLogging
791+
$commits = "git log --pretty=format:`"%s ([@%aN](https://github.com/%aN))`" --perl-regexp --regexp-ignore-case --grep=`"$EXCLUDE_PRS`" --invert-grep --committer=`"$EXCLUDE_BOTS`" --author=`"$EXCLUDE_BOTS`" `"$range`" | Sort-Object | Get-Unique" | Invoke-ExpressionWithLogging
796792

797793
# Format changelog entry
798794
$versionChangelog = ""
@@ -1003,7 +999,7 @@ function Update-ProjectMetadata {
1003999
Set-GitIdentity | Write-InformationStream -Tags "Update-ProjectMetadata"
10041000

10051001
Write-Information "Committing changes..." -Tags "Update-ProjectMetadata"
1006-
"git commit -m $CommitMessage" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Update-ProjectMetadata"
1002+
"git commit -m `"$CommitMessage`"" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Update-ProjectMetadata"
10071003

10081004
Write-Information "Pushing changes..." -Tags "Update-ProjectMetadata"
10091005
"git push" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "Update-ProjectMetadata"
@@ -1365,7 +1361,7 @@ function New-GitHubRelease {
13651361

13661362
# Create and push the tag first
13671363
Write-Information "Creating and pushing tag v$($BuildConfiguration.Version)..." -Tags "New-GitHubRelease"
1368-
"git tag -a `"v$($BuildConfiguration.Version)`" $BuildConfiguration.ReleaseHash -m `"Release v$($BuildConfiguration.Version)`"" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "New-GitHubRelease"
1364+
"git tag -a `"v$($BuildConfiguration.Version)`" `"$($BuildConfiguration.ReleaseHash)`" -m `"Release v$($BuildConfiguration.Version)`"" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "New-GitHubRelease"
13691365
Assert-LastExitCode "Failed to create git tag"
13701366

13711367
"git push origin `"v$($BuildConfiguration.Version)`"" | Invoke-ExpressionWithLogging | Write-InformationStream -Tags "New-GitHubRelease"

0 commit comments

Comments
 (0)