From 00ed49219eec41f94f60ab8bba9d8c54ed0b4921 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Wed, 11 Nov 2020 17:54:31 -0800 Subject: [PATCH 1/3] Refactoring artifact-metadata-parsing.ps1, update-docs-metadata.ps1, and create-tags-and-git-release.ps1 --- .../scripts/artifact-metadata-parsing.ps1 | 390 +----------------- .../scripts/create-tags-and-git-release.ps1 | 4 +- eng/common/scripts/update-docs-metadata.ps1 | 42 +- 3 files changed, 28 insertions(+), 408 deletions(-) diff --git a/eng/common/scripts/artifact-metadata-parsing.ps1 b/eng/common/scripts/artifact-metadata-parsing.ps1 index b2ca199d455e..8f2117ecc74a 100644 --- a/eng/common/scripts/artifact-metadata-parsing.ps1 +++ b/eng/common/scripts/artifact-metadata-parsing.ps1 @@ -1,5 +1,4 @@ -Import-Module "${PSScriptRoot}/modules/ChangeLog-Operations.psm1" -. (Join-Path $PSScriptRoot SemVer.ps1) +. (Join-Path $PSScriptRoot common.ps1) $SDIST_PACKAGE_REGEX = "^(?.*)\-(?$([AzureEngSemanticVersion]::SEMVER_REGEX))" @@ -40,336 +39,6 @@ function CreateReleases($pkgList, $releaseApiUrl, $releaseSha) { } } -# Parse out package publishing information given a maven POM file -function ParseMavenPackage($pkg, $workingDirectory) { - [xml]$contentXML = Get-Content $pkg - - $pkgId = $contentXML.project.artifactId - $pkgVersion = $contentXML.project.version - $groupId = if ($contentXML.project.groupId -eq $null) { $contentXML.project.parent.groupId } else { $contentXML.project.groupId } - $releaseNotes = "" - $readmeContent = "" - - # if it's a snapshot. return $null (as we don't want to create tags for this, but we also don't want to fail) - if ($pkgVersion.Contains("SNAPSHOT")) { - return $null - } - - $changeLogLoc = @(Get-ChildItem -Path $pkg.DirectoryName -Recurse -Include "$($pkg.Basename)-changelog.md")[0] - if ($changeLogLoc) { - $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion - } - - $readmeContentLoc = @(Get-ChildItem -Path $pkg.DirectoryName -Recurse -Include "$($pkg.Basename)-readme.md")[0] - if ($readmeContentLoc) { - $readmeContent = Get-Content -Raw $readmeContentLoc - } - - return New-Object PSObject -Property @{ - PackageId = $pkgId - GroupId = $groupId - PackageVersion = $pkgVersion - ReleaseTag = "$($pkgId)_$($pkgVersion)" - Deployable = $forceCreate -or !(IsMavenPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion -groupId $groupId.Replace(".", "/")) - ReleaseNotes = $releaseNotes - ReadmeContent = $readmeContent - } -} - -# Returns the maven (really sonatype) publish status of a package id and version. -function IsMavenPackageVersionPublished($pkgId, $pkgVersion, $groupId) { - try { - - $uri = "https://oss.sonatype.org/content/repositories/releases/$groupId/$pkgId/$pkgVersion/$pkgId-$pkgVersion.pom" - $pomContent = Invoke-RestMethod -MaximumRetryCount 3 -RetryIntervalSec 10 -Method "GET" -uri $uri - - if ($pomContent -ne $null -or $pomContent.Length -eq 0) { - return $true - } - else { - return $false - } - } - catch { - $statusCode = $_.Exception.Response.StatusCode.value__ - $statusDescription = $_.Exception.Response.StatusDescription - - # if this is 404ing, then this pkg has never been published before - if ($statusCode -eq 404) { - return $false - } - - Write-Host "VersionCheck to maven for packageId $pkgId failed with statuscode $statusCode" - Write-Host $statusDescription - exit(1) - } -} - -# make certain to always take the package json closest to the top -function ResolvePkgJson($workFolder) { - $pathsWithComplexity = @() - foreach ($file in (Get-ChildItem -Path $workFolder -Recurse -Include "package.json")) { - $complexity = ($file.FullName -Split { $_ -eq "/" -or $_ -eq "\" }).Length - $pathsWithComplexity += New-Object PSObject -Property @{ - Path = $file - Complexity = $complexity - } - } - - return ($pathsWithComplexity | Sort-Object -Property Complexity)[0].Path -} - -# Parse out package publishing information given a .tgz npm artifact -function ParseNPMPackage($pkg, $workingDirectory) { - $workFolder = "$workingDirectory$($pkg.Basename)" - $origFolder = Get-Location - $releaseNotes = "" - $readmeContent = "" - - New-Item -ItemType Directory -Force -Path $workFolder - cd $workFolder - - tar -xzf $pkg - - $packageJSON = ResolvePkgJson -workFolder $workFolder | Get-Content | ConvertFrom-Json - $pkgId = $packageJSON.name - $pkgVersion = $packageJSON.version - - $changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0] - if ($changeLogLoc) { - $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion - } - - $readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md") | Select-Object -Last 1 - if ($readmeContentLoc) { - $readmeContent = Get-Content -Raw $readmeContentLoc - } - - cd $origFolder - Remove-Item $workFolder -Force -Recurse -ErrorAction SilentlyContinue - - $resultObj = New-Object PSObject -Property @{ - PackageId = $pkgId - PackageVersion = $pkgVersion - ReleaseTag = "$($pkgId)_$($pkgVersion)" - Deployable = $forceCreate -or !(IsNPMPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion) - ReleaseNotes = $releaseNotes - ReadmeContent = $readmeContent - } - - return $resultObj -} - -# Returns the npm publish status of a package id and version. -function IsNPMPackageVersionPublished($pkgId, $pkgVersion) { - $npmVersions = (npm show $pkgId versions) - - if ($LastExitCode -ne 0) { - npm ping - - if ($LastExitCode -eq 0) { - return $False - } - - Write-Host "Could not find a deployed version of $pkgId, and NPM connectivity check failed." - exit(1) - } - - $npmVersionList = $npmVersions.split(",") | % { return $_.replace("[", "").replace("]", "").Trim() } - return $npmVersionList.Contains($pkgVersion) -} - -# Parse out package publishing information given a nupkg ZIP format. -function ParseNugetPackage($pkg, $workingDirectory) { - $workFolder = "$workingDirectory$($pkg.Basename)" - $origFolder = Get-Location - $zipFileLocation = "$workFolder/$($pkg.Basename).zip" - $releaseNotes = "" - $readmeContent = "" - - New-Item -ItemType Directory -Force -Path $workFolder - - Copy-Item -Path $pkg -Destination $zipFileLocation - Expand-Archive -Path $zipFileLocation -DestinationPath $workFolder - [xml] $packageXML = Get-ChildItem -Path "$workFolder/*.nuspec" | Get-Content - $pkgId = $packageXML.package.metadata.id - $pkgVersion = $packageXML.package.metadata.version - - $changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0] - if ($changeLogLoc) { - $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion - } - - $readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md")[0] - if ($readmeContentLoc) { - $readmeContent = Get-Content -Raw $readmeContentLoc - } - - Remove-Item $workFolder -Force -Recurse -ErrorAction SilentlyContinue - - return New-Object PSObject -Property @{ - PackageId = $pkgId - PackageVersion = $pkgVersion - ReleaseTag = "$($pkgId)_$($pkgVersion)" - Deployable = $forceCreate -or !(IsNugetPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion) - ReleaseNotes = $releaseNotes - ReadmeContent = $readmeContent - } -} - -# Returns the nuget publish status of a package id and version. -function IsNugetPackageVersionPublished($pkgId, $pkgVersion) { - - $nugetUri = "https://api.nuget.org/v3-flatcontainer/$($pkgId.ToLowerInvariant())/index.json" - - try { - $nugetVersions = Invoke-RestMethod -MaximumRetryCount 3 -RetryIntervalSec 10 -uri $nugetUri -Method "GET" - - return $nugetVersions.versions.Contains($pkgVersion) - } - catch { - $statusCode = $_.Exception.Response.StatusCode.value__ - $statusDescription = $_.Exception.Response.StatusDescription - - # if this is 404ing, then this pkg has never been published before - if ($statusCode -eq 404) { - return $False - } - - Write-Host "Nuget Invocation failed:" - Write-Host "StatusCode:" $statusCode - Write-Host "StatusDescription:" $statusDescription - exit(1) - } - -} - -# Parse out package publishing information given a python sdist of ZIP format. -function ParsePyPIPackage($pkg, $workingDirectory) { - $pkg.Basename -match $SDIST_PACKAGE_REGEX | Out-Null - - $pkgId = $matches["package"] - $pkgVersion = $matches["versionstring"] - - $workFolder = "$workingDirectory$($pkg.Basename)" - $origFolder = Get-Location - $releaseNotes = "" - $readmeContent = "" - - New-Item -ItemType Directory -Force -Path $workFolder - Expand-Archive -Path $pkg -DestinationPath $workFolder - - $changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0] - if ($changeLogLoc) { - $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion - } - - $readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md") | Select-Object -Last 1 - - if ($readmeContentLoc) { - $readmeContent = Get-Content -Raw $readmeContentLoc - } - - Remove-Item $workFolder -Force -Recurse -ErrorAction SilentlyContinue - - return New-Object PSObject -Property @{ - PackageId = $pkgId - PackageVersion = $pkgVersion - ReleaseTag = "$($pkgId)_$($pkgVersion)" - Deployable = $forceCreate -or !(IsPythonPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion) - ReleaseNotes = $releaseNotes - ReadmeContent = $readmeContent - } -} - -function ParseCArtifact($pkg, $workingDirectory) { - $packageInfo = Get-Content -Raw -Path $pkg | ConvertFrom-JSON - $packageArtifactLocation = (Get-ItemProperty $pkg).Directory.FullName - $releaseNotes = "" - $readmeContent = "" - - $pkgVersion = $packageInfo.version - - $changeLogLoc = @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "CHANGELOG.md")[0] - if ($changeLogLoc) - { - $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion - } - - $readmeContentLoc = @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "README.md")[0] - if ($readmeContentLoc) { - $readmeContent = Get-Content -Raw $readmeContentLoc - } - - return New-Object PSObject -Property @{ - PackageId = '' - PackageVersion = $pkgVersion - ReleaseTag = $pkgVersion - # Artifact info is always considered deployable for C becasue it is not - # deployed anywhere. Dealing with duplicate tags happens downstream in - # CheckArtifactShaAgainstTagsList - Deployable = $true - ReleaseNotes = $releaseNotes - } -} - -function ParseCppArtifact($pkg, $workingDirectory) { - $packageInfo = Get-Content -Raw -Path $pkg | ConvertFrom-JSON - $packageArtifactLocation = (Get-ItemProperty $pkg).Directory.FullName - $releaseNotes = "" - $readmeContent = "" - - $pkgVersion = $packageInfo.version - $pkgName = $packageInfo.name - - $changeLogLoc = @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "CHANGELOG.md")[0] - if ($changeLogLoc) - { - $releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion - } - - $readmeContentLoc = @(Get-ChildItem -Path $packageArtifactLocation -Recurse -Include "README.md")[0] - if ($readmeContentLoc) { - $readmeContent = Get-Content -Raw $readmeContentLoc - } - - return New-Object PSObject -Property @{ - PackageId = $pkgName - PackageVersion = $pkgVersion - ReleaseTag = "${pkgName}_${pkgVersion}" - # Artifact info is always considered deployable for now becasue it is not - # deployed anywhere. Dealing with duplicate tags happens downstream in - # CheckArtifactShaAgainstTagsList - Deployable = $true - ReleaseNotes = $releaseNotes - } -} - - -# Returns the pypi publish status of a package id and version. -function IsPythonPackageVersionPublished($pkgId, $pkgVersion) { - try { - $existingVersion = (Invoke-RestMethod -MaximumRetryCount 3 -RetryIntervalSec 10 -Method "Get" -uri "https://pypi.org/pypi/$pkgId/$pkgVersion/json").info.version - - # if existingVersion exists, then it's already been published - return $True - } - catch { - $statusCode = $_.Exception.Response.StatusCode.value__ - $statusDescription = $_.Exception.Response.StatusDescription - - # if this is 404ing, then this pkg has never been published before - if ($statusCode -eq 404) { - return $False - } - - Write-Host "PyPI Invocation failed:" - Write-Host "StatusCode:" $statusCode - Write-Host "StatusDescription:" $statusDescription - exit(1) - } -} - # Retrieves the list of all tags that exist on the target repository function GetExistingTags($apiUrl) { try { @@ -394,12 +63,12 @@ function GetExistingTags($apiUrl) { } # Retrieve release tag for artiface package. If multiple packages, then output the first one. -function RetrieveReleaseTag($pkgRepository, $artifactLocation, $continueOnError = $true) { +function RetrieveReleaseTag($artifactLocation, $continueOnError = $true) { if (!$artifactLocation) { return "" } try { - $pkgs, $parsePkgInfoFn = RetrievePackages -pkgRepository $pkgRepository -artifactLocation $artifactLocation + $pkgs, $parsePkgInfoFn = RetrievePackages -artifactLocation $artifactLocation if (!$pkgs -or !$pkgs[0]) { Write-Host "No packages retrieved from artifact location." return "" @@ -421,52 +90,23 @@ function RetrieveReleaseTag($pkgRepository, $artifactLocation, $continueOnError Write-Error "No release tag retrieved from $artifactLocation" } } -function RetrievePackages($pkgRepository, $artifactLocation) { - $parsePkgInfoFn = "" - $packagePattern = "" - $pkgRepository = $pkgRepository.Trim() - switch ($pkgRepository) { - "Maven" { - $parsePkgInfoFn = "ParseMavenPackage" - $packagePattern = "*.pom" - break - } - "Nuget" { - $parsePkgInfoFn = "ParseNugetPackage" - $packagePattern = "*.nupkg" - break - } - "NPM" { - $parsePkgInfoFn = "ParseNPMPackage" - $packagePattern = "*.tgz" - break - } - "PyPI" { - $parsePkgInfoFn = "ParsePyPIPackage" - $packagePattern = "*.zip" - break - } - "C" { - $parsePkgInfoFn = "ParseCArtifact" - $packagePattern = "*.json" - } - "CPP" { - $parsePkgInfoFn = "ParseCppArtifact" - $packagePattern = "*.json" - } - default { - Write-Host "Unrecognized Language: $language" - exit(1) - } - } + +function RetrievePackages($artifactLocation) { $pkgs = Get-ChildItem -Path $artifactLocation -Include $packagePattern -Recurse -File - return $pkgs, $parsePkgInfoFn + if ((Get-ChildItem -Path Function: | ? { $_.Name -eq $GetPackageInfoFromPackageFileFn }).Count -gt 0) + { + return $pkgs, $GetPackageInfoFromPackageFileFn + } + else + { + LogError "The function '$GetPackageInfoFromPackageFileFn' was not found." + } } # Walk across all build artifacts, check them against the appropriate repository, return a list of tags/releases -function VerifyPackages($pkgRepository, $artifactLocation, $workingDirectory, $apiUrl, $releaseSha, $continueOnError = $false) { +function VerifyPackages($artifactLocation, $workingDirectory, $apiUrl, $releaseSha, $continueOnError = $false) { $pkgList = [array]@() - $pkgs, $parsePkgInfoFn = RetrievePackages -pkgRepository $pkgRepository -artifactLocation $artifactLocation + $pkgs, $parsePkgInfoFn = RetrievePackages -artifactLocation $artifactLocation foreach ($pkg in $pkgs) { try { diff --git a/eng/common/scripts/create-tags-and-git-release.ps1 b/eng/common/scripts/create-tags-and-git-release.ps1 index 83f2caa5cf41..07d8cd0ed5bc 100644 --- a/eng/common/scripts/create-tags-and-git-release.ps1 +++ b/eng/common/scripts/create-tags-and-git-release.ps1 @@ -18,13 +18,13 @@ param ( [switch]$continueOnError = $false ) -. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1) +. (Join-Path $PSScriptRoot common.ps1) $apiUrl = "https://api.github.com/repos/$repoId" Write-Host "Using API URL $apiUrl" # VERIFY PACKAGES -$pkgList = VerifyPackages -pkgRepository $packageRepository -artifactLocation $artifactLocation -workingDirectory $workingDirectory -apiUrl $apiUrl -releaseSha $releaseSha -continueOnError $continueOnError +$pkgList = VerifyPackages -artifactLocation $artifactLocation -workingDirectory $workingDirectory -apiUrl $apiUrl -releaseSha $releaseSha -continueOnError $continueOnError if ($pkgList) { Write-Host "Given the visible artifacts, github releases will be created for the following:" diff --git a/eng/common/scripts/update-docs-metadata.ps1 b/eng/common/scripts/update-docs-metadata.ps1 index 2f7f3343de43..662544854dae 100644 --- a/eng/common/scripts/update-docs-metadata.ps1 +++ b/eng/common/scripts/update-docs-metadata.ps1 @@ -14,41 +14,22 @@ param ( $DocRepoContentLocation = "docs-ref-services/" # within the doc repo, where does our readme go? ) -. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1) -. (Join-Path $PSScriptRoot SemVer.ps1) +. (Join-Path $PSScriptRoot common.ps1) $releaseReplaceRegex = "(https://github.com/$RepoId/(?:blob|tree)/)master" -function GetMetaData($lang){ - switch ($lang) { - "java" { - $metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/java-packages.csv" - break - } - ".net" { - $metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/dotnet-packages.csv" - break - } - "python" { - $metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/python-packages.csv" - break - } - "javascript" { - $metadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/js-packages.csv" - break - } - default { - Write-Host "Unrecognized Language: $language" - exit(1) - } +function GetMetaData { + if (Test-Path Variable:MetadataUri) { + $metadataResponse = Invoke-RestMethod -Uri $MetadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv + } + else { + LogError "The variable '$MetadataUri' was not found." } - - $metadataResponse = Invoke-RestMethod -Uri $metadataUri -method "GET" -MaximumRetryCount 3 -RetryIntervalSec 10 | ConvertFrom-Csv return $metadataResponse } -function GetAdjustedReadmeContent($pkgInfo, $lang){ +function GetAdjustedReadmeContent($pkgInfo){ $date = Get-Date -Format "MM/dd/yyyy" $service = "" @@ -56,7 +37,7 @@ function GetAdjustedReadmeContent($pkgInfo, $lang){ $pkgId = $pkgInfo.PackageId.Replace("@azure/", "") try { - $metadata = GetMetaData -lang $lang + $metadata = GetMetaData $service = $metadata | ? { $_.Package -eq $pkgId } @@ -93,8 +74,7 @@ function GetAdjustedReadmeContent($pkgInfo, $lang){ } $apiUrl = "https://api.github.com/repos/$repoId" -$pkgs = VerifyPackages -pkgRepository $Repository ` - -artifactLocation $ArtifactLocation ` +$pkgs = VerifyPackages -artifactLocation $ArtifactLocation ` -workingDirectory $WorkDirectory ` -apiUrl $apiUrl ` -releaseSha $ReleaseSHA ` @@ -116,7 +96,7 @@ if ($pkgs) { $readmeLocation = Join-Path $DocRepoLocation $DocRepoContentLocation $readmeName if ($packageInfo.ReadmeContent) { - $adjustedContent = GetAdjustedReadmeContent -pkgInfo $packageInfo -lang $Language + $adjustedContent = GetAdjustedReadmeContent -pkgInfo $packageInfo } if ($adjustedContent) { From 2239548ffc9987e09b7fc40c22677b95eae56a90 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 17 Nov 2020 13:40:56 -0800 Subject: [PATCH 2/3] Clean up common imports --- eng/common/scripts/Add-IssueComment.ps1 | 2 +- eng/common/scripts/Add-IssueLabels.ps1 | 2 +- eng/common/scripts/Delete-RemoteBranches.ps1 | 2 +- eng/common/scripts/Get-PullRequestCreator.ps1 | 2 +- eng/common/scripts/Package-Properties.ps1 | 2 +- eng/common/scripts/Queue-Pipeline.ps1 | 3 +-- eng/common/scripts/Submit-PullRequest.ps1 | 2 +- eng/common/scripts/Update-ChangeLog.ps1 | 2 +- eng/common/scripts/artifact-metadata-parsing.ps1 | 4 +--- eng/common/scripts/common.ps1 | 1 + eng/common/scripts/copy-docs-to-blobstorage.ps1 | 2 +- eng/common/scripts/update-docs-ci.ps1 | 7 ++----- 12 files changed, 13 insertions(+), 18 deletions(-) diff --git a/eng/common/scripts/Add-IssueComment.ps1 b/eng/common/scripts/Add-IssueComment.ps1 index b1d8a649797c..81636eb0d555 100644 --- a/eng/common/scripts/Add-IssueComment.ps1 +++ b/eng/common/scripts/Add-IssueComment.ps1 @@ -16,7 +16,7 @@ param( [string]$AuthToken ) -. "${PSScriptRoot}\common.ps1" +. (Join-Path $PSScriptRoot common.ps1) try { Add-GithubIssueComment -RepoOwner $RepoOwner -RepoName $RepoName ` diff --git a/eng/common/scripts/Add-IssueLabels.ps1 b/eng/common/scripts/Add-IssueLabels.ps1 index 0cd4837e69ad..a0482261d228 100644 --- a/eng/common/scripts/Add-IssueLabels.ps1 +++ b/eng/common/scripts/Add-IssueLabels.ps1 @@ -16,7 +16,7 @@ param( [string]$AuthToken ) -. "${PSScriptRoot}\common.ps1" +. (Join-Path $PSScriptRoot common.ps1) try { Add-GithubIssueLabels -RepoOwner $RepoOwner -RepoName $RepoName ` diff --git a/eng/common/scripts/Delete-RemoteBranches.ps1 b/eng/common/scripts/Delete-RemoteBranches.ps1 index 222f8562e3ea..f3a0e8729893 100644 --- a/eng/common/scripts/Delete-RemoteBranches.ps1 +++ b/eng/common/scripts/Delete-RemoteBranches.ps1 @@ -5,7 +5,7 @@ param( $AuthToken ) -. "${PSScriptRoot}\common.ps1" +. (Join-Path $PSScriptRoot common.ps1) LogDebug "Operating on Repo [ $RepoName ]" try{ diff --git a/eng/common/scripts/Get-PullRequestCreator.ps1 b/eng/common/scripts/Get-PullRequestCreator.ps1 index e9ed824c91b6..ff6784731452 100644 --- a/eng/common/scripts/Get-PullRequestCreator.ps1 +++ b/eng/common/scripts/Get-PullRequestCreator.ps1 @@ -12,7 +12,7 @@ param ( [string]$AuthToken ) -. "${PSScriptRoot}\common.ps1" +. (Join-Path $PSScriptRoot common.ps1) try { diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index d75b897f28c6..20a0309a2d3b 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -93,7 +93,7 @@ function Get-PkgProperties { $pkgDirectoryPath = Join-Path $serviceDirectoryPath $directory.Name - if ((Get-ChildItem -Path Function: | ? { $_.Name -eq $GetPackageInfoFromRepoFn }).Count -gt 0) + if ($GetPackageInfoFromRepoFn -and (Test-Path "Function:$GetPackageInfoFromRepoFn")) { $pkgProps = &$GetPackageInfoFromRepoFn -pkgPath $pkgDirectoryPath -serviceDirectory $ServiceDirectory -pkgName $PackageName } diff --git a/eng/common/scripts/Queue-Pipeline.ps1 b/eng/common/scripts/Queue-Pipeline.ps1 index d3c135e7bac0..a8c147e2ef38 100644 --- a/eng/common/scripts/Queue-Pipeline.ps1 +++ b/eng/common/scripts/Queue-Pipeline.ps1 @@ -21,8 +21,7 @@ param( [string]$Base64EncodedAuthToken ) -. "${PSScriptRoot}\logging.ps1" -. "${PSScriptRoot}\Invoke-DevOpsAPI.ps1" +. (Join-Path $PSScriptRoot common.ps1) if ($CancelPreviousBuilds) { diff --git a/eng/common/scripts/Submit-PullRequest.ps1 b/eng/common/scripts/Submit-PullRequest.ps1 index 32422e7f51aa..d337eb766269 100644 --- a/eng/common/scripts/Submit-PullRequest.ps1 +++ b/eng/common/scripts/Submit-PullRequest.ps1 @@ -59,7 +59,7 @@ param( [boolean]$CloseAfterOpenForTesting=$false ) -. "${PSScriptRoot}\common.ps1" +. (Join-Path $PSScriptRoot common.ps1) try { $resp = Get-GitHubPullRequests -RepoOwner $RepoOwner -RepoName $RepoName ` diff --git a/eng/common/scripts/Update-ChangeLog.ps1 b/eng/common/scripts/Update-ChangeLog.ps1 index eb506076c62b..769ea6af062a 100644 --- a/eng/common/scripts/Update-ChangeLog.ps1 +++ b/eng/common/scripts/Update-ChangeLog.ps1 @@ -22,7 +22,7 @@ if ($ReleaseDate -and ($Unreleased -eq $True)) { exit 1 } -. "${PSScriptRoot}\common.ps1" +. (Join-Path $PSScriptRoot common.ps1) if ($ReleaseDate) { diff --git a/eng/common/scripts/artifact-metadata-parsing.ps1 b/eng/common/scripts/artifact-metadata-parsing.ps1 index 8f2117ecc74a..6f9db9b88ee3 100644 --- a/eng/common/scripts/artifact-metadata-parsing.ps1 +++ b/eng/common/scripts/artifact-metadata-parsing.ps1 @@ -1,5 +1,3 @@ -. (Join-Path $PSScriptRoot common.ps1) - $SDIST_PACKAGE_REGEX = "^(?.*)\-(?$([AzureEngSemanticVersion]::SEMVER_REGEX))" # Posts a github release for each item of the pkgList variable. SilentlyContinue @@ -93,7 +91,7 @@ function RetrieveReleaseTag($artifactLocation, $continueOnError = $true) { function RetrievePackages($artifactLocation) { $pkgs = Get-ChildItem -Path $artifactLocation -Include $packagePattern -Recurse -File - if ((Get-ChildItem -Path Function: | ? { $_.Name -eq $GetPackageInfoFromPackageFileFn }).Count -gt 0) + if ($GetPackageInfoFromPackageFileFn -and (Test-Path "Function:$GetPackageInfoFromPackageFileFn")) { return $pkgs, $GetPackageInfoFromPackageFileFn } diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index 891821529c4e..9b2f2bce3750 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -10,6 +10,7 @@ $EngScriptsDir = Join-Path $EngDir "scripts" . (Join-Path $EngCommonScriptsDir Package-Properties.ps1) . (Join-Path $EngCommonScriptsDir logging.ps1) . (Join-Path $EngCommonScriptsDir Invoke-GitHubAPI.ps1) +. (Join-Path $EngCommonScriptsDir Invoke-DevOpsAPI.ps1) . (Join-Path $EngCommonScriptsDir artifact-metadata-parsing.ps1) # Setting expected from common languages settings diff --git a/eng/common/scripts/copy-docs-to-blobstorage.ps1 b/eng/common/scripts/copy-docs-to-blobstorage.ps1 index a81fc485f953..9e6ddf81077a 100644 --- a/eng/common/scripts/copy-docs-to-blobstorage.ps1 +++ b/eng/common/scripts/copy-docs-to-blobstorage.ps1 @@ -231,7 +231,7 @@ function Upload-Blobs } -if ((Get-ChildItem -Path Function: | ? { $_.Name -eq $PublishGithubIODocsFn }).Count -gt 0) +if ($PublishGithubIODocsFn -and (Test-Path "Function:$PublishGithubIODocsFn")) { &$PublishGithubIODocsFn -DocLocation $DocLocation -PublicArtifactLocation $PublicArtifactLocation } diff --git a/eng/common/scripts/update-docs-ci.ps1 b/eng/common/scripts/update-docs-ci.ps1 index 466df8a92654..f0df3b375af7 100644 --- a/eng/common/scripts/update-docs-ci.ps1 +++ b/eng/common/scripts/update-docs-ci.ps1 @@ -30,9 +30,7 @@ param ( $Configs ) -# import artifact parsing and semver handling -. (Join-Path $PSScriptRoot artifact-metadata-parsing.ps1) -. (Join-Path $PSScriptRoot SemVer.ps1) +. (Join-Path $PSScriptRoot common.ps1) # Updates a python CI configuration json. # For "latest", the version attribute is cleared, as default behavior is to pull latest "non-preview". @@ -235,8 +233,7 @@ $targets = ($Configs | ConvertFrom-Json).targets #} $apiUrl = "https://api.github.com/repos/$repoId" -$pkgs = VerifyPackages -pkgRepository $Repository ` - -artifactLocation $ArtifactLocation ` +$pkgs = VerifyPackages -artifactLocation $ArtifactLocation ` -workingDirectory $WorkDirectory ` -apiUrl $apiUrl ` -continueOnError $True From eadc8507ae1574d54b5691982964b77418be3c32 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Tue, 17 Nov 2020 16:55:49 -0800 Subject: [PATCH 3/3] Refactor Update-docs-ci.ps1 --- .../scripts/artifact-metadata-parsing.ps1 | 2 + eng/common/scripts/common.ps1 | 3 +- eng/common/scripts/update-docs-ci.ps1 | 220 +----------------- 3 files changed, 11 insertions(+), 214 deletions(-) diff --git a/eng/common/scripts/artifact-metadata-parsing.ps1 b/eng/common/scripts/artifact-metadata-parsing.ps1 index 6f9db9b88ee3..20541f53b4c9 100644 --- a/eng/common/scripts/artifact-metadata-parsing.ps1 +++ b/eng/common/scripts/artifact-metadata-parsing.ps1 @@ -1,3 +1,5 @@ +. (Join-Path $EngCommonScriptsDir SemVer.ps1) + $SDIST_PACKAGE_REGEX = "^(?.*)\-(?$([AzureEngSemanticVersion]::SEMVER_REGEX))" # Posts a github release for each item of the pkgList variable. SilentlyContinue diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index 9b2f2bce3750..e9a4e0709993 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -32,4 +32,5 @@ if (-not $LanguageShort) # Transformed Functions $GetPackageInfoFromRepoFn = "Get-${Language}-PackageInfoFromRepo" $GetPackageInfoFromPackageFileFn = "Get-${Language}-PackageInfoFromPackageFile" -$PublishGithubIODocsFn = "Publish-${Language}-GithubIODocs" \ No newline at end of file +$PublishGithubIODocsFn = "Publish-${Language}-GithubIODocs" +$UpdateDocCIFn = "Update-${Language}-CIConfig" \ No newline at end of file diff --git a/eng/common/scripts/update-docs-ci.ps1 b/eng/common/scripts/update-docs-ci.ps1 index f0df3b375af7..d13942b7f15e 100644 --- a/eng/common/scripts/update-docs-ci.ps1 +++ b/eng/common/scripts/update-docs-ci.ps1 @@ -32,198 +32,6 @@ param ( . (Join-Path $PSScriptRoot common.ps1) -# Updates a python CI configuration json. -# For "latest", the version attribute is cleared, as default behavior is to pull latest "non-preview". -# For "preview", we update to >= the target releasing package version. -function UpdateParamsJsonPython($pkgs, $ciRepo, $locationInDocRepo){ - $pkgJsonLoc = (Join-Path -Path $ciRepo -ChildPath $locationInDocRepo) - - if (-not (Test-Path $pkgJsonLoc)) { - Write-Error "Unable to locate package json at location $pkgJsonLoc, exiting." - exit(1) - } - - $allJson = Get-Content $pkgJsonLoc | ConvertFrom-Json - $visibleInCI = @{} - - for ($i=0; $i -lt $allJson.packages.Length; $i++) { - $pkgDef = $allJson.packages[$i] - - if ($pkgDef.package_info.name) { - $visibleInCI[$pkgDef.package_info.name] = $i - } - } - - foreach ($releasingPkg in $pkgs) { - if ($visibleInCI.ContainsKey($releasingPkg.PackageId)) { - $packagesIndex = $visibleInCI[$releasingPkg.PackageId] - $existingPackageDef = $allJson.packages[$packagesIndex] - - if ($releasingPkg.IsPrerelease) { - if (-not $existingPackageDef.package_info.version) { - $existingPackageDef.package_info | Add-Member -NotePropertyName version -NotePropertyValue "" - } - - $existingPackageDef.package_info.version = ">=$($releasingPkg.PackageVersion)" - } - else { - if ($def.version) { - $def.PSObject.Properties.Remove('version') - } - } - } - else { - $newItem = New-Object PSObject -Property @{ - package_info = New-Object PSObject -Property @{ - prefer_source_distribution = "true" - install_type = "pypi" - name=$releasingPkg.PackageId - } - excludePath = @("test*","example*","sample*","doc*") - } - $allJson.packages += $newItem - } - } - - $jsonContent = $allJson | ConvertTo-Json -Depth 10 | % {$_ -replace "(?m) (?<=^(?: )*)", " " } - - Set-Content -Path $pkgJsonLoc -Value $jsonContent -} - -# Updates a js CI configuration json. -# For "latest", we simply set a target package name -# For "preview", we add @next to the target package name -function UpdateParamsJsonJS($pkgs, $ciRepo, $locationInDocRepo){ - $pkgJsonLoc = (Join-Path -Path $ciRepo -ChildPath $locationInDocRepo) - - if (-not (Test-Path $pkgJsonLoc)) { - Write-Error "Unable to locate package json at location $pkgJsonLoc, exiting." - exit(1) - } - - $allJson = Get-Content $pkgJsonLoc | ConvertFrom-Json - - $visibleInCI = @{} - - for ($i=0; $i -lt $allJson.npm_package_sources.Length; $i++) { - $pkgDef = $allJson.npm_package_sources[$i] - $accessor = ($pkgDef.name).Replace("`@next", "") - $visibleInCI[$accessor] = $i - } - - foreach ($releasingPkg in $pkgs) { - $name = $releasingPkg.PackageId - - if ($releasingPkg.IsPrerelease) { - $name += "`@next" - } - - if ($visibleInCI.ContainsKey($releasingPkg.PackageId)) { - $packagesIndex = $visibleInCI[$releasingPkg.PackageId] - $existingPackageDef = $allJson.npm_package_sources[$packagesIndex] - $existingPackageDef.name = $name - } - else { - $newItem = New-Object PSObject -Property @{ - name = $name - } - - if ($newItem) { $allJson.npm_package_sources += $newItem } - } - } - - $jsonContent = $allJson | ConvertTo-Json -Depth 10 | % {$_ -replace "(?m) (?<=^(?: )*)", " " } - - Set-Content -Path $pkgJsonLoc -Value $jsonContent -} - -# details on CSV schema can be found here -# https://review.docs.microsoft.com/en-us/help/onboard/admin/reference/dotnet/documenting-nuget?branch=master#set-up-the-ci-job -function UpdateCSVBasedCI($pkgs, $ciRepo, $locationInDocRepo){ - $csvLoc = (Join-Path -Path $ciRepo -ChildPath $locationInDocRepo) - - if (-not (Test-Path $csvLoc)) { - Write-Error "Unable to locate package csv at location $csvLoc, exiting." - exit(1) - } - - $allCSVRows = Get-Content $csvLoc - $visibleInCI = @{} - - # first pull what's already available - for ($i=0; $i -lt $allCSVRows.Length; $i++) { - $pkgDef = $allCSVRows[$i] - - # get rid of the modifiers to get just the package id - $id = $pkgDef.split(",")[1] -replace "\[.*?\]", "" - - $visibleInCI[$id] = $i - } - - foreach ($releasingPkg in $pkgs) { - $installModifiers = "tfm=netstandard2.0" - if ($releasingPkg.IsPrerelease) { - $installModifiers += ";isPrerelease=true" - } - $lineId = $releasingPkg.PackageId.Replace(".","").ToLower() - - if ($visibleInCI.ContainsKey($releasingPkg.PackageId)) { - $packagesIndex = $visibleInCI[$releasingPkg.PackageId] - $allCSVRows[$packagesIndex] = "$($lineId),[$installModifiers]$($releasingPkg.PackageId)" - } - else { - $newItem = "$($lineId),[$installModifiers]$($releasingPkg.PackageId)" - $allCSVRows += ($newItem) - } - } - - Set-Content -Path $csvLoc -Value $allCSVRows -} - -# a "package.json configures target packages for all the monikers in a Repository, it also has a slightly different -# schema than the moniker-specific json config that is seen in python and js -function UpdatePackageJson($pkgs, $ciRepo, $locationInDocRepo, $monikerId){ - $pkgJsonLoc = (Join-Path -Path $ciRepo -ChildPath $locationInDocRepo) - - if (-not (Test-Path $pkgJsonLoc)) { - Write-Error "Unable to locate package json at location $pkgJsonLoc, exiting." - exit(1) - } - - $allJsonData = Get-Content $pkgJsonLoc | ConvertFrom-Json - - $visibleInCI = @{} - - for ($i=0; $i -lt $allJsonData[$monikerId].packages.Length; $i++) { - $pkgDef = $allJsonData[$monikerId].packages[$i] - $visibleInCI[$pkgDef.packageArtifactId] = $i - } - - foreach ($releasingPkg in $pkgs) { - if ($visibleInCI.ContainsKey($releasingPkg.PackageId)) { - $packagesIndex = $visibleInCI[$releasingPkg.PackageId] - $existingPackageDef = $allJsonData[$monikerId].packages[$packagesIndex] - $existingPackageDef.packageVersion = $releasingPkg.PackageVersion - } - else { - $newItem = New-Object PSObject -Property @{ - packageDownloadUrl = "https://repo1.maven.org/maven2" - packageGroupId = $releasingPkg.GroupId - packageArtifactId = $releasingPkg.PackageId - packageVersion = $releasingPkg.PackageVersion - inputPath = @() - excludePath = @() - } - - $allJsonData[$monikerId].packages += $newItem - } - } - - $jsonContent = $allJsonData | ConvertTo-Json -Depth 10 | % {$_ -replace "(?m) (?<=^(?: )*)", " " } - - Set-Content -Path $pkgJsonLoc -Value $jsonContent -} - $targets = ($Configs | ConvertFrom-Json).targets #{ @@ -246,27 +54,13 @@ foreach ($config in $targets) { Write-Host "Given the visible artifacts, CI updates against $($config.path_to_config) will be processed for the following packages." Write-Host ($pkgsFiltered | % { $_.PackageId + " " + $_.PackageVersion }) - switch ($Repository) { - "Nuget" { - UpdateCSVBasedCI -pkgs $pkgsFiltered -ciRepo $CIRepository -locationInDocRepo $config.path_to_config - break - } - "NPM" { - UpdateParamsJsonJS -pkgs $pkgsFiltered -ciRepo $CIRepository -locationInDocRepo $config.path_to_config - break - } - "PyPI" { - UpdateParamsJsonPython -pkgs $pkgsFiltered -ciRepo $CIRepository -locationInDocRepo $config.path_to_config - break - } - "Maven" { - UpdatePackageJson -pkgs $pkgsFiltered -ciRepo $CIRepository -locationInDocRepo $config.path_to_config -monikerId $config.monikerid - break - } - default { - Write-Host "Unrecognized target: $Repository" - exit(1) - } + if ($UpdateDocCIFn -and (Test-Path "Function:$UpdateDocCIFn")) + { + &$UpdateDocCIFn -pkgs $pkgsFiltered -ciRepo $CIRepository -locationInDocRepo $config.path_to_config -monikerId $config.monikerid + } + else + { + LogWarning "The function '$UpdateDocCIFn' was not found." } } } \ No newline at end of file