-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Automate filing issues for any external package dependency #19076
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
Merged
praveenkuttappan
merged 21 commits into
Azure:main
from
praveenkuttappan:automate_dependency_upgrade
Dec 13, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
16fd7b2
Automate filing issues for any external package dependency and deprec…
praveenkuttappan 769babf
Revert temporary config changes
praveenkuttappan 6ae09ff
Additional fixes
praveenkuttappan e4548b3
Additional change as per review suggestion
praveenkuttappan 531599b
Fix pipeline errors
praveenkuttappan 8580f6b
Fix pipeline errors
praveenkuttappan 442612a
Update path to script
praveenkuttappan e99416a
Update path to script
praveenkuttappan bf21a41
Logging changes
praveenkuttappan 5cbb21f
Logging changes
praveenkuttappan 1c97629
pipeline changs
praveenkuttappan 5698d56
Update script to avoid create out file
praveenkuttappan 1f80c09
Update script to avoid create out file
praveenkuttappan e5db6dd
Update script to avoid create out file
praveenkuttappan 256682a
Update script to avoid create out file
praveenkuttappan cbc10fb
Update script to avoid create out file
praveenkuttappan b856986
Script changes
praveenkuttappan 5ea84a9
Script changes
praveenkuttappan 7070b3a
Script changes
praveenkuttappan 950192c
Additional changes
praveenkuttappan 2dee74e
Revert temp changes
praveenkuttappan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| [CmdletBinding(SupportsShouldProcess = $true)] | ||
| param ( | ||
| [Parameter(Mandatory = $true)] | ||
| [string]$AuthToken, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$RepoOwner, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [string]$RepoName | ||
| ) | ||
|
|
||
| # This script will reset the repo and any changes in tracked files will be lost. | ||
|
|
||
| $dependencyUpgradeLabel = "dependency-upgrade-required" | ||
| $dependencyRegex = "^\+\s(?<pkg>[\S]*)\s(?<version>[\S]*)\s\((?<newVersion>[0-9\.a-b]*).*\)\s?(?<deprecated>deprecated)?" | ||
| $RepoRoot = Resolve-Path -Path "${PSScriptRoot}/../.." | ||
| Write-Host "Repo root: $RepoRoot" | ||
| $rushFile = join-Path -Path $RepoRoot "rush.json" | ||
| Write-Host "Path to rush.json: $rushFile" | ||
| $commonConfigFile = Join-path -Path $RepoRoot "common" "config" "rush" "common-versions.json" | ||
| Write-Host "Path to common-versions.json: $commonConfigFile" | ||
|
|
||
| $EngCommonScriptsPath = Join-Path (Resolve-Path "${PSScriptRoot}/..") "common" "scripts" | ||
| . (Join-Path $EngCommonScriptsPath common.ps1) | ||
|
|
||
| $ghIssues = Get-GitHubIssues -RepoOwner $RepoOwner -RepoName $RepoName -CreatedBy "azure-sdk" -Labels "dependency-upgrade-required" -AuthToken $AuthToken | ||
| # Check and return if an isue already exists to upgrade the package | ||
| function Get-GithubIssue($IssueTitle) { | ||
| foreach ($issue in $ghIssues) { | ||
| if ($issue.title -eq $IssueTitle) { | ||
| return $issue | ||
| } | ||
| } | ||
| return $null | ||
| } | ||
|
|
||
| # Create new issue if none exists for the package. or update current one if an issue exists | ||
| function Set-GitHubIssue($Package) { | ||
| $pkgName = $Package.Name | ||
| $issueTitle = "Dependency package $pkgName has a new version available" | ||
| $issueDesc = "We have identified a dependency on $pkgName ($($Package.OldVersion)). " | ||
|
|
||
| if ($Package.IsDeprecated) { | ||
| $issueDesc += "Version $($Package.OldVersion) of $pkgName has been deprecated.`n" | ||
| } | ||
| $issueDesc += "A new version ($($Package.NewVersion)) is available now." | ||
|
|
||
| $issue = Get-GithubIssue -IssueTitle $issueTitle | ||
| if ($issue) { | ||
| if ($issue.body -ne $issueDesc) { | ||
| $oldIssue = Update-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -AuthToken $AuthToken -IssueNumber $issue.number -Body $issueDesc | ||
| Write-Host "Updated existing issue $($oldIssue.number)" | ||
| } | ||
| else { | ||
| Write-Host "Found existing issue for package $($Package.Name)" | ||
| } | ||
| } | ||
| else { | ||
| write-Host "Creating issue for $pkgName" | ||
| $newIssue = New-GitHubIssue -RepoOwner $RepoOwner -RepoName $RepoName -AuthToken $AuthToken -Title $issueTitle -Description $issueDesc | ||
| if ($newIssue) { | ||
| $out = Add-GitHubIssueLabels -RepoOwner $RepoOwner -RepoName $RepoName -AuthToken $AuthToken -Labels $dependencyUpgradeLabel -IssueNumber $newIssue.number | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| # Update rush configuration files to alter settings | ||
| if ((Test-Path $rushFile) -and (Test-Path $commonConfigFile)) { | ||
| $rushJson = Get-Content -Path $rushFile | ConvertFrom-Json | ||
| $rushJson.pnpmOptions.strictPeerDependencies = $false | ||
| Set-Content -Path $rushFile -Value (ConvertTo-Json -InputObject $rushJson) | ||
|
|
||
| $configJson = Get-Content -Path $commonConfigFile | ConvertFrom-Json | ||
| $configJson.implicitlyPreferredVersions = $true | ||
| Set-Content -Path $commonConfigFile -Value (ConvertTo-Json -InputObject $configJson) | ||
| } | ||
| else { | ||
| Write-Error "Failed to find $($rushFile) and/or $($commonConfigFile). Verify repo root parameter." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Run rush update --full | ||
| Write-Host "Running rush update" | ||
| $rushUpdateOutput = node common/scripts/install-run-rush.js update --full | ||
| write-host $rushUpdateOutput | ||
| foreach ($line in $rushUpdateOutput) { | ||
| if ($line -match $dependencyRegex -and !$matches['pkg'].StartsWith("@azure")) { | ||
| $p = New-Object PSObject -Property @{ | ||
| Name = $matches['pkg'] | ||
| OldVersion = [AzureEngSemanticVersion]::ParseVersionString($matches['version']) | ||
| NewVersion = [AzureEngSemanticVersion]::ParseVersionString($matches['newVersion']) | ||
| IsDeprecated = ($matches['deprecated'] -eq "deprecated") | ||
| } | ||
|
|
||
| if ($null -ne $p.OldVersion -and $null -ne $p.NewVersion) { | ||
| Set-GitHubIssue -Package $p | ||
| Start-Sleep -s 5 | ||
| } | ||
| } | ||
| } | ||
| Write-Host "Verified and filed issues" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.