Skip to content

Commit

Permalink
Test generic typespec validation template
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr committed Oct 16, 2024
1 parent c9fa717 commit a553ecc
Show file tree
Hide file tree
Showing 19 changed files with 843 additions and 179 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pingme.txt
# TS/Node files
dist/
node_modules/
eng/packages/**/*.tgz

# MSBuild binary log files
msbuild.binlog
Expand Down
444 changes: 444 additions & 0 deletions eng/common/pipelines/templates/archetype-typespec-emitter.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
parameters:
- name: npmrcPath
type: string
- name: registryUrl
type: string

steps:
- pwsh: |
Write-Host "Creating .npmrc file ${{ parameters.npmrcPath }} for registry ${{ parameters.registryUrl }}"
$parentFolder = Split-Path -Path '${{ parameters.npmrcPath }}' -Parent
if (!(Test-Path $parentFolder)) {
Write-Host "Creating folder $parentFolder"
New-Item -Path $parentFolder -ItemType Directory | Out-Null
}
$content = "registry=${{ parameters.registryUrl }}`n`nalways-auth=true"
$content | Out-File '${{ parameters.npmrcPath }}'
displayName: 'Create .npmrc'
- task: npmAuthenticate@0
displayName: Authenticate .npmrc
inputs:
workingFile: ${{ parameters.npmrcPath }}
26 changes: 24 additions & 2 deletions eng/common/scripts/Helpers/CommandInvocation-Helpers.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
function Invoke-LoggedCommand($Command, $ExecutePath, [switch]$GroupOutput)
function Invoke-LoggedCommand
{
[CmdletBinding()]
param
(
[string] $Command,
[string] $ExecutePath,
[switch] $GroupOutput,
[int[]] $AllowedExitCodes = @(0)
)

$pipelineBuild = !!$env:TF_BUILD
$startTime = Get-Date

Expand All @@ -22,7 +31,7 @@ function Invoke-LoggedCommand($Command, $ExecutePath, [switch]$GroupOutput)
Write-Host "##[endgroup]"
}

if($LastExitCode -ne 0)
if($LastExitCode -notin $AllowedExitCodes)
{
if($pipelineBuild) {
Write-Error "##[error]Command failed to execute ($duration): $Command`n"
Expand All @@ -40,3 +49,16 @@ function Invoke-LoggedCommand($Command, $ExecutePath, [switch]$GroupOutput)
}
}
}

function Set-ConsoleEncoding
{
[CmdletBinding()]
param
(
[string] $Encoding = 'utf-8'
)

$outputEncoding = [System.Text.Encoding]::GetEncoding($Encoding)
[Console]::OutputEncoding = $outputEncoding
[Console]::InputEncoding = $outputEncoding
}
11 changes: 5 additions & 6 deletions eng/common/scripts/New-RegenerateMatrix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ param (
[int]$MinimumPerJob = 10,

[Parameter()]
[string]$OnlyTypespec
[string]$OnlyTypeSpec
)

. (Join-Path $PSScriptRoot common.ps1)
Expand Down Expand Up @@ -57,14 +57,13 @@ function Split-Items([array]$Items) {
New-Item -ItemType Directory -Path $OutputDirectory -Force | Out-Null

if (Test-Path "Function:$GetDirectoriesForGenerationFn") {
$directoriesForGeneration = &$GetDirectoriesForGenerationFn
$directoriesForGeneration = &$GetDirectoriesForGenerationFn -OnlyTypeSpec $OnlyTypespec
}
else {
$directoriesForGeneration = Get-ChildItem "$RepoRoot/sdk" -Directory | Get-ChildItem -Directory
}

if ($OnlyTypespec) {
$directoriesForGeneration = $directoriesForGeneration | Where-Object { Test-Path "$_/tsp-location.yaml" }
if ($OnlyTypespec) {
$directoriesForGeneration = $directoriesForGeneration | Where-Object { Test-Path "$_/tsp-location.yaml" }
}
}

[array]$packageDirectories = $directoriesForGeneration
Expand Down
1 change: 1 addition & 0 deletions eng/common/scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $EngScriptsDir = Join-Path $EngDir "scripts"
. (Join-Path $EngCommonScriptsDir artifact-metadata-parsing.ps1)
. (Join-Path $EngCommonScriptsDir "Helpers" git-helpers.ps1)
. (Join-Path $EngCommonScriptsDir "Helpers" Package-Helpers.ps1)
. (Join-Path $EngCommonScriptsDir "Helpers" CommandInvocation-Helpers.ps1)

# Setting expected from common languages settings
$Language = "Unknown"
Expand Down
6 changes: 5 additions & 1 deletion eng/common/scripts/typespec/New-EmitterPackageJson.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#Requires -Version 7.0
[CmdletBinding()]
param (
[parameter(Mandatory = $true)]
Expand Down Expand Up @@ -35,9 +36,12 @@ if ($OverridesPath) {

$devDependencies = [ordered]@{}

foreach ($package in $packageJson.peerDependencies.Keys | Sort-Object) {
$possiblyPinnedPackages = $packageJson['azure-sdk/emitter-package-json-pinning'] ?? $packageJson.peerDependencies.Keys;

foreach ($package in $possiblyPinnedPackages | Sort-Object) {
$pinnedVersion = $packageJson.devDependencies[$package]
if ($pinnedVersion -and -not $overrides[$package]) {
#We have a dev pinned version that isn't overridden by the overrides.json file
Write-Host "Pinning $package to $pinnedVersion"
$devDependencies[$package] = $pinnedVersion
}
Expand Down
2 changes: 2 additions & 0 deletions eng/packages/http-client-csharp/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
artifacts/
85 changes: 33 additions & 52 deletions eng/packages/http-client-csharp/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,39 @@ pr:
include:
- eng/packages/http-client-csharp

variables:
- template: /eng/pipelines/templates/variables/image.yml
parameters:
- name: BuildPrereleaseVersion
displayName: 'Build prerelease version'
type: boolean
default: true
- name: ShouldRegenrate
displayName: 'Should regenerate'
type: boolean
default: true
- name: UseTypeSpecNext
displayName: 'Use TypeSpec Next'
type: boolean
default: false
- name: PublishTo
displayName: 'Publish to'
type: string
default: 'devops'
values: ['none', 'devops', 'public']

extends:
template: /eng/pipelines/templates/stages/1es-redirect.yml
template: /eng/common/pipelines/templates/archetype-typespec-emitter.yml
parameters:
stages:
- stage: 'Build'
pool:
name: $(WINDOWSPOOL)
image: $(WINDOWSVMIMAGE)
os: windows
jobs:
- job: Build
timeoutInMinutes: 120
steps:
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
- task: UseDotNet@2
displayName: 'Use .NET Core SDK'
retryCountOnTaskFailure: 3
inputs:
useGlobalJson: true
performMultiLevelLookup: true
- task: NodeTool@0
displayName: "Install Node 18.x"
inputs:
versionSpec: '18.x'
- script: |
npm ci
displayName: "Install packages"
workingDirectory: $(Build.SourcesDirectory)/eng/packages/http-client-csharp
- script: |
npm ls -a
displayName: "List packages"
workingDirectory: $(Build.SourcesDirectory)/eng/packages/http-client-csharp
- script: |
npm run prettier
displayName: "Emitter format check"
workingDirectory: $(Build.SourcesDirectory)/eng/packages/http-client-csharp/emitter
- script: |
npm run lint
displayName: "Emitter linter check"
workingDirectory: $(Build.SourcesDirectory)/eng/packages/http-client-csharp/emitter
- script: |
npm run build
displayName: 'Build Azure csharp client emitter and generator'
workingDirectory: $(Build.SourcesDirectory)/eng/packages/http-client-csharp/
- pwsh: ./eng/packages/http-client-csharp/eng/scripts/CodeGenerationCheck.ps1
displayName: "Check if generated code is up-to-date"
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_MULTILEVEL_LOOKUP: 0
- pwsh: dotnet test $(Build.SourcesDirectory)/eng/packages/http-client-csharp/generator
displayName: "Run tests"
BuildPrereleaseVersion: ${{ parameters.BuildPrereleaseVersion }}
UseTypeSpecNext: ${{ parameters.UseTypeSpecNext }}
${{ if eq(variables['System.TeamProject'], 'internal') }}:
ShouldPublish: ${{ ne(parameters.PublishTo, 'none') }}
PublishPublic: ${{ eq(parameters.PublishTo, 'public') }}
PublishDependsOnTest: ${{ eq(parameters.PublishTo, 'public') }}

ShouldRegenrate: ${{ parameters.ShouldRegenrate }}
RegenerationJobCount: 5
MinimumPerJob: 10
OnlyGenerateTypespec: true
TestMatrix:
All:
TestArguments: -UnitTests -GenerationChecks -Filter .NET
27 changes: 0 additions & 27 deletions eng/packages/http-client-csharp/eng/scripts/Generate.ps1

This file was deleted.

59 changes: 0 additions & 59 deletions eng/packages/http-client-csharp/eng/scripts/Generation.psm1

This file was deleted.

9 changes: 0 additions & 9 deletions eng/packages/http-client-csharp/package-lock.json

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

35 changes: 18 additions & 17 deletions eng/packages/http-client-csharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"scripts": {
"clean": "rimraf ./dist ./emitter/temp && dotnet clean ./generator",
"build:emitter": "tsc -p ./emitter/tsconfig.build.json",
"build:generator": "dotnet build ./generator",
"build": "npm run build:emitter && npm run build:generator && copyfiles -u 5 ./node_modules/@typespec/http-client-csharp/dist/generator/Microsoft.Generator.CSharp.runtimeconfig.json ./dist/generator",
"build:generator": "dotnet build ./generator && copyfiles -u 5 ./node_modules/@typespec/http-client-csharp/dist/generator/Microsoft.Generator.CSharp.runtimeconfig.json ./dist/generator",
"build": "npm run build:emitter && npm run build:generator",
"test:emitter": "vitest run -c ./emitter/vitest.config.ts",
"test:generator": "dotnet test ./generator",
"test": "npm run test:emitter && npm run test:generator",
"test:generator": "dotnet test ./generator --logger \"trx;LogFileName=debug.trx\"",
"test": "npm run test:generator && npm run test:emitter",
"lint": "eslint . --max-warnings=0",
"lint:fix": "eslint . --fix",
"prettier:fix": "prettier --write --config .prettierrc.json ./**/*.ts",
Expand All @@ -25,24 +25,12 @@
"dependencies": {
"@typespec/http-client-csharp": "0.1.9-alpha.20241010.1"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.46.0 <1.0.0 || ~0.47.0-0",
"@azure-tools/typespec-client-generator-core": ">=0.46.0 <1.0.0 || ~0.47.0-0",
"@typespec/compiler": ">=0.60.0 <1.0.0 || ~0.61.0-0",
"@typespec/http": ">=0.60.0 <1.0.0 || ~0.61.0-0",
"@typespec/openapi": ">=0.60.0 <1.0.0 || ~0.61.0-0",
"@typespec/rest": ">=0.60.0 <1.0.0 || ~0.61.0-0",
"@typespec/versioning": ">=0.60.0 <1.0.0 || ~0.61.0-0"
},
"devDependencies": {
"@azure-tools/typespec-azure-core": "0.46.0",
"@azure-tools/typespec-client-generator-core": "0.46.2",
"@azure-tools/typespec-azure-resource-manager": "0.46.1",
"@azure-tools/typespec-azure-rulesets": "0.46.0",
"@azure-tools/typespec-autorest": "0.46.0",
"@eslint/js": "^9.2.0",
"@types/node": "~22.7.5",
"@types/prettier": "^2.6.3",
"@typespec/compiler": "0.60.0",
"@typespec/http": "0.60.0",
"@typespec/json-schema": "0.60.0",
Expand All @@ -51,6 +39,9 @@
"@typespec/rest": "0.60.0",
"@typespec/versioning": "0.60.0",
"@typespec/xml": "0.60.0",

"@types/node": "~22.7.5",
"@types/prettier": "^2.6.3",
"@vitest/coverage-v8": "^1.4.0",
"@vitest/ui": "^1.4.0",
"c8": "^9.1.0",
Expand All @@ -59,7 +50,17 @@
"vitest": "^1.4.0",
"copyfiles": "^2.4.1",
"eslint": "^8.57.0",
"@eslint/js": "^9.2.0",
"prettier": "~3.0.3",
"typescript-eslint": "^7.8.0"
}
},
"azure-sdk/emitter-package-json-pinning": [
"@azure-tools/typespec-azure-core",
"@azure-tools/typespec-client-generator-core",
"@typespec/compiler",
"@typespec/http",
"@typespec/openapi",
"@typespec/rest",
"@typespec/versioning"
]
}
Loading

0 comments on commit a553ecc

Please sign in to comment.