Skip to content

Commit

Permalink
isolate generate reports stage
Browse files Browse the repository at this point in the history
  • Loading branch information
fey101 committed Jul 9, 2024
1 parent e0007aa commit b05bfb3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 140 deletions.
152 changes: 12 additions & 140 deletions pipelines/snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,156 +13,21 @@ schedules:
- master
always: true

resources:
repositories:
- repository: microsoft-graph-docs
type: github
endpoint: microsoftgraph (22)
name: microsoftgraph/microsoft-graph-docs
ref: main

pool:
name: 1es-ubuntu-latest


parameters:
- name: snippetLanguages
type: object
default: ['C#', 'CLI', 'Go', 'Java', 'JavaScript', 'PHP', 'PowerShell', 'Python'] # should be ordered alphabetically
displayName: 'Languages to generate snippets for'
- name: extractBuildId
type: string
default: "155605"
displayName: 'BuildId for run with artifacts'

variables:
buildConfiguration: 'Release'
apidoctorPath: 'microsoft-graph-devx-api/apidoctor'
apidoctorProjects: '$(apidoctorPath)/**/*.csproj'
snippetLanguages: ${{ join(',',parameters.snippetLanguages) }}
extractBuildId: ${{parameters.extractBuildId}}

stages:
- stage: GenerateSnippets
displayName: Generate snippets
jobs:
- job: GenerateSnippets
displayName: Generate snippets
steps:
- checkout: self
displayName: checkout GE api
fetchDepth: 1
submodules: recursive
persistCredentials: true

- checkout: microsoft-graph-docs
displayName: checkout docs
fetchDepth: 1
persistCredentials: true

- pwsh: |
# override branch prefix incase the run is manually triggered
$branchPrefix = if ($env:BUILD_REASON -eq 'Manual') { "preview-snippet-generation" } else { "snippet-generation" }
Write-Host "##vso[task.setvariable variable=branchPrefix]$branchPrefix"
Write-Host "Branch prefix is $branchPrefix"
displayName: 'Evaluate branch prefix to use'
- template: templates/git-config.yml

- task: UseDotNet@2
displayName: 'Install .NET Core SDK 6'
inputs:
version: 6.x

- task: UseDotNet@2
displayName: 'Install .NET Core SDK 8'
inputs:
version: 8.0.x

- task: DotNetCoreCLI@2
displayName: 'Build snippet generator'
inputs:
command: 'build'
projects: 'microsoft-graph-devx-api/CodeSnippetsReflection.App/CodeSnippetsReflection.App.csproj'
arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'Restore packages for APIDoctor'
inputs:
command: 'restore'
projects: '$(Build.SourcesDirectory)/$(apidoctorProjects)'

- task: DotNetCoreCLI@2
displayName: 'Build APIDoctor'
inputs:
command: 'build'
projects: '$(Build.SourcesDirectory)/$(apidoctorProjects)'
arguments: '--configuration $(buildConfiguration)'

- pwsh: |
# release folder can change based on .NET core version, so search recursively in bin folder
$snippetGeneratorPath = (Get-ChildItem $env:BUILD_SOURCESDIRECTORY/microsoft-graph-devx-api/CodeSnippetsReflection.App/bin/Release *App -Recurse).FullName
Write-Host "Path to snippet generator tool: $snippetGeneratorPath"
$apidoctorPath = (Get-ChildItem $env:BUILD_SOURCESDIRECTORY/microsoft-graph-devx-api/apidoctor/ApiDoctor.Console/bin/Release apidoc -Recurse).FullName
Write-Host "Path to apidoctor tool: $apidoctorPath"
. $apidoctorPath generate-snippets --ignore-warnings --path . --snippet-generator-path $snippetGeneratorPath --temp-output-path $env:BUILD_ARTIFACTSTAGINGDIRECTORY/Snippets --lang $(snippetLanguages) --git-path "/bin/git"
displayName: 'Generate snippets'
workingDirectory: microsoft-graph-docs
- task: PublishBuildArtifacts@1
displayName: 'Publish snippets as artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/Snippets'
ArtifactName: 'Snippets'
publishLocation: 'Container'
StoreAsTar: true

- pwsh: $(Build.SourcesDirectory)/microsoft-graph-devx-api/scripts/cleanupUnusedSnippets.ps1
displayName: 'Cleanup unused snippets'
workingDirectory: microsoft-graph-docs

- template: templates/commit-changes.yml
- stage: RunTests
dependsOn: GenerateSnippets
displayName: Run tests
jobs:
- job: RunTests
strategy:
matrix:
'HTTP v1 Stable':
SNIPPET_LANGUAGE: 'http'
GRAPH_VERSION: 'v1'
TEST_CATEGORY: 'Stable'
'HTTP v1 KnownIssues':
SNIPPET_LANGUAGE: 'http'
GRAPH_VERSION: 'v1'
TEST_CATEGORY: 'KnownIssues'
'HTTP beta Stable':
SNIPPET_LANGUAGE: 'http'
GRAPH_VERSION: 'beta'
TEST_CATEGORY: 'Stable'
'HTTP beta KnownIssues':
SNIPPET_LANGUAGE: 'http'
GRAPH_VERSION: 'beta'
TEST_CATEGORY: 'KnownIssues'
${{ each language in parameters.snippetLanguages }}:
'${{ language }} v1 Stable':
SNIPPET_LANGUAGE: ${{ lower(language) }}
GRAPH_VERSION: 'v1'
TEST_CATEGORY: 'Stable'
'${{ language }} v1 KnownIssues':
SNIPPET_LANGUAGE: ${{ lower(language) }}
GRAPH_VERSION: 'v1'
TEST_CATEGORY: 'KnownIssues'
'${{ language }} beta Stable':
SNIPPET_LANGUAGE: ${{ lower(language) }}
GRAPH_VERSION: 'beta'
TEST_CATEGORY: 'Stable'
'${{ language }} beta KnownIssues':
SNIPPET_LANGUAGE: ${{ lower(language) }}
GRAPH_VERSION: 'beta'
TEST_CATEGORY: 'KnownIssues'
steps:
- template: templates/run-tests.yml
- stage: GenerateRunTestReports
dependsOn: RunTests
displayName: GenerateRunTestReports
jobs:
- job: GenerateCategorizationReport
Expand All @@ -173,6 +38,13 @@ stages:
submodules: recursive
persistCredentials: true

- pwsh: |
$(Build.SourcesDirectory)/scripts/downloadArtifacts.ps1 -buildId $(extractBuildId)
env:
AZURE_DEVOPS_EXT_PAT: $(AZURE_DEVOPS_EXT_PAT)
BASE_DIRECTORY: $(Build.SourcesDirectory)
displayName: 'Download and extract artifact'
- task: DownloadPipelineArtifact@2
displayName: 'Download RunTests artifact'
inputs:
Expand Down
52 changes: 52 additions & 0 deletions scripts/downloadArtifacts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
param(
[int]$buildId = -1
)

# get script directory
$scriptsDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition

$projectPath = Split-Path -Parent $scriptsDirectory

$organization = "https://dev.azure.com/microsoftgraph"
$project = "Graph Developer Experiences"
$pipelineName = "Snippet Generation DevX"

if ($buildId -eq -1) {
Write-Warning "selecting the latest scheduled build as buildId is not specified"
$buildId = az pipelines build list --organization $organization --project $project --query "[?definition.name=='$pipelineName' && status=='completed' && reason=='schedule'].id" --output tsv | Select-Object -First 1
}

$tempFolder = $env:BASE_DIRECTORY

$artifactExtractDirectory = Join-Path $tempFolder "artifact-extract-directory"
New-Item -ItemType Directory -Force -Path $artifactExtractDirectory
$stableDownloadUrl = "$organization/$project/_apis/build/builds/$buildId/artifacts?artifactName=Generation%20Test%20Results&api-version=5.0&%24format=zip"
$DownloadFolderName = "SnippetGenerationTestResults"
$downloadZipFullPath = Join-Path $artifactExtractDirectory "$DownloadFolderName.zip"
$downloadExtractDirectory = "$(Build.ArtifactStagingDirectory)/TestResults"

if ([string]::IsNullOrEmpty($env:AZURE_DEVOPS_EXT_PAT))
{
Write-Warning "Fetching request token from logged in az account user"
$token = az account get-access-token --query accessToken --output tsv
$auth_header_value = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token)
}
else{
$PAT_token = $env:AZURE_DEVOPS_EXT_PAT
$base64_PAT_token = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$($PAT_token)"))
$auth_header_value = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", $base64_PAT_token)
}

try
{
Invoke-WebRequest -Uri $stableDownloadUrl -OutFile $downloadZipFullPath -Headers @{Authorization=$auth_header_value}
}
catch
{
Write-Warning "Failed to download artifact $DownloadFolderName"
exit
}

Expand-Archive -Path $downloadZipFullPath -DestinationPath $downloadExtractDirectory

Remove-Item $downloadZipFullPath

0 comments on commit b05bfb3

Please sign in to comment.