Skip to content

Commit

Permalink
Docs onboarding v2 (Azure#36383)
Browse files Browse the repository at this point in the history
* Add v2 docs onboarding for Java

* Add onboarding logic for onboarding v2

* Set skipPublishDocMs for packages that are skipped in Language-Settings.ps1 and should not publish docs.

* Ignore errors removing path that doesn't exist (ensure that test runs on local machine are clean, it's OK if files aren't present to clean up.

* Revert "Set skipPublishDocMs for packages that are skipped in Language-Settings.ps1 and should not publish docs."

This reverts commit d383cad.
  • Loading branch information
danieljurek authored Aug 23, 2023
1 parent b6e5ed1 commit fe7e43e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
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"

. "$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'
}
}

0 comments on commit fe7e43e

Please sign in to comment.