-
Notifications
You must be signed in to change notification settings - Fork 3k
Add foundations for eng/common restructure #12725
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
chidozieononiwu
merged 1 commit into
Azure:master
from
chidozieononiwu:RestructureCommonTools
Jul 25, 2020
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
$Language = "python" | ||
$Lang = "python" | ||
$PackageRepository = "PyPI" | ||
$packagePattern = "*.zip" | ||
$MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/python-packages.csv" | ||
|
||
function Extract-python-PkgProperties ($pkgPath, $serviceName, $pkgName) | ||
{ | ||
$pkgName = $pkgName.Replace('_', '-') | ||
if (Test-Path (Join-Path $pkgPath "setup.py")) | ||
{ | ||
$setupLocation = $pkgPath.Replace('\','/') | ||
pushd $RepoRoot | ||
$setupProps = (python -c "import sys; import os; sys.path.append(os.path.join('scripts', 'devops_tasks')); from common_tasks import parse_setup; obj=parse_setup('$setupLocation'); print('{0},{1}'.format(obj[0], obj[1]));") -split "," | ||
popd | ||
if (($setupProps -ne $null) -and ($setupProps[0] -eq $pkgName)) | ||
{ | ||
return [PackageProps]::new($setupProps[0], $setupProps[1], $pkgPath, $serviceName) | ||
} | ||
} | ||
return $null | ||
} | ||
|
||
# Returns the pypi publish status of a package id and version. | ||
function IsPythonPackageVersionPublished($pkgId, $pkgVersion) { | ||
try | ||
{ | ||
$existingVersion = (Invoke-RestMethod -MaximumRetryCount 3 -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) | ||
} | ||
} | ||
|
||
# Parse out package publishing information given a python sdist of ZIP format. | ||
function Parse-python-Package($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 | ||
Deployable = $forceCreate -or !(IsPythonPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion) | ||
ReleaseNotes = $releaseNotes | ||
ReadmeContent = $readmeContent | ||
} | ||
} | ||
|
||
# Stage and Upload Docs to blob Storage | ||
function StageAndUpload-python-Docs() | ||
{ | ||
$PublishedDocs = Get-ChildItem "$DocLocation" | Where-Object -FilterScript {$_.Name.EndsWith(".zip")} | ||
|
||
foreach ($Item in $PublishedDocs) | ||
{ | ||
$PkgName = $Item.BaseName | ||
$ZippedDocumentationPath = Join-Path -Path $DocLocation -ChildPath $Item.Name | ||
$UnzippedDocumentationPath = Join-Path -Path $DocLocation -ChildPath $PkgName | ||
$VersionFileLocation = Join-Path -Path $UnzippedDocumentationPath -ChildPath "version.txt" | ||
|
||
Expand-Archive -Force -Path $ZippedDocumentationPath -DestinationPath $UnzippedDocumentationPath | ||
|
||
$Version = $(Get-Content $VersionFileLocation).Trim() | ||
|
||
Write-Host "Discovered Package Name: $PkgName" | ||
Write-Host "Discovered Package Version: $Version" | ||
Write-Host "Directory for Upload: $UnzippedDocumentationPath" | ||
|
||
Upload-Blobs -DocDir $UnzippedDocumentationPath -PkgName $PkgName -DocVersion $Version | ||
} | ||
} |
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.