Skip to content
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

Docs onboarding v2 #36383

Merged
merged 5 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $GithubUri = "https://github.com/Azure/azure-sdk-for-java"
$PackageRepositoryUri = "https://repo1.maven.org/maven2"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you plan to use the new script you are adding to common in Azure/azure-sdk-tools#6632?

. "$PSScriptRoot/docs/Docs-ToC.ps1"
. "$PSScriptRoot/docs/Docs-Onboarding.ps1"

function Get-java-PackageInfoFromRepo ($pkgPath, $serviceDirectory)
{
Expand Down Expand Up @@ -315,6 +316,12 @@ function SourcePackageHasComFolder($artifactNamePrefix, $packageDirectory) {

$sourcesJarPath = (Get-ChildItem -File -Path $packageDirectory -Filter "*-sources.jar")[0]
$sourcesExtractPath = Join-Path $packageDirectory "sources"

# Ensure that the sources folder is empty before extracting the jar
# otherwise there could be file collisions from a previous extraction run on
# the same system.
Remove-Item $sourcesExtractPath/* -Force -Recurse -ErrorAction Ignore

Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($sourcesJarPath, $sourcesExtractPath)

Expand Down
66 changes: 66 additions & 0 deletions eng/scripts/docs/Docs-Onboarding.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#$SetDocsPackageOnboarding = "Set-${Language}-DocsPackageOnboarding"
function Set-java-DocsPackageOnboarding($moniker, $metadata, $docRepoLocation, $packageSourceOverride) {

# Do not write onboarding information for legacy moniker
# TODO: remove this once legacy moniker is properly configured
if ($moniker -eq 'legacy') {
return
}

$packageJsonPath = Join-Path $docRepoLocation "package.json"
$onboardingInfo = Get-Content $packageJsonPath | ConvertFrom-Json

$monikerOutputPath = "docs-ref-autogen"
if ($moniker -ne 'latest') {
$monikerOutputPath = "$moniker/docs-ref-autogen"
}
$monikerIndex = -1
for($i = 0; $i -lt $onboardingInfo.Count; $i++) {
if ($onboardingInfo[$i].output_path -eq $monikerOutputPath) {
$monikerIndex = $i
break
}
}

if ($monikerIndex -eq -1) {
Write-Error "No appropriate index for moniker $moniker"
}

$onboardedPackages = @()
foreach ($package in $metadata) {
$packageInfo = [ordered]@{
packageArtifactId = $package.Name
packageGroupId = $package.Group
packageVersion = $package.Version

# packageDownloadUrl is required by docs build and other values are
# rejected. This is a temporary workaround until the docs build
# supports more package stores.
packageDownloadUrl = 'https://repo1.maven.org/maven2'
}

# Add items from 'DocsCiConfigProperties' into onboarding info. If a
# property already exists, it will be overwritten.
if ($package.ContainsKey('DocsCiConfigProperties')) {
foreach ($key in $package['DocsCiConfigProperties'].Keys) {
$packageInfo[$key] = $package['DocsCiConfigProperties'][$key]
}
}

$onboardedPackages += $packageInfo
}

$onboardingInfo[$monikerIndex].packages = $onboardedPackages

Set-Content -Path $packageJsonPath -Value (ConvertTo-Json -InputObject $onboardingInfo -Depth 100)
}

#$GetDocsPackagesAlreadyOnboarded = "Get-${Language}-DocsPackagesAlreadyOnboarded"
function Get-java-DocsPackagesAlreadyOnboarded($docRepoLocation, $moniker) {
return Get-java-OnboardedDocsMsPackagesForMoniker $docRepoLocation $moniker
}

# $GetPackageIdentity = "Get-${Language}-PackageIdentity"
function Get-java-PackageIdentity($package) {
return "$($package['Group']):$($package['Name'])"
}
3 changes: 3 additions & 0 deletions eng/scripts/docs/Docs-ToC.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function Get-java-OnboardedDocsMsPackagesForMoniker ($DocRepoLocation, $moniker)
elseif("latest" -eq $moniker) {
$onboardingSpec = $onboardingSpec | Where-Object { $_.output_path -eq "docs-ref-autogen" }
}

# TODO: Add support for "legacy" moniker

$onboardedPackages = @{}
foreach ($spec in $onboardingSpec.packages) {
$packageName = $spec.packageArtifactId
Expand Down
17 changes: 17 additions & 0 deletions eng/scripts/docs/tests/Docs-Onboarding.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Import-Module Pester

BeforeAll {
. $PSScriptRoot/../Docs-Onboarding.ps1
}

Describe 'Get-java-PackageIdentity' {
It 'should return the package identity' {
$package = [ordered]@{
Name = 'packageName'
Group = 'packageGroup'
}

$packageIdentity = Get-java-PackageIdentity $package
$packageIdentity | Should -Be 'packageGroup:packageName'
}
}