Update Vendor #1390
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
| name: Update Vendor | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # At 13:37 UTC every day. | |
| - cron: '37 13 * * *' | |
| concurrency: | |
| group: vendor-update | |
| cancel-in-progress: false | |
| env: | |
| # Fork owners can opt in by setting this Actions repository variable to true. | |
| AUTO_MERGE_MINOR_VENDOR_UPDATES: ${{ vars.AUTO_MERGE_MINOR_VENDOR_UPDATES || 'false' }} | |
| defaults: | |
| run: | |
| shell: pwsh | |
| permissions: | |
| contents: read | |
| jobs: | |
| vendor: | |
| runs-on: windows-latest | |
| continue-on-error: false | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure auto-merge policy | |
| shell: pwsh | |
| run: | | |
| $rawValue = [string]$env:AUTO_MERGE_MINOR_VENDOR_UPDATES | |
| $normalizedValue = $rawValue.Trim().ToLowerInvariant() | |
| $enabled = $normalizedValue -in @('true', '1', 'yes', 'on') | |
| if ($enabled) { | |
| Add-Content -Path $env:GITHUB_ENV -Value "AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED=True" | |
| } else { | |
| Add-Content -Path $env:GITHUB_ENV -Value "AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED=False" | |
| } | |
| - name: Summary - Workflow started | |
| shell: pwsh | |
| run: | | |
| $summary = @" | |
| ## 📦 Update Vendor - Workflow Summary | |
| Checking for vendor dependency updates... | |
| "@ | |
| $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 | |
| - id: make-changes | |
| name: Checking for updates | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| $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 | |
| function Add-GitHubEnvMultiline { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string]$Name, | |
| [AllowEmptyString()] | |
| [string]$Value | |
| ) | |
| $delimiter = [System.Guid]::NewGuid().ToString('N') | |
| Add-Content -Path $env:GITHUB_ENV -Value "$Name<<$delimiter" | |
| Add-Content -Path $env:GITHUB_ENV -Value $Value | |
| Add-Content -Path $env:GITHUB_ENV -Value $delimiter | |
| } | |
| function Get-GitHubReleaseInfo { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string]$DownloadUrl, | |
| [Parameter(Mandatory = $true)] | |
| [string]$OldVersion, | |
| [Parameter(Mandatory = $true)] | |
| [string]$NewVersion | |
| ) | |
| $uri = [uri]$DownloadUrl | |
| $segments = $uri.AbsolutePath.Trim('/').Split('/') | |
| if ($uri.Host -ne 'github.com' -or $segments.Count -lt 2) { | |
| return $null | |
| } | |
| $owner = $segments[0] | |
| $repo = $segments[1] | |
| $repoPath = "$owner/$repo" | |
| $repoUrl = "https://github.com/$repoPath" | |
| $tagName = $null | |
| for ($i = 0; $i -lt $segments.Count; $i++) { | |
| if ($segments[$i] -eq 'download' -and $i + 1 -lt $segments.Count) { | |
| $tagName = $segments[$i + 1] | |
| break | |
| } | |
| if ($segments[$i] -eq 'archive' -and $i + 1 -lt $segments.Count) { | |
| $tagName = $segments[$i + 1] -replace '\.tar\.gz$', '' -replace '\.zip$', '' | |
| break | |
| } | |
| } | |
| if ([string]::IsNullOrWhiteSpace($tagName)) { | |
| $tagName = "v$NewVersion" | |
| } | |
| if ($tagName -match [regex]::Escape($NewVersion)) { | |
| $oldTagName = $tagName -replace [regex]::Escape($NewVersion), $OldVersion | |
| } else { | |
| $oldTagName = "v$OldVersion" | |
| } | |
| return @{ | |
| RepoPath = $repoPath | |
| RepoUrl = $repoUrl | |
| ReleasesUrl = "$repoUrl/releases" | |
| ReleaseUrl = "$repoUrl/releases/tag/$tagName" | |
| CompareUrl = "$repoUrl/compare/$oldTagName...$tagName" | |
| OldTagName = $oldTagName | |
| TagName = $tagName | |
| } | |
| } | |
| function Invoke-GitHubApi { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string]$Uri, | |
| [string]$Method = 'Get', | |
| [object]$Body | |
| ) | |
| $headers = @{ | |
| Accept = 'application/vnd.github+json' | |
| 'X-GitHub-Api-Version' = '2022-11-28' | |
| } | |
| if (-not [string]::IsNullOrWhiteSpace($env:GITHUB_TOKEN)) { | |
| $headers.Authorization = "Bearer $env:GITHUB_TOKEN" | |
| } | |
| $params = @{ | |
| Uri = $Uri | |
| Method = $Method | |
| Headers = $headers | |
| ErrorAction = 'Stop' | |
| } | |
| if ($null -ne $Body) { | |
| $params.Body = ($Body | ConvertTo-Json -Depth 8) | |
| $params.ContentType = 'application/json' | |
| } | |
| return Invoke-RestMethod @params | |
| } | |
| function Get-ReadmeBuildStatusBadge { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [string]$RepoPath | |
| ) | |
| try { | |
| $readme = Invoke-GitHubApi -Uri "https://api.github.com/repos/$RepoPath/readme" | |
| if ([string]::IsNullOrWhiteSpace($readme.content)) { | |
| return '—' | |
| } | |
| $bytes = [System.Convert]::FromBase64String(($readme.content -replace '\s', '')) | |
| $markdown = [System.Text.Encoding]::UTF8.GetString($bytes) | |
| $matches = [regex]::Matches($markdown, '\[!\[(?<alt>[^\]]*)\]\((?<image>[^)]*)\)\]\((?<target>[^)]*)\)') | |
| $bestBadge = $null | |
| $bestScore = 0 | |
| foreach ($match in $matches) { | |
| $alt = $match.Groups['alt'].Value | |
| $image = $match.Groups['image'].Value | |
| $target = $match.Groups['target'].Value | |
| $haystack = "$alt $image $target".ToLowerInvariant() | |
| $score = 0 | |
| if ($alt -match '(?i)\b(build|status|ci|check)\b') { | |
| $score += 8 | |
| } | |
| if ($image -match '(?i)(actions/workflows|/workflows/|dev\.azure\.com|badge\.svg)') { | |
| $score += 6 | |
| } | |
| if ($target -match '(?i)(/actions|actions/workflows|dev\.azure\.com|/_build/)') { | |
| $score += 4 | |
| } | |
| if ($haystack -match '(?i)(codecov|gitter|discord|covenant|visualstudiocode|open%20in)') { | |
| $score -= 8 | |
| } | |
| if ($score -gt $bestScore) { | |
| $bestScore = $score | |
| $bestBadge = $match.Value | |
| } | |
| } | |
| if ($bestScore -gt 0 -and -not [string]::IsNullOrWhiteSpace($bestBadge)) { | |
| return $bestBadge | |
| } | |
| } catch { | |
| Write-Verbose "Unable to fetch README build badge for ${RepoPath}: $($_.Exception.Message)" -Verbose | |
| } | |
| return '—' | |
| } | |
| function Get-ReleaseTitle { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [object]$Release | |
| ) | |
| if (-not [string]::IsNullOrWhiteSpace($Release.name)) { | |
| return $Release.name | |
| } | |
| return $Release.tag_name | |
| } | |
| function Get-ReleaseNotesForRange { | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [hashtable]$ReleaseInfo, | |
| [Parameter(Mandatory = $true)] | |
| [string]$ChangeType | |
| ) | |
| $typeLabel = switch ($ChangeType) { | |
| 'major' { 'Major changelog' } | |
| 'minor' { 'Minor changelog' } | |
| 'patch' { 'Patch changelog' } | |
| default { 'Release changelog' } | |
| } | |
| try { | |
| $releases = @(Invoke-GitHubApi -Uri "https://api.github.com/repos/$($ReleaseInfo.RepoPath)/releases?per_page=100") | |
| if ($releases.Count -gt 0) { | |
| $newIndex = -1 | |
| $oldIndex = -1 | |
| for ($i = 0; $i -lt $releases.Count; $i++) { | |
| if ($releases[$i].tag_name -eq $ReleaseInfo.TagName) { | |
| $newIndex = $i | |
| } | |
| if ($releases[$i].tag_name -eq $ReleaseInfo.OldTagName) { | |
| $oldIndex = $i | |
| } | |
| } | |
| if ($newIndex -ge 0) { | |
| if ($oldIndex -gt $newIndex) { | |
| $rangeReleases = @($releases[$newIndex..($oldIndex - 1)]) | |
| } else { | |
| $rangeReleases = @($releases[$newIndex]) | |
| } | |
| $maxReleaseCount = 8 | |
| $omittedReleaseCount = [Math]::Max(0, $rangeReleases.Count - $maxReleaseCount) | |
| $rangeReleases = @($rangeReleases | Select-Object -First $maxReleaseCount) | |
| $notes = "**$typeLabel**`n" | |
| foreach ($release in $rangeReleases) { | |
| $title = Get-ReleaseTitle -Release $release | |
| $releaseUrl = if (-not [string]::IsNullOrWhiteSpace($release.html_url)) { | |
| $release.html_url | |
| } else { | |
| "$($ReleaseInfo.RepoUrl)/releases/tag/$($release.tag_name)" | |
| } | |
| $notes += "`n### [$title]($releaseUrl)`n`n" | |
| if ([string]::IsNullOrWhiteSpace($release.body)) { | |
| $notes += "No release notes were published for this release.`n" | |
| } else { | |
| $releaseBody = $release.body.Trim() | |
| if ($releaseBody.Length -gt 1200) { | |
| $releaseBody = $releaseBody.Substring(0, 1200).TrimEnd() + "...`n`n_Release notes truncated; open the release link for the full text._" | |
| } | |
| $notes += $releaseBody + "`n" | |
| } | |
| } | |
| if ($omittedReleaseCount -gt 0) { | |
| $notes += "`n...and $omittedReleaseCount more releases. Open the compare link for the full range.`n" | |
| } | |
| return $notes.Trim() | |
| } | |
| } | |
| } catch { | |
| Write-Verbose "Unable to fetch release range notes for $($ReleaseInfo.RepoPath) $($ReleaseInfo.OldTagName)...$($ReleaseInfo.TagName): $($_.Exception.Message)" -Verbose | |
| } | |
| try { | |
| $release = Invoke-GitHubApi -Uri "https://api.github.com/repos/$($ReleaseInfo.RepoPath)/releases/tags/$($ReleaseInfo.TagName)" | |
| if (-not [string]::IsNullOrWhiteSpace($release.body)) { | |
| $title = Get-ReleaseTitle -Release $release | |
| return "**$typeLabel**`n`n### [$title]($($release.html_url))`n`n$($release.body.Trim())" | |
| } | |
| } catch { | |
| Write-Verbose "Unable to fetch release notes for $($ReleaseInfo.RepoPath) $($ReleaseInfo.TagName): $($_.Exception.Message)" -Verbose | |
| } | |
| return "No release notes were found for the requested release range." | |
| } | |
| function ConvertTo-BlockQuote { | |
| param( | |
| [AllowEmptyString()] | |
| [string]$Markdown, | |
| [int]$MaxLength = 2500 | |
| ) | |
| $text = if ([string]::IsNullOrWhiteSpace($Markdown)) { | |
| "No release notes were found." | |
| } else { | |
| $Markdown.Trim() | |
| } | |
| if ($text.Length -gt $MaxLength) { | |
| $text = $text.Substring(0, $MaxLength).TrimEnd() + "...`n`n_Release notes truncated; open the release links for the full text._" | |
| } | |
| return (($text -split "`r?`n") | ForEach-Object { "> $_" }) -join "`n" | |
| } | |
| function Get-VersionFromSources { | |
| param( | |
| [object[]]$Sources, | |
| [Parameter(Mandatory = $true)] | |
| [string]$Name | |
| ) | |
| return ($Sources | Where-Object { $_.name -eq $Name } | Select-Object -First 1).version | |
| } | |
| $previousPrVersion = $null | |
| $fetchPreviousPrBranchOutput = & git fetch origin update-vendor 2>&1 | |
| if ($LASTEXITCODE -eq 0) { | |
| $previousPrSourcesJson = & git show FETCH_HEAD:vendor/sources.json 2>$null | |
| if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrWhiteSpace($previousPrSourcesJson)) { | |
| $previousPrVersion = $previousPrSourcesJson | ConvertFrom-Json | |
| } | |
| } else { | |
| Write-Verbose "No existing update-vendor branch was found to use as notification baseline: $fetchPreviousPrBranchOutput" -Verbose | |
| } | |
| $notificationBaselineVersion = if ($null -ne $previousPrVersion) { $previousPrVersion } else { $currentVersion } | |
| $listUpdated = "" | |
| $updateMessage = "| Name | Old Version | New Version | Build Status |`n| :--- | :---: | :---: | :---: |`n" | |
| $changelogSection = "" | |
| $hasBreakingChanges = $false | |
| $hasMinorOrMajorSinceLastPrUpdate = $false | |
| $usedEmojis = [System.Collections.Generic.List[string]]::new() | |
| $emojiDescriptions = [ordered]@{ | |
| '🔥' = 'Major version update.' | |
| '🚀' = 'Minor version update.' | |
| '⬆️' = 'Patch version update.' | |
| '🔄' = 'Version change could not be classified.' | |
| } | |
| $singleDepName = "" | |
| $singleDepOldVersion = "" | |
| $singleDepNewVersion = "" | |
| foreach ($s in $newVersion) { | |
| $oldVersion = ($currentVersion | Where-Object {$_.name -eq $s.name}).version | |
| if ($s.version -ne $oldVersion) { | |
| $releaseInfo = Get-GitHubReleaseInfo -DownloadUrl $s.url -OldVersion $oldVersion -NewVersion $s.version | |
| if ($null -ne $releaseInfo) { | |
| $repoUrl = $releaseInfo.ReleasesUrl | |
| $releaseUrl = $releaseInfo.ReleaseUrl | |
| $statusBadge = Get-ReadmeBuildStatusBadge -RepoPath $releaseInfo.RepoPath | |
| } else { | |
| $repoUrl = ($repoUrl = $s.Url.Replace("/archive/", "/releases/")).Substring(0, $repoUrl.IndexOf("/releases/")) + "/releases" | |
| $releaseUrl = $repoUrl | |
| $statusBadge = "—" | |
| } | |
| # 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 | |
| if (-not $usedEmojis.Contains($emoji)) { | |
| $usedEmojis.Add($emoji) | |
| } | |
| if ($changeType -in @('major', 'downgrade', 'unknown')) { | |
| $hasBreakingChanges = $true | |
| } | |
| $previousPrUpdateVersion = Get-VersionFromSources -Sources $notificationBaselineVersion -Name $s.name | |
| if (-not [string]::IsNullOrWhiteSpace($previousPrUpdateVersion) -and $previousPrUpdateVersion -ne $s.version) { | |
| $notificationChangeType = Get-VersionChangeType -OldVersion $previousPrUpdateVersion -NewVersion $s.version | |
| if ($notificationChangeType.ChangeType -in @('major', 'minor')) { | |
| $hasMinorOrMajorSinceLastPrUpdate = $true | |
| } | |
| } | |
| if ($null -ne $releaseInfo) { | |
| $releaseNotes = Get-ReleaseNotesForRange -ReleaseInfo $releaseInfo -ChangeType $changeType | |
| $changelogSection += "<details>`n" | |
| $changelogSection += "<summary>$($s.name)</summary>`n`n" | |
| $changelogSection += "[Release notes]($($releaseInfo.ReleaseUrl)) · [Compare changes]($($releaseInfo.CompareUrl))`n`n" | |
| $changelogSection += (ConvertTo-BlockQuote -Markdown $releaseNotes -MaxLength 6000) + "`n`n" | |
| $changelogSection += "</details>`n`n" | |
| } | |
| $listUpdated += "$($s.name) v$($s.version), " | |
| $updateMessage += "| $emoji **[$($s.name)]($repoUrl)** | ``$oldVersion`` | **[``$($s.version)``]($releaseUrl)** | $statusBadge |`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 = "" | |
| } | |
| 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 | |
| $emojiLegend = "**Legend**`n`n" | |
| foreach ($usedEmoji in $usedEmojis) { | |
| $emojiLegend += "$usedEmoji $($emojiDescriptions[$usedEmoji])`n" | |
| } | |
| if ([string]::IsNullOrWhiteSpace($changelogSection)) { | |
| $changelogSection = "" | |
| } else { | |
| $changelogSection = "`n### Release notes for updated vendors`n`n$changelogSection" | |
| } | |
| $reviewTeam = "" | |
| if ($hasMinorOrMajorSinceLastPrUpdate -and $env:GITHUB_REPOSITORY_OWNER -eq 'cmderdev') { | |
| $reviewTeam = "trusted-contributors" | |
| } | |
| Add-GitHubEnvMultiline -Name UPDATE_MESSAGE -Value $updateMessage | |
| Add-GitHubEnvMultiline -Name CHANGELOG_SECTION -Value $changelogSection | |
| Add-GitHubEnvMultiline -Name EMOJI_LEGEND -Value $emojiLegend | |
| if ($hasBreakingChanges) { | |
| Add-Content -Path $env:GITHUB_ENV -Value "HAS_BREAKING_CHANGES=True" | |
| } else { | |
| Add-Content -Path $env:GITHUB_ENV -Value "HAS_BREAKING_CHANGES=False" | |
| } | |
| Add-Content -Path $env:GITHUB_ENV -Value "HAS_MINOR_OR_MAJOR_SINCE_LAST_PR_UPDATE=$hasMinorOrMajorSinceLastPrUpdate" | |
| Add-Content -Path $env:GITHUB_ENV -Value "REVIEW_TEAM=$reviewTeam" | |
| - name: Summary - Update check results | |
| shell: pwsh | |
| run: | | |
| $count = [int]$env:COUNT_UPDATED | |
| if ($count -eq 0) { | |
| $summary = "### ✅ No Updates Available`n`nAll vendor dependencies are up to date! 🎉`n" | |
| } else { | |
| $word = if ($count -eq 1) { 'dependency' } else { 'dependencies' } | |
| $summary = "### 🔄 Updates Found`n`n" | |
| if ($count -eq 1) { | |
| $summary += '📦 **' + $env:SINGLE_DEP_NAME + '** updated from `' + $env:SINGLE_DEP_OLD_VERSION + '` to `' + $env:SINGLE_DEP_NEW_VERSION + '`' + "`n" + "`n" | |
| } else { | |
| $summary += '📦 **' + $count + '** vendor ' + $word + ' updated:' + "`n" + "`n" | |
| } | |
| } | |
| $summary += $env:UPDATE_MESSAGE + "`n" | |
| # Check if we can auto-merge (only minor/patch changes, opt-in only). | |
| $hasBreaking = $env:HAS_BREAKING_CHANGES -eq 'True' | |
| $autoMergeEnabled = $env:AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED -eq 'True' | |
| if ($hasBreaking) { | |
| $summary += '> ⚠️ **Note:** This update contains major version changes that may include breaking changes.' | |
| } elseif ($autoMergeEnabled) { | |
| $summary += '> ℹ️ **Note:** This update only contains minor or patch changes, and auto-merge is enabled.' | |
| } else { | |
| $summary += '> ℹ️ **Note:** This update only contains minor or patch changes. Auto-merge is disabled by default; set the `AUTO_MERGE_MINOR_VENDOR_UPDATES` Actions repository variable to `true` to opt in.' | |
| } | |
| $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' && env.AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED == 'True' | |
| shell: pwsh | |
| run: | | |
| function Get-PushFailureReason { | |
| param( | |
| [string[]]$PushOutput | |
| ) | |
| $text = ($PushOutput -join "`n").Trim() | |
| if ([string]::IsNullOrWhiteSpace($text)) { | |
| return "Git rejected the push to `master`." | |
| } | |
| if ($text -match 'GH006: Protected branch' -or $text -match 'protected branch hook declined') { | |
| return "GitHub rejected the push because `master` is protected and direct pushes are blocked." | |
| } | |
| if ($text -match 'non-fast-forward|fetch first|failed to push some refs') { | |
| return "The remote branch moved ahead of the local commit, so the push was rejected as non-fast-forward." | |
| } | |
| if ($text -match 'not authorized|permission denied|write access') { | |
| return "The workflow token does not have permission to push to `master`." | |
| } | |
| return (($text -split "`r?`n" | Where-Object { $_ -match '^(remote:|! \[remote rejected\]|error:|To )' } | Select-Object -First 4) -join '; ') | |
| } | |
| 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 | |
| $pushOutput = & git push origin HEAD:master 2>&1 | |
| $pushSuccess = $LASTEXITCODE -eq 0 | |
| if (-not $pushSuccess) { | |
| $pushFailureReason = Get-PushFailureReason -PushOutput @($pushOutput) | |
| if (-not [string]::IsNullOrWhiteSpace($pushFailureReason)) { | |
| Add-Content -Path $env:GITHUB_ENV -Value "AUTO_MERGE_FAILURE_REASON=$pushFailureReason" | |
| } | |
| $pushErrorMessage = if ([string]::IsNullOrWhiteSpace($pushFailureReason)) { | |
| "Failed to push to master (exit code: $LASTEXITCODE)" | |
| } else { | |
| "Failed to push to master (exit code: $LASTEXITCODE): $pushFailureReason" | |
| } | |
| } | |
| 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 $pushErrorMessage | |
| } | |
| } 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)" | |
| # Set flag to create PR instead | |
| echo "AUTO_MERGED=false" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 | |
| $global:LASTEXITCODE = 0 | |
| exit 0 | |
| } | |
| - id: create-pr | |
| uses: peter-evans/create-pull-request@v8 | |
| if: fromJSON(env.COUNT_UPDATED) > 0 && env.AUTO_MERGED != 'true' | |
| with: | |
| title: ${{ env.COUNT_UPDATED == 1 && format('⬆️ Update {0}', env.LIST_UPDATED) || format('⬆️ Update {0} vendored dependencies', env.COUNT_UPDATED) }} | |
| body: | | |
| ### ${{ 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 }} | |
| --- | |
| ${{ env.EMOJI_LEGEND }} | |
| ${{ env.HAS_BREAKING_CHANGES == 'True' && '**Review note:** This update contains version changes that may require manual review.' || '**Review note:** 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 | |
| labels: | | |
| 👆 Dependencies | |
| 🗃️ Vendor | |
| team-reviewers: ${{ env.REVIEW_TEAM }} | |
| - name: Summary - Pull request result | |
| if: env.COUNT_UPDATED > 0 && env.AUTO_MERGED != 'true' | |
| shell: pwsh | |
| env: | |
| PR_URL: ${{ steps.create-pr.outputs.pull-request-url }} | |
| PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }} | |
| PR_OPERATION: ${{ steps.create-pr.outputs.pull-request-operation }} | |
| AUTO_MERGE_FAILURE_REASON: ${{ env.AUTO_MERGE_FAILURE_REASON }} | |
| AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED: ${{ env.AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED }} | |
| run: | | |
| $updateVendorBranchUrl = "$($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/update-vendor" | |
| $summary = @" | |
| ### 🎉 Pull Request Result | |
| **Branch:** [``update-vendor``]($updateVendorBranchUrl) | |
| $(if (-not [string]::IsNullOrEmpty($env:LIST_UPDATED)) { "**Updated dependencies:** $env:LIST_UPDATED" } else { "**Updated dependencies:** " }) | |
| "@ | |
| switch ($env:PR_OPERATION) { | |
| 'created' { | |
| $summary += "A new pull request has been created: [#$($env:PR_NUMBER)]($($env:PR_URL))`n`n" | |
| } | |
| 'updated' { | |
| $summary += "An existing pull request has been updated: [#$($env:PR_NUMBER)]($($env:PR_URL))`n`n" | |
| } | |
| 'none' { | |
| $summary += "No pull request was created because [update-vendor]($updateVendorBranchUrl) no longer differs from ``master``.`n`n" | |
| } | |
| default { | |
| if (-not [string]::IsNullOrWhiteSpace($env:PR_URL)) { | |
| $summary += "A pull request was reported, but the operation type was not recognized: [#$($env:PR_NUMBER)]($($env:PR_URL))`n`n" | |
| } else { | |
| $summary += "A pull request was requested, but no PR link was returned.`n`n" | |
| } | |
| } | |
| } | |
| if (-not [string]::IsNullOrWhiteSpace($env:AUTO_MERGE_FAILURE_REASON)) { | |
| $summary += "> ⚠️ **Auto-merge failure:** $env:AUTO_MERGE_FAILURE_REASON`n`n" | |
| } | |
| if ($env:HAS_BREAKING_CHANGES -eq 'True') { | |
| $summary += "> ⚠️ **Manual review required:** This update contains major version changes." | |
| } elseif ($env:PR_OPERATION -eq 'none') { | |
| $summary += "> ℹ️ **Note:** No pull request was created because there were no differences left to propose." | |
| } elseif ($env:AUTO_MERGE_MINOR_VENDOR_UPDATES_ENABLED -ne 'True') { | |
| $summary += "> ℹ️ **Note:** Auto-merge is disabled by configuration. Set the ``AUTO_MERGE_MINOR_VENDOR_UPDATES`` Actions repository variable to ``true`` to opt in." | |
| } else { | |
| $summary += "> ℹ️ **Note:** Auto-merge failed, manual review required." | |
| } | |
| $summary += "`n> Please review and merge the pull request to apply the updates.`n`n" | |
| $summary | Add-Content -Path $env:GITHUB_STEP_SUMMARY -Encoding utf8 |