mirror of
https://github.com/cmderdev/cmder.git
synced 2026-04-15 06:44:31 +08:00
Extract version parsing to shared function and improve error handling
- Created Get-VersionChangeType function in scripts/utils.ps1 (DRY principle) - Updated vendor.yml and update.ps1 to use shared function - Fixed numeric comparison for COUNT_UPDATED (fromJSON for proper numeric eval) - Improved git operation error handling with proper exit code checking - Only reset commit if it succeeded but push failed Agent-Logs-Url: https://github.com/cmderdev/cmder/sessions/4511d497-599a-4a80-bc3c-12bd6f2d8191 Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
09b00758b1
commit
58ab7976d2
85
.github/workflows/vendor.yml
vendored
85
.github/workflows/vendor.yml
vendored
@@ -57,6 +57,9 @@ jobs:
|
||||
Set-GHVariable -Name COUNT_UPDATED -Value $count
|
||||
|
||||
$newVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json)
|
||||
# Source utility functions
|
||||
. scripts/utils.ps1
|
||||
|
||||
$listUpdated = ""
|
||||
$updateMessage = "| Name | Old Version | New Version |`n| :--- | :---: | :---: |`n"
|
||||
$majorUpdates = @()
|
||||
@@ -75,46 +78,11 @@ jobs:
|
||||
$singleDepNewVersion = $s.version
|
||||
}
|
||||
|
||||
# Determine change type and emoji
|
||||
$changeType = "unknown"
|
||||
$emoji = "🔄"
|
||||
$isMajor = $false
|
||||
try {
|
||||
# Handle versions with more than 4 parts
|
||||
$oldVerStr = $oldVersion.Split('-')[0]
|
||||
$newVerStr = $s.version.Split('-')[0]
|
||||
|
||||
# Split by dots and take only numeric parts, first 4 max
|
||||
$oldParts = $oldVerStr.Split('.') | Where-Object { $_ -match '^\d+$' } | Select-Object -First 4
|
||||
$newParts = $newVerStr.Split('.') | Where-Object { $_ -match '^\d+$' } | Select-Object -First 4
|
||||
|
||||
# Ensure we have at least 2 parts (major.minor)
|
||||
if ($oldParts.Count -ge 2 -and $newParts.Count -ge 2) {
|
||||
$oldVerParseable = $oldParts -join '.'
|
||||
$newVerParseable = $newParts -join '.'
|
||||
|
||||
$oldVer = [System.Version]::Parse($oldVerParseable)
|
||||
$newVer = [System.Version]::Parse($newVerParseable)
|
||||
|
||||
if ($newVer.Major -gt $oldVer.Major) {
|
||||
$changeType = "major"
|
||||
$emoji = "🔥"
|
||||
$isMajor = $true
|
||||
} elseif ($newVer.Minor -gt $oldVer.Minor) {
|
||||
$changeType = "minor"
|
||||
$emoji = "🚀"
|
||||
} elseif ($newVer -gt $oldVer) {
|
||||
$changeType = "patch"
|
||||
$emoji = "⬆️"
|
||||
} else {
|
||||
$changeType = "unknown"
|
||||
$emoji = "🔄"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
$changeType = "unknown"
|
||||
$emoji = "🔄"
|
||||
}
|
||||
# Determine change type and emoji using shared function
|
||||
$result = Get-VersionChangeType -OldVersion $oldVersion -NewVersion $s.version
|
||||
$changeType = $result.ChangeType
|
||||
$emoji = $result.Emoji
|
||||
$isMajor = $result.IsMajor
|
||||
|
||||
# Track major updates for changelog section
|
||||
if ($isMajor) {
|
||||
@@ -229,18 +197,26 @@ jobs:
|
||||
# Commit the changes
|
||||
git add vendor/sources.json
|
||||
$commitResult = git commit -m "⬆️ Update dependencies ($env:LIST_UPDATED)"
|
||||
$commitSuccess = $LASTEXITCODE -eq 0
|
||||
|
||||
if ($commitResult) {
|
||||
if ($commitSuccess) {
|
||||
# Push directly to master
|
||||
git push origin HEAD:master
|
||||
$pushSuccess = $LASTEXITCODE -eq 0
|
||||
|
||||
echo "" >> $env:GITHUB_STEP_SUMMARY
|
||||
echo "✅ **Success!** Updates have been automatically merged to master." >> $env:GITHUB_STEP_SUMMARY
|
||||
echo "" >> $env:GITHUB_STEP_SUMMARY
|
||||
echo "**Updated dependencies:** $env:LIST_UPDATED" >> $env:GITHUB_STEP_SUMMARY
|
||||
if ($pushSuccess) {
|
||||
echo "" >> $env:GITHUB_STEP_SUMMARY
|
||||
echo "✅ **Success!** Updates have been automatically merged to master." >> $env:GITHUB_STEP_SUMMARY
|
||||
echo "" >> $env:GITHUB_STEP_SUMMARY
|
||||
echo "**Updated dependencies:** $env:LIST_UPDATED" >> $env:GITHUB_STEP_SUMMARY
|
||||
|
||||
# Set a flag to skip PR creation
|
||||
echo "AUTO_MERGED=true" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||
# Set a flag to skip PR creation
|
||||
echo "AUTO_MERGED=true" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||
} else {
|
||||
throw "Failed to push to master (exit code: $LASTEXITCODE)"
|
||||
}
|
||||
} else {
|
||||
throw "Failed to commit changes (exit code: $LASTEXITCODE)"
|
||||
}
|
||||
} catch {
|
||||
echo "" >> $env:GITHUB_STEP_SUMMARY
|
||||
@@ -252,9 +228,16 @@ jobs:
|
||||
|
||||
Write-Warning "Failed to auto-merge: $($_.Exception.Message)"
|
||||
|
||||
# Reset the commit if one was made
|
||||
if ($commitResult) {
|
||||
git reset --hard HEAD~1
|
||||
# Only reset if commit was successful but push failed
|
||||
if ($commitSuccess -and -not $pushSuccess) {
|
||||
try {
|
||||
git reset --hard HEAD~1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Warning "Failed to reset commit (exit code: $LASTEXITCODE), continuing with PR creation"
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "Failed to reset commit: $($_.Exception.Message), continuing with PR creation"
|
||||
}
|
||||
}
|
||||
|
||||
# Set flag to create PR instead
|
||||
@@ -262,7 +245,7 @@ jobs:
|
||||
}
|
||||
|
||||
- uses: peter-evans/create-pull-request@v8
|
||||
if: env.COUNT_UPDATED > 0 && (env.HAS_BREAKING_CHANGES == 'True' || env.AUTO_MERGED == 'false')
|
||||
if: fromJSON(env.COUNT_UPDATED) > 0 && (env.HAS_BREAKING_CHANGES == 'True' || env.AUTO_MERGED == 'false')
|
||||
with:
|
||||
title: ${{ env.COUNT_UPDATED == 1 && format('⬆️ Update {0}', env.LIST_UPDATED) || format('⬆️ Update {0} vendored dependencies', env.COUNT_UPDATED) }}
|
||||
body: |
|
||||
|
||||
Reference in New Issue
Block a user