Skip to content

Commit be60888

Browse files
CopilotDRSDavidSoft
andcommitted
Improve vendor CI/CD workflow with better messaging and auto-merge
Co-authored-by: DRSDavidSoft <[email protected]>
1 parent d61a4f7 commit be60888

File tree

2 files changed

+137
-16
lines changed

2 files changed

+137
-16
lines changed

.github/workflows/vendor.yml

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ jobs:
3131
- name: Summary - Workflow started
3232
shell: pwsh
3333
run: |
34-
echo "## 📦 Update Vendor - Workflow Summary" >> $env:GITHUB_STEP_SUMMARY
34+
echo "## 📦 Vendor Update - Workflow Summary" >> $env:GITHUB_STEP_SUMMARY
3535
echo "" >> $env:GITHUB_STEP_SUMMARY
36-
echo "Checking for vendor dependency updates..." >> $env:GITHUB_STEP_SUMMARY
36+
echo "🔍 Checking for vendor dependency updates..." >> $env:GITHUB_STEP_SUMMARY
3737
echo "" >> $env:GITHUB_STEP_SUMMARY
3838
3939
- id: make-changes
@@ -46,13 +46,36 @@ jobs:
4646
Set-GHVariable -Name COUNT_UPDATED -Value $count
4747
$newVersion = (Get-Content .\vendor\sources.json | ConvertFrom-Json)
4848
$listUpdated = ""
49-
$updateMessage = "| Name | Old Version | New Version |`n| :--- | ---- | ---- |`n"
49+
$updateMessage = "| Name | Old Version | New Version | Change Type |`n| :--- | :---: | :---: | :---: |`n"
5050
foreach ($s in $newVersion) {
5151
$oldVersion = ($currentVersion | Where-Object {$_.name -eq $s.name}).version
5252
if ($s.version -ne $oldVersion) {
5353
$repoUrl = ($repoUrl = $s.Url.Replace("/archive/", "/releases/")).Substring(0, $repoUrl.IndexOf("/releases/")) + "/releases"
54+
55+
# Determine change type and emoji
56+
$changeType = "unknown"
57+
$emoji = "🔄"
58+
try {
59+
$oldVer = [System.Version]::Parse($oldVersion.Split('-')[0])
60+
$newVer = [System.Version]::Parse($s.version.Split('-')[0])
61+
62+
if ($newVer.Major -gt $oldVer.Major) {
63+
$changeType = "major"
64+
$emoji = "⚠️"
65+
} elseif ($newVer.Minor -gt $oldVer.Minor) {
66+
$changeType = "minor"
67+
$emoji = "✨"
68+
} else {
69+
$changeType = "patch"
70+
$emoji = "🐛"
71+
}
72+
} catch {
73+
$changeType = "unknown"
74+
$emoji = "🔄"
75+
}
76+
5477
$listUpdated += "$($s.name) v$($s.version), "
55-
$updateMessage += "| **[$($s.name)]($repoUrl)** | $oldVersion | **$($s.version)** |`n"
78+
$updateMessage += "| $emoji **[$($s.name)]($repoUrl)** | \`$oldVersion\` | \`$($s.version)\` | $changeType |`n"
5679
}
5780
}
5881
if ($count -eq 0) { return }
@@ -66,32 +89,89 @@ jobs:
6689
if ($count -eq 0) {
6790
echo "### ✅ No Updates Available" >> $env:GITHUB_STEP_SUMMARY
6891
echo "" >> $env:GITHUB_STEP_SUMMARY
69-
echo "All vendor dependencies are up to date." >> $env:GITHUB_STEP_SUMMARY
92+
echo "All vendor dependencies are up to date! 🎉" >> $env:GITHUB_STEP_SUMMARY
7093
} else {
7194
$word = if ($count -eq 1) { 'dependency' } else { 'dependencies' }
95+
$emoji = if ($count -eq 1) { '📦' } else { '📦📦' }
7296
echo "### 🔄 Updates Found" >> $env:GITHUB_STEP_SUMMARY
7397
echo "" >> $env:GITHUB_STEP_SUMMARY
74-
echo "**$count** vendor $word updated:" >> $env:GITHUB_STEP_SUMMARY
98+
echo "$emoji **$count** vendor $word updated:" >> $env:GITHUB_STEP_SUMMARY
7599
echo "" >> $env:GITHUB_STEP_SUMMARY
76100
echo "$env:UPDATE_MESSAGE" >> $env:GITHUB_STEP_SUMMARY
77101
echo "" >> $env:GITHUB_STEP_SUMMARY
102+
103+
# Check if we can auto-merge (only minor/patch changes)
104+
$hasBreaking = $env:HAS_BREAKING_CHANGES -eq 'True'
105+
if ($hasBreaking) {
106+
echo "> ⚠️ **Note:** This update contains major version changes that may include breaking changes." >> $env:GITHUB_STEP_SUMMARY
107+
} else {
108+
echo "> ℹ️ **Note:** This update only contains minor or patch changes." >> $env:GITHUB_STEP_SUMMARY
109+
}
110+
}
111+
112+
- name: Auto-merge minor updates
113+
if: env.COUNT_UPDATED > 0 && env.HAS_BREAKING_CHANGES != 'True'
114+
shell: pwsh
115+
run: |
116+
try {
117+
echo "### 🚀 Auto-merging Updates" >> $env:GITHUB_STEP_SUMMARY
118+
echo "" >> $env:GITHUB_STEP_SUMMARY
119+
echo "Attempting to automatically merge non-breaking changes to master..." >> $env:GITHUB_STEP_SUMMARY
120+
121+
git config --global user.name "github-actions[bot]"
122+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
123+
124+
# Commit the changes
125+
git add vendor/sources.json
126+
git commit -m "⬆️ Update dependencies ($env:LIST_UPDATED)"
127+
128+
# Push directly to master
129+
git push origin HEAD:master
130+
131+
echo "" >> $env:GITHUB_STEP_SUMMARY
132+
echo "✅ **Success!** Updates have been automatically merged to master." >> $env:GITHUB_STEP_SUMMARY
133+
echo "" >> $env:GITHUB_STEP_SUMMARY
134+
echo "**Updated dependencies:** $env:LIST_UPDATED" >> $env:GITHUB_STEP_SUMMARY
135+
136+
# Set a flag to skip PR creation
137+
echo "AUTO_MERGED=true" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
138+
} catch {
139+
echo "" >> $env:GITHUB_STEP_SUMMARY
140+
echo "⚠️ **Warning:** Unable to automatically merge updates." >> $env:GITHUB_STEP_SUMMARY
141+
echo "" >> $env:GITHUB_STEP_SUMMARY
142+
echo "**Error:** $($_.Exception.Message)" >> $env:GITHUB_STEP_SUMMARY
143+
echo "" >> $env:GITHUB_STEP_SUMMARY
144+
echo "Falling back to creating a pull request..." >> $env:GITHUB_STEP_SUMMARY
145+
146+
Write-Warning "Failed to auto-merge: $($_.Exception.Message)"
147+
148+
# Reset changes so PR creation can work
149+
git reset --hard HEAD~1
150+
151+
# Set flag to create PR instead
152+
echo "AUTO_MERGED=false" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
78153
}
79154
80155
- uses: peter-evans/create-pull-request@v7
81-
if: env.COUNT_UPDATED > 0
156+
if: env.COUNT_UPDATED > 0 && (env.HAS_BREAKING_CHANGES == 'True' || env.AUTO_MERGED == 'false')
82157
with:
83-
title: 'Updates to `${{ env.COUNT_UPDATED }}` vendored dependencies'
158+
title: ${{ env.COUNT_UPDATED == '1' && format('⬆️ Update {0}', env.LIST_UPDATED) || format('⬆️ Update {0} vendored dependencies', env.COUNT_UPDATED) }}
84159
body: |
85-
### Automatically updated `${{ env.COUNT_UPDATED }}` dependencies:
160+
### ${{ env.COUNT_UPDATED == '1' && '📦 Automatically updated 1 dependency' || format('📦 Automatically updated {0} dependencies', env.COUNT_UPDATED) }}
161+
86162
${{ env.UPDATE_MESSAGE }}
163+
87164
---
88-
Please verify and then **Merge** the pull request to update.
165+
166+
${{ env.HAS_BREAKING_CHANGES == 'True' && '⚠️ **This update contains major version changes that may include breaking changes.**' || 'ℹ️ This update only contains minor or patch changes.' }}
167+
168+
Please verify and then **Merge** the pull request to apply the updates.
89169
commit-message: '⬆️ Update dependencies (${{ env.LIST_UPDATED }})'
90170
branch: update-vendor
91171
base: master
92172

93173
- name: Summary - Pull request created
94-
if: env.COUNT_UPDATED > 0
174+
if: env.COUNT_UPDATED > 0 && (env.HAS_BREAKING_CHANGES == 'True' || env.AUTO_MERGED == 'false')
95175
shell: pwsh
96176
run: |
97177
echo "### 🎉 Pull Request Created" >> $env:GITHUB_STEP_SUMMARY
@@ -102,4 +182,10 @@ jobs:
102182
echo "" >> $env:GITHUB_STEP_SUMMARY
103183
echo "**Updated dependencies:** $env:LIST_UPDATED" >> $env:GITHUB_STEP_SUMMARY
104184
echo "" >> $env:GITHUB_STEP_SUMMARY
105-
echo "> Please review and merge the pull request to apply the updates." >> $env:GITHUB_STEP_SUMMARY
185+
if ($env:HAS_BREAKING_CHANGES -eq 'True') {
186+
echo "> ⚠️ **Manual review required:** This update contains major version changes." >> $env:GITHUB_STEP_SUMMARY
187+
} else {
188+
echo "> ℹ️ **Note:** Auto-merge failed, manual review required." >> $env:GITHUB_STEP_SUMMARY
189+
}
190+
echo "" >> $env:GITHUB_STEP_SUMMARY
191+
echo "Please review and merge the pull request to apply the updates." >> $env:GITHUB_STEP_SUMMARY

scripts/update.ps1

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ function Fetch-DownloadUrl {
259259
}
260260

261261
$count = 0
262+
$hasBreakingChanges = $false
263+
$updateDetails = @()
262264

263265
# Read the current sources content
264266
$sources = Get-Content $sourcesPath | Out-String | ConvertFrom-Json
@@ -301,6 +303,35 @@ foreach ($s in $sources) {
301303
# }
302304

303305
$count++
306+
307+
# Analyze version change type
308+
$changeType = "unknown"
309+
try {
310+
# Try parsing as semantic version
311+
$oldVer = [System.Version]::Parse($s.version.Split('-')[0])
312+
$newVer = [System.Version]::Parse($version.Split('-')[0])
313+
314+
if ($newVer.Major -gt $oldVer.Major) {
315+
$changeType = "major"
316+
$hasBreakingChanges = $true
317+
} elseif ($newVer.Minor -gt $oldVer.Minor) {
318+
$changeType = "minor"
319+
} else {
320+
$changeType = "patch"
321+
}
322+
} catch {
323+
# If semantic versioning fails, treat as unknown (potentially breaking)
324+
$changeType = "unknown"
325+
$hasBreakingChanges = $true
326+
Write-Verbose "Could not parse version as semantic version, treating as potentially breaking"
327+
}
328+
329+
$updateDetails += @{
330+
name = $s.name
331+
oldVersion = $s.version
332+
newVersion = $version
333+
changeType = $changeType
334+
}
304335
}
305336

306337
$s.url = $downloadUrl
@@ -314,12 +345,16 @@ if ($count -eq 0) {
314345
return
315346
}
316347

317-
if ($Env:APPVEYOR -eq 'True') {
318-
Add-AppveyorMessage -Message "Successfully updated $count dependencies." -Category Information
319-
}
320-
348+
# Export update details for GitHub Actions
321349
if ($Env:GITHUB_ACTIONS -eq 'true') {
350+
$updateDetailsJson = $updateDetails | ConvertTo-Json -Compress
351+
Write-Output "UPDATE_DETAILS=$updateDetailsJson" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
352+
Write-Output "HAS_BREAKING_CHANGES=$hasBreakingChanges" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
322353
Write-Output "::notice title=Task Complete::Successfully updated $count dependencies."
323354
}
324355

356+
if ($Env:APPVEYOR -eq 'True') {
357+
Add-AppveyorMessage -Message "Successfully updated $count dependencies." -Category Information
358+
}
359+
325360
Write-Host -ForegroundColor green "Successfully updated $count dependencies."

0 commit comments

Comments
 (0)