-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Auto-merge non-breaking vendor updates with improved messaging #3059
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
base: master
Are you sure you want to change the base?
Changes from all commits
d61a4f7
be60888
4d21982
f2e8ae5
e64c0b1
bf90303
e6fea0b
fa2a34a
570b1d6
0f6584f
cd2c4ec
4911924
2cc1125
9cfff38
e598536
82f7fdd
1afbd4a
a475de2
400cdfe
10a0675
7b86263
d495b06
f2bde61
8c0e2c5
a6f0015
1e2d8eb
ae3ed77
2ebb4f2
d11c564
6924bcb
e4ab8fb
7fdae8e
59ef29c
426d9e6
d3df508
09b0075
58ab797
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ on: | |
| # At 13:37 UTC every day. | ||
| - cron: '37 13 * * *' | ||
|
|
||
| concurrency: | ||
| group: vendor-update | ||
| cancel-in-progress: false | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: pwsh | ||
|
|
@@ -45,64 +49,223 @@ jobs: | |
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| $currentVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json) | ||
| . .\scripts\update.ps1 -verbose | ||
| Set-GHVariable -Name COUNT_UPDATED -Value $count | ||
| $newVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json) | ||
| $listUpdated = "" | ||
| $updateMessage = "| Name | Old Version | New Version |`n| :--- | ---- | ---- |`n" | ||
| foreach ($s in $newVersion) { | ||
| $oldVersion = ($currentVersion | Where-Object {$_.name -eq $s.name}).version | ||
| if ($s.version -ne $oldVersion) { | ||
| $repoUrl = ($repoUrl = $s.Url.Replace("/archive/", "/releases/")).Substring(0, $repoUrl.IndexOf("/releases/")) + "/releases" | ||
| $listUpdated += "$($s.name) v$($s.version), " | ||
| $updateMessage += "| **[$($s.name)]($repoUrl)** | $oldVersion | **$($s.version)** |`n" | ||
| $currentVersion = (Get-Content -Raw .\vendor\sources.json | ConvertFrom-Json) | ||
| . .\scripts\update.ps1 -verbose | ||
|
|
||
| # Export count of updated packages (update.ps1 is expected to set $count) | ||
| if (-not ($count)) { $count = 0 } | ||
| 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 = @() | ||
| $singleDepName = "" | ||
| $singleDepOldVersion = "" | ||
| $singleDepNewVersion = "" | ||
| foreach ($s in $newVersion) { | ||
| $oldVersion = ($currentVersion | Where-Object {$_.name -eq $s.name}).version | ||
| if ($s.version -ne $oldVersion) { | ||
| $repoUrl = ($repoUrl = $s.Url.Replace("/archive/", "/releases/")).Substring(0, $repoUrl.IndexOf("/releases/")) + "/releases" | ||
|
|
||
| # Store single dependency info for messages (only if this is the only update) | ||
| if ($count -eq 1) { | ||
| $singleDepName = $s.name | ||
| $singleDepOldVersion = $oldVersion | ||
| $singleDepNewVersion = $s.version | ||
| } | ||
|
|
||
| # 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) { | ||
| $compareUrl = "$repoUrl/compare/v$oldVersion...v$($s.version)" | ||
| $majorUpdates += @{ | ||
| name = $s.name | ||
| oldVersion = $oldVersion | ||
| newVersion = $s.version | ||
| compareUrl = $compareUrl | ||
| repoUrl = $repoUrl | ||
| } | ||
| } | ||
|
|
||
| $listUpdated += "$($s.name) v$($s.version), " | ||
| $updateMessage += "| $emoji **[$($s.name)]($repoUrl)** | \`$oldVersion\` | **\`$($s.version)\`** |`n" | ||
| } | ||
| } | ||
|
|
||
| if ($count -eq 0) { return } | ||
|
|
||
| Set-GHVariable -Name LIST_UPDATED -Value $listUpdated.Trim(', ') | ||
| # Set single dependency variables (they will only be used if COUNT_UPDATED is 1) | ||
| # Use safe fallback values in case variables weren't set (shouldn't happen but prevents errors) | ||
| if ([string]::IsNullOrEmpty($singleDepName) -and $count -eq 1) { | ||
| # This shouldn't happen, but if it does, log a warning | ||
| Write-Warning "Single dependency name not set despite count being 1" | ||
| $singleDepName = "unknown-package" | ||
| $singleDepOldVersion = "unknown" | ||
| $singleDepNewVersion = "unknown" | ||
| } elseif ([string]::IsNullOrEmpty($singleDepName)) { | ||
| # For multiple dependencies, set placeholder values (won't be used) | ||
| $singleDepName = "" | ||
| $singleDepOldVersion = "" | ||
| $singleDepNewVersion = "" | ||
| } | ||
| } | ||
| if ($count -eq 0) { return } | ||
| Set-GHVariable -Name LIST_UPDATED -Value $listUpdated.Trim(', ') | ||
|
|
||
| echo "UPDATE_MESSAGE<<EOF`n$updateMessage`nEOF" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 | ||
| Set-GHVariable -Name SINGLE_DEP_NAME -Value $singleDepName | ||
| Set-GHVariable -Name SINGLE_DEP_OLD_VERSION -Value $singleDepOldVersion | ||
| Set-GHVariable -Name SINGLE_DEP_NEW_VERSION -Value $singleDepNewVersion | ||
|
|
||
| # Write multiline UPDATE_MESSAGE to GITHUB_ENV | ||
| ## echo "UPDATE_MESSAGE<<EOF`n$updateMessage`nEOF" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 | ||
| Add-Content -Path $env:GITHUB_ENV -Value "UPDATE_MESSAGE<<EOF" | ||
| Add-Content -Path $env:GITHUB_ENV -Value $updateMessage | ||
| Add-Content -Path $env:GITHUB_ENV -Value "EOF" | ||
|
|
||
| # Generate major updates changelog section and export | ||
| if ($majorUpdates.Count -gt 0) { | ||
| $changelogSection = "`n<details>`n<summary>π₯ Major version updates - View changelog</summary>`n`n" | ||
| foreach ($update in $majorUpdates) { | ||
| $changelogSection += "### [$($update.name)]($($update.repoUrl))`n" | ||
| $changelogSection += "**$($update.oldVersion)** β **$($update.newVersion)**`n`n" | ||
| $changelogSection += "- [View full changelog]($($update.compareUrl))`n" | ||
| $changelogSection += "- [Release notes]($($update.repoUrl)/tag/v$($update.newVersion))`n`n" | ||
| } | ||
| $changelogSection += "</details>`n" | ||
|
|
||
| Add-Content -Path $env:GITHUB_ENV -Value "CHANGELOG_SECTION<<EOF" | ||
| Add-Content -Path $env:GITHUB_ENV -Value $changelogSection | ||
| Add-Content -Path $env:GITHUB_ENV -Value "EOF" | ||
| Add-Content -Path $env:GITHUB_ENV -Value "HAS_BREAKING_CHANGES=True" | ||
| } else { | ||
| Add-Content -Path $env:GITHUB_ENV -Value "CHANGELOG_SECTION=" | ||
| Add-Content -Path $env:GITHUB_ENV -Value "HAS_BREAKING_CHANGES=False" | ||
| } | ||
|
|
||
| - name: Summary - Update check results | ||
| shell: pwsh | ||
| run: | | ||
| $count = [int]$env:COUNT_UPDATED | ||
|
|
||
| if ($count -eq 0) { | ||
| $summary = @" | ||
| ### β No Updates Available | ||
|
|
||
| All vendor dependencies are up to date. | ||
| All vendor dependencies are up to date! π | ||
| "@ | ||
| } else { | ||
| $word = if ($count -eq 1) { 'dependency' } else { 'dependencies' } | ||
| $summary = @" | ||
| ### π Updates Found | ||
|
|
||
| **$count** vendor $word updated: | ||
| "@ | ||
| $summary += 'π¦ **' + $env:SINGLE_DEP_NAME + '** updated from `' + $env:SINGLE_DEP_OLD_VERSION + '` to `' + $env:SINGLE_DEP_NEW_VERSION + '`' + "`n" + "`n" | ||
| $summary += 'π¦ **' + $count + '** vendor ' + $word + ' updated:' + "`n" + "`n" | ||
| } | ||
|
|
||
| $env:UPDATE_MESSAGE | ||
| $summary += $env:UPDATE_MESSAGE + "`n" | ||
|
|
||
| "@ | ||
| # Check if we can auto-merge (only minor/patch changes) | ||
| $hasBreaking = $env:HAS_BREAKING_CHANGES -eq 'True' | ||
| if ($hasBreaking) { | ||
| $summary += '> β οΈ **Note:** This update contains major version changes that may include breaking changes.' | ||
| } else { | ||
| $summary += '> βΉοΈ **Note:** This update only contains minor or patch changes.' | ||
| } | ||
|
|
||
| $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 | ||
|
|
||
| - name: Auto-merge minor updates | ||
| if: env.COUNT_UPDATED > 0 && env.HAS_BREAKING_CHANGES != 'True' | ||
|
DRSDavidSoft marked this conversation as resolved.
|
||
| shell: pwsh | ||
| run: | | ||
| try { | ||
| echo "### π Auto-merging Updates" >> $env:GITHUB_STEP_SUMMARY | ||
| echo "" >> $env:GITHUB_STEP_SUMMARY | ||
| echo "Attempting to automatically merge non-breaking changes to master..." >> $env:GITHUB_STEP_SUMMARY | ||
|
|
||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| # Commit the changes | ||
| git add vendor/sources.json | ||
| $commitResult = git commit -m "β¬οΈ Update dependencies ($env:LIST_UPDATED)" | ||
| $commitSuccess = $LASTEXITCODE -eq 0 | ||
|
|
||
| if ($commitSuccess) { | ||
| # Push directly to master | ||
| git push origin HEAD:master | ||
| $pushSuccess = $LASTEXITCODE -eq 0 | ||
|
|
||
| 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 | ||
| } 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 | ||
| echo "β οΈ **Warning:** Unable to automatically merge updates." >> $env:GITHUB_STEP_SUMMARY | ||
| echo "" >> $env:GITHUB_STEP_SUMMARY | ||
| echo "**Error:** $($_.Exception.Message)" >> $env:GITHUB_STEP_SUMMARY | ||
| echo "" >> $env:GITHUB_STEP_SUMMARY | ||
| echo "Falling back to creating a pull request..." >> $env:GITHUB_STEP_SUMMARY | ||
|
|
||
| Write-Warning "Failed to auto-merge: $($_.Exception.Message)" | ||
|
|
||
| # 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" | ||
| } | ||
| } | ||
|
Comment on lines
+221
to
+241
|
||
|
|
||
| # Set flag to create PR instead | ||
| echo "AUTO_MERGED=false" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 | ||
| } | ||
|
|
||
| - uses: peter-evans/create-pull-request@v8 | ||
| if: env.COUNT_UPDATED > 0 | ||
| if: fromJSON(env.COUNT_UPDATED) > 0 && (env.HAS_BREAKING_CHANGES == 'True' || env.AUTO_MERGED == 'false') | ||
| with: | ||
| title: 'Updates to `${{ env.COUNT_UPDATED }}` vendored dependencies' | ||
| title: ${{ env.COUNT_UPDATED == 1 && format('β¬οΈ Update {0}', env.LIST_UPDATED) || format('β¬οΈ Update {0} vendored dependencies', env.COUNT_UPDATED) }} | ||
| body: | | ||
| ### Automatically updated `${{ env.COUNT_UPDATED }}` dependencies: | ||
|
DRSDavidSoft marked this conversation as resolved.
|
||
| ### ${{ env.COUNT_UPDATED == 1 && format('π¦ Updated {0} from `{1}` to `{2}`', env.SINGLE_DEP_NAME, env.SINGLE_DEP_OLD_VERSION, env.SINGLE_DEP_NEW_VERSION) || format('π¦ Automatically updated `{0}` dependencies', env.COUNT_UPDATED) }} | ||
|
|
||
| ${{ env.UPDATE_MESSAGE }} | ||
|
|
||
| ${{ env.CHANGELOG_SECTION }} | ||
|
|
||
| --- | ||
| Please verify and then **Merge** the pull request to update. | ||
|
|
||
| ${{ env.HAS_BREAKING_CHANGES == 'True' && 'β οΈ **This update contains major version changes that may include breaking changes.**' || 'βΉοΈ This update only contains minor or patch changes.' }} | ||
|
|
||
| Please verify and then **Merge** the pull request to apply the updates. | ||
| commit-message: 'β¬οΈ Update dependencies (${{ env.LIST_UPDATED }})' | ||
| branch: update-vendor | ||
| base: master | ||
|
|
||
| - name: Summary - Pull request created | ||
| if: env.COUNT_UPDATED > 0 | ||
| if: env.COUNT_UPDATED > 0 && (env.HAS_BREAKING_CHANGES == 'True' || env.AUTO_MERGED == 'false') | ||
|
DRSDavidSoft marked this conversation as resolved.
|
||
| shell: pwsh | ||
| run: | | ||
| $summary = @" | ||
|
|
@@ -112,9 +275,19 @@ jobs: | |
|
|
||
| **Branch:** ``update-vendor`` | ||
|
|
||
| **Updated dependencies:** $env:LIST_UPDATED | ||
| $(if (-not [string]::IsNullOrEmpty($env:LIST_UPDATED)) { "**Updated dependencies:** $env:LIST_UPDATED" } else { "**Updated dependencies:** " }) | ||
|
|
||
| "@ | ||
|
|
||
| if ($env:HAS_BREAKING_CHANGES -eq 'True') { | ||
| $summary += "> β οΈ **Manual review required:** This update contains major version changes." | ||
| } else { | ||
| $summary += "> βΉοΈ **Note:** Auto-merge failed, manual review required." | ||
| } | ||
|
|
||
| $summary += @" | ||
| > Please review and merge the pull request to apply the updates. | ||
|
|
||
| "@ | ||
|
|
||
| $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 | ||
Uh oh!
There was an error while loading. Please reload this page.