-
Notifications
You must be signed in to change notification settings - Fork 254
Add legacy moniker migration logic #6895
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,122 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Move metadata JSON and package-level overview markdown files for deprecated packages to the legacy folder. | ||
|
|
||
| .DESCRIPTION | ||
| Move onboarding information to the "legacy" moniker for whose support is "deprecated" in the Metadata CSV. | ||
| Only one version of a package can be documented in the "legacy" moniker. If multiple versions are available, | ||
| the "latest" version will be used and the "preview" version will be deleted. | ||
|
|
||
| .PARAMETER DocRepoLocation | ||
| The location of the target docs repository. | ||
| #> | ||
|
|
||
| param( | ||
| [Parameter(Mandatory = $true)] | ||
| [string] $DocRepoLocation | ||
| ) | ||
|
|
||
| . (Join-Path $PSScriptRoot common.ps1) | ||
|
|
||
| Set-StrictMode -Version 3 | ||
|
|
||
| function getPackageMetadata($moniker) { | ||
| $jsonFiles = Get-ChildItem -Path (Join-Path $DocRepoLocation "metadata/$moniker") -Filter *.json | ||
| $metadata = @{} | ||
|
|
||
| foreach ($jsonFile in $jsonFiles) { | ||
| $packageMetadata = Get-Content $jsonFile -Raw | ConvertFrom-Json -AsHashtable | ||
| $packageIdentity = $packageMetadata.Name | ||
| if (Test-Path "Function:$GetPackageIdentity") { | ||
| $packageIdentity = &$GetPackageIdentity $packageMetadata | ||
| } | ||
|
|
||
| $metadata[$packageIdentity] = @{ File = $jsonFile; Metadata = $packageMetadata } | ||
| } | ||
|
|
||
| return $metadata | ||
| } | ||
|
|
||
| function getPackageInfoFromLookup($packageIdentity, $version, $lookupTable) { | ||
| if ($lookupTable.ContainsKey($packageIdentity)) { | ||
| if ($lookupTable[$packageIdentity]['Metadata'].Version -eq $version) { | ||
| # Only return if the version matches | ||
| return $lookupTable[$packageIdentity] | ||
| } | ||
| } | ||
|
|
||
| return $null | ||
| } | ||
|
|
||
| function moveToLegacy($packageInfo) { | ||
| $docsMsMetadata = &$GetDocsMsMetadataForPackageFn -PackageInfo $packageInfo['Metadata'] | ||
|
|
||
| Write-Host "Move to legacy: $($packageInfo['Metadata'].Name)" | ||
| $packageInfoPath = $packageInfo['File'] | ||
| Move-Item "$($packageInfoPath.Directory)/$($packageInfoPath.BaseName).*" "$DocRepoLocation/metadata/legacy/" -Force | ||
|
|
||
| $readmePath = "$DocRepoLocation/$($docsMsMetadata.PreviewReadMeLocation)/$($docsMsMetadata.DocsMsReadMeName)-readme.md" | ||
| if (Test-Path $readmePath) { | ||
| Move-Item ` | ||
| $readmePath ` | ||
| "$DocRepoLocation/$($docsMsMetadata.LegacyReadMeLocation)/" ` | ||
| -Force | ||
| } | ||
| } | ||
|
|
||
| function deletePackageInfo($packageInfo) { | ||
| $docsMsMetadata = &$GetDocsMsMetadataForPackageFn -PackageInfo $packageInfo['Metadata'] | ||
|
|
||
| Write-Host "Delete superseded package: $($packageInfo['Metadata'].Name)" | ||
| $packageInfoPath = $packageInfo['File'] | ||
| Remove-Item "$($packageInfoPath.Directory)/$($packageInfoPath.BaseName).*" -Force | ||
|
|
||
| $readmePath = "$DocRepoLocation/$($docsMsMetadata.PreviewReadMeLocation)/$($docsMsMetadata.DocsMsReadMeName)-readme.md" | ||
| if (Test-Path $readmePath) { | ||
| Remove-Item $readmePath -Force | ||
| } | ||
| } | ||
|
|
||
| $metadataLookup = @{ | ||
| 'latest' = getPackageMetadata 'latest' | ||
| 'preview' = getPackageMetadata 'preview' | ||
| } | ||
| $deprecatedPackages = (Get-CSVMetadata).Where({ $_.Support -eq 'deprecated' }) | ||
|
|
||
| foreach ($package in $deprecatedPackages) { | ||
| $packageIdentity = $package.Package | ||
| if (Test-Path "Function:$GetPackageIdentityFromCsvMetadata") { | ||
| $packageIdentity = &$GetPackageIdentityFromCsvMetadata $package | ||
| } | ||
|
|
||
| $packageInfoPreview = $packageInfoLatest = $null | ||
| if ($package.VersionPreview) { | ||
| $packageInfoPreview = getPackageInfoFromLookup ` | ||
| -packageIdentity $packageIdentity ` | ||
| -version $package.VersionPreview ` | ||
| -lookupTable $metadataLookup['preview'] | ||
| } | ||
|
|
||
| if ($package.VersionGA) { | ||
| $packageInfoLatest = getPackageInfoFromLookup ` | ||
| -packageIdentity $packageIdentity ` | ||
| -version $package.VersionGA ` | ||
| -lookupTable $metadataLookup['latest'] | ||
| } | ||
|
|
||
| if (!$packageInfoPreview -and !$packageInfoLatest) { | ||
| # Nothing to move or delete | ||
| continue | ||
| } | ||
|
|
||
| if ($packageInfoPreview -and $packageInfoLatest) { | ||
| # Delete metadata JSON and package-level overview markdown files for | ||
| # the preview version instead of moving both. This mitigates situations | ||
| # where the "latest" verison doesn't have a package-level overview | ||
| # markdown file and the "preview" version does. | ||
| deletePackageInfo $packageInfoPreview | ||
| moveToLegacy $packageInfoLatest | ||
| } else { | ||
| moveToLegacy ($packageInfoPreview ?? $packageInfoLatest) | ||
| } | ||
| } | ||
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
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.