Skip to content

Commit 612d7bc

Browse files
Add foundations for eng/common restructure (#12725)
1 parent 0c40b36 commit 612d7bc

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

eng/scripts/Language-Settings.ps1

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
$Language = "python"
2+
$Lang = "python"
3+
$PackageRepository = "PyPI"
4+
$packagePattern = "*.zip"
5+
$MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/master/_data/releases/latest/python-packages.csv"
6+
7+
function Extract-python-PkgProperties ($pkgPath, $serviceName, $pkgName)
8+
{
9+
$pkgName = $pkgName.Replace('_', '-')
10+
if (Test-Path (Join-Path $pkgPath "setup.py"))
11+
{
12+
$setupLocation = $pkgPath.Replace('\','/')
13+
pushd $RepoRoot
14+
$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 ","
15+
popd
16+
if (($setupProps -ne $null) -and ($setupProps[0] -eq $pkgName))
17+
{
18+
return [PackageProps]::new($setupProps[0], $setupProps[1], $pkgPath, $serviceName)
19+
}
20+
}
21+
return $null
22+
}
23+
24+
# Returns the pypi publish status of a package id and version.
25+
function IsPythonPackageVersionPublished($pkgId, $pkgVersion) {
26+
try
27+
{
28+
$existingVersion = (Invoke-RestMethod -MaximumRetryCount 3 -Method "Get" -uri "https://pypi.org/pypi/$pkgId/$pkgVersion/json").info.version
29+
# if existingVersion exists, then it's already been published
30+
return $True
31+
}
32+
catch
33+
{
34+
$statusCode = $_.Exception.Response.StatusCode.value__
35+
$statusDescription = $_.Exception.Response.StatusDescription
36+
37+
# if this is 404ing, then this pkg has never been published before
38+
if ($statusCode -eq 404)
39+
{
40+
return $False
41+
}
42+
Write-Host "PyPI Invocation failed:"
43+
Write-Host "StatusCode:" $statusCode
44+
Write-Host "StatusDescription:" $statusDescription
45+
exit(1)
46+
}
47+
}
48+
49+
# Parse out package publishing information given a python sdist of ZIP format.
50+
function Parse-python-Package($pkg, $workingDirectory) {
51+
$pkg.Basename -match $SDIST_PACKAGE_REGEX | Out-Null
52+
53+
$pkgId = $matches["package"]
54+
$pkgVersion = $matches["versionstring"]
55+
56+
$workFolder = "$workingDirectory$($pkg.Basename)"
57+
$origFolder = Get-Location
58+
$releaseNotes = ""
59+
$readmeContent = ""
60+
61+
New-Item -ItemType Directory -Force -Path $workFolder
62+
Expand-Archive -Path $pkg -DestinationPath $workFolder
63+
64+
$changeLogLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "CHANGELOG.md")[0]
65+
if ($changeLogLoc) {
66+
$releaseNotes = Get-ChangeLogEntryAsString -ChangeLogLocation $changeLogLoc -VersionString $pkgVersion
67+
}
68+
69+
$readmeContentLoc = @(Get-ChildItem -Path $workFolder -Recurse -Include "README.md") | Select-Object -Last 1
70+
71+
if ($readmeContentLoc) {
72+
$readmeContent = Get-Content -Raw $readmeContentLoc
73+
}
74+
75+
Remove-Item $workFolder -Force -Recurse -ErrorAction SilentlyContinue
76+
77+
return New-Object PSObject -Property @{
78+
PackageId = $pkgId
79+
PackageVersion = $pkgVersion
80+
Deployable = $forceCreate -or !(IsPythonPackageVersionPublished -pkgId $pkgId -pkgVersion $pkgVersion)
81+
ReleaseNotes = $releaseNotes
82+
ReadmeContent = $readmeContent
83+
}
84+
}
85+
86+
# Stage and Upload Docs to blob Storage
87+
function StageAndUpload-python-Docs()
88+
{
89+
$PublishedDocs = Get-ChildItem "$DocLocation" | Where-Object -FilterScript {$_.Name.EndsWith(".zip")}
90+
91+
foreach ($Item in $PublishedDocs)
92+
{
93+
$PkgName = $Item.BaseName
94+
$ZippedDocumentationPath = Join-Path -Path $DocLocation -ChildPath $Item.Name
95+
$UnzippedDocumentationPath = Join-Path -Path $DocLocation -ChildPath $PkgName
96+
$VersionFileLocation = Join-Path -Path $UnzippedDocumentationPath -ChildPath "version.txt"
97+
98+
Expand-Archive -Force -Path $ZippedDocumentationPath -DestinationPath $UnzippedDocumentationPath
99+
100+
$Version = $(Get-Content $VersionFileLocation).Trim()
101+
102+
Write-Host "Discovered Package Name: $PkgName"
103+
Write-Host "Discovered Package Version: $Version"
104+
Write-Host "Directory for Upload: $UnzippedDocumentationPath"
105+
106+
Upload-Blobs -DocDir $UnzippedDocumentationPath -PkgName $PkgName -DocVersion $Version
107+
}
108+
}

0 commit comments

Comments
 (0)