Skip to content

Commit

Permalink
Use package.json for autorest in sdk repo (Azure#42524)
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr authored Mar 11, 2024
1 parent 4b6f51c commit 3092f46
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 25 deletions.
12 changes: 11 additions & 1 deletion eng/pipelines/templates/jobs/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
parameters:
Artifacts: ${{ parameters.Artifacts }}

- ${{ if eq(parameters.CheckAOTCompat, 'true') }}:
- template: /eng/pipelines/templates/steps/aot-compatibility.yml
parameters:
Expand Down Expand Up @@ -213,6 +213,10 @@ jobs:
pwsh: true
failOnStderr: false

- template: /eng/pipelines/templates/steps/dotnet-diagnostics.yml
parameters:
LogFilePath: $(Build.ArtifactStagingDirectory)/rebuild.binlog

- script: >-
dotnet build eng/service.proj -warnaserror
/t:rebuild
Expand All @@ -225,9 +229,15 @@ jobs:
/p:Configuration=$(BuildConfiguration)
/p:EnableSourceLink=false
/p:BuildSnippets=true
$(DiagnosticArguments)
displayName: Build snippets
condition: and(succeeded(), eq(${{ parameters.BuildSnippets }}, true))
- template: /eng/common/pipelines/templates/steps/publish-artifact.yml
parameters:
ArtifactPath: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'verify'

# For some pipelines like mgmt which are tested in aggregate we want to limit the pipeline to no tests or
# other stages that are aggregate in nature as those are tested in another aggregate pipeline
- ${{ if or(ne(variables['Build.Reason'], 'PullRequest'), ne(parameters.LimitForPullRequest, 'true')) }}:
Expand Down
10 changes: 7 additions & 3 deletions eng/scripts/CodeChecks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ function Invoke-Block([scriptblock]$cmd) {
}

try {
Write-Host "Initialize npx cache"
Write-Host "Restore ./node_modules"
Invoke-Block {
& npx autorest --version
& npm ci --prefix $RepoRoot
}

if ($ProjectDirectory -and -not $ServiceDirectory)
Expand Down Expand Up @@ -92,9 +92,13 @@ try {
}
}

$debugLogging = $env:SYSTEM_DEBUG -eq "true"
$logsFolder = $env:BUILD_ARTIFACTSTAGINGDIRECTORY
$diagnosticArguments = ($debugLogging -and $logsFolder) ? "/binarylogger:$logsFolder/generatecode.binlog" : ""

Write-Host "Re-generating clients"
Invoke-Block {
& dotnet msbuild $PSScriptRoot\..\service.proj /restore /t:GenerateCode /p:SDKType=$SDKType /p:ServiceDirectory=$ServiceDirectory
& dotnet msbuild $PSScriptRoot\..\service.proj /restore /t:GenerateCode /p:SDKType=$SDKType /p:ServiceDirectory=$ServiceDirectory $diagnosticArguments
}
}

Expand Down
10 changes: 7 additions & 3 deletions eng/scripts/Export-API.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ param (
[Parameter(Position=0)]
[ValidateNotNullOrEmpty()]
[string] $ServiceDirectory,
[string] $SDKType = "all",
[string] $SDKType = "all",
[switch] $SpellCheckPublicApiSurface
)

if ($SpellCheckPublicApiSurface -and -not (Get-Command 'npx')) {
if ($SpellCheckPublicApiSurface -and -not (Get-Command 'npx')) {
Write-Error "Could not locate npx. Install NodeJS (includes npm and npx) https://nodejs.org/en/download/"
exit 1
}

$servicesProj = Resolve-Path "$PSScriptRoot/../service.proj"

dotnet build /t:ExportApi /p:RunApiCompat=false /p:InheritDocEnabled=false /p:GeneratePackageOnBuild=false /p:Configuration=Release /p:IncludeSamples=false /p:IncludePerf=false /p:IncludeStress=false /p:IncludeTests=false /p:Scope="$ServiceDirectory" /p:SDKType=$SDKType /restore $servicesProj
$debugLogging = $env:SYSTEM_DEBUG -eq "true"
$logsFolder = $env:BUILD_ARTIFACTSTAGINGDIRECTORY
$diagnosticArguments = ($debugLogging -and $logsFolder) ? "/binarylogger:$logsFolder/exportapi.binlog" : ""

dotnet build /t:ExportApi /p:RunApiCompat=false /p:InheritDocEnabled=false /p:GeneratePackageOnBuild=false /p:Configuration=Release /p:IncludeSamples=false /p:IncludePerf=false /p:IncludeStress=false /p:IncludeTests=false /p:Scope="$ServiceDirectory" /p:SDKType=$SDKType /restore $servicesProj $diagnosticArguments

if ($SpellCheckPublicApiSurface) {
Write-Host "Spell check public API surface"
Expand Down
21 changes: 3 additions & 18 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -623,22 +623,11 @@ function Update-dotnet-GeneratedSdks([string]$PackageDirectoriesFile) {
$lines | Out-File $projectListOverrideFile -Encoding UTF8
Write-Host "`n"

# Initialize npm and npx cache
Write-Host "##[group]Initializing npm and npx cache"
# Install autorest locally
Invoke-LoggedCommand "npm ci --prefix $RepoRoot"

## Generate code in sdk/template to prime the npx and npm cache
Push-Location "$RepoRoot/sdk/template/Azure.Template/src"
try {
Write-Host "Building then resetting sdk/template/Azure.Template/src"
Invoke-LoggedCommand "dotnet build /t:GenerateCode"
Invoke-LoggedCommand "git restore ."
Invoke-LoggedCommand "git clean . --force"
}
finally {
Pop-Location
}
Write-Host "Running npm ci over emitter-package.json in a temp folder to prime the npm cache"

## Run npm install over emitter-package.json in a temp folder to prime the npm cache
$tempFolder = New-TemporaryFile
$tempFolder | Remove-Item -Force
New-Item $tempFolder -ItemType Directory -Force | Out-Null
Expand All @@ -658,14 +647,10 @@ function Update-dotnet-GeneratedSdks([string]$PackageDirectoriesFile) {
$tempFolder | Remove-Item -Force -Recurse
}

Write-Host "##[endgroup]"

# Generate projects
$showSummary = ($env:SYSTEM_DEBUG -eq 'true') -or ($VerbosePreference -ne 'SilentlyContinue')
$summaryArgs = $showSummary ? "/v:n /ds" : ""

Invoke-LoggedCommand "npx autorest --version"

Invoke-LoggedCommand "dotnet msbuild /restore /t:GenerateCode /p:ProjectListOverrideFile=$(Resolve-Path $projectListOverrideFile -Relative) $summaryArgs eng\service.proj"
}
finally {
Expand Down
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "azure-sdk-for-net",
"version": "1.0.0",
"dependencies": {
"autorest": "^3.7.1"
}
}

0 comments on commit 3092f46

Please sign in to comment.