From 0551990fa13e16de3ec3e0650d664fd718e4bec9 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 2 Apr 2024 16:38:32 -0700 Subject: [PATCH] PR checks perf improvements and organization (#568) Result when from 30-35min pipelines to under 20min - Use corepack to install pnpm: Faster and respect the pnpm version set in package.json instead of having another place to keep up to date - dependency cache - move swagger check to seperate job - upgrade to new code coverage task - Don't run core tests in ci - Move all consitency check to independent github action workflow(Makes it easier to see which one failed immediately without having to open devops and dig into the steps) --- .../improve-pr-speed-2024-3-2-0-21-51.md | 9 ++ .../improve-pr-speed-2024-3-2-3-18-19.md | 9 ++ .github/actions/setup/action.yml | 19 +++++ .github/workflows/consistency.yml | 85 +++++++++++++++++-- eng/pipelines/ci.yml | 2 +- eng/pipelines/jobs/build-and-test.yml | 50 +---------- eng/pipelines/jobs/e2e-job.yml | 9 +- eng/pipelines/jobs/policies.yml | 29 +++++++ eng/pipelines/jobs/publish-artifacts.yml | 1 + eng/pipelines/pr.yml | 28 +++--- eng/pipelines/templates/install.yml | 15 +++- eng/pipelines/templates/swagger-checks.yml | 22 ++--- eng/pipelines/templates/upload-coverage.yml | 8 +- package.json | 9 +- packages/samples/README.md | 2 +- packages/samples/package.json | 2 +- .../typespec-autorest-canonical/package.json | 2 +- .../src/openapi.ts | 21 ++--- .../vitest.config.ts | 9 +- packages/typespec-autorest/package.json | 2 +- packages/typespec-autorest/src/openapi.ts | 17 ++-- packages/typespec-autorest/vitest.config.ts | 22 ++--- packages/typespec-azure-core/package.json | 2 +- .../package.json | 4 +- .../typespec-azure-portal-core/package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- packages/typespec-service-csharp/package.json | 2 +- 28 files changed, 244 insertions(+), 142 deletions(-) create mode 100644 .chronus/changes/improve-pr-speed-2024-3-2-0-21-51.md create mode 100644 .chronus/changes/improve-pr-speed-2024-3-2-3-18-19.md create mode 100644 .github/actions/setup/action.yml create mode 100644 eng/pipelines/jobs/policies.yml diff --git a/.chronus/changes/improve-pr-speed-2024-3-2-0-21-51.md b/.chronus/changes/improve-pr-speed-2024-3-2-0-21-51.md new file mode 100644 index 0000000000..9457c164c5 --- /dev/null +++ b/.chronus/changes/improve-pr-speed-2024-3-2-0-21-51.md @@ -0,0 +1,9 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@azure-tools/typespec-autorest-canonical" + - "@azure-tools/typespec-autorest" +--- + +Small performance improvements diff --git a/.chronus/changes/improve-pr-speed-2024-3-2-3-18-19.md b/.chronus/changes/improve-pr-speed-2024-3-2-3-18-19.md new file mode 100644 index 0000000000..25d40e01e2 --- /dev/null +++ b/.chronus/changes/improve-pr-speed-2024-3-2-3-18-19.md @@ -0,0 +1,9 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: internal +packages: + - "@azure-tools/typespec-azure-core" + - "@azure-tools/typespec-azure-portal-core" + - "@azure-tools/typespec-azure-resource-manager" + - "@azure-tools/typespec-client-generator-core" +--- diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000000..8b9571678f --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,19 @@ +name: Install dependencies +description: Setup for node. pnpm and dependencies +inputs: + node-version: + required: false + description: Node version for setup-node + default: 20.x + +runs: + using: composite + + steps: + - name: Install pnpm + uses: pnpm/action-setup@v2 + + - name: Set node version to ${{ inputs.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} diff --git a/.github/workflows/consistency.yml b/.github/workflows/consistency.yml index 804efe5b91..5f4a441d3c 100644 --- a/.github/workflows/consistency.yml +++ b/.github/workflows/consistency.yml @@ -7,6 +7,7 @@ on: branches: ["main"] pull_request: branches: ["main"] + merge_group: workflow_dispatch: {} # A workflow run is made up of one or more jobs that can run sequentially or in parallel @@ -20,16 +21,11 @@ jobs: fetch-depth: 0 ## Needed for Changesets to find `main` branch submodules: recursive + - uses: ./.github/actions/setup + - run: git pull --force --no-tags origin main:main name: Get main ref - - name: Use Node.js 20.x - uses: actions/setup-node@v3 - with: - node-version: 20.x - - - uses: pnpm/action-setup@v2 - - run: pnpm install name: Install dependencies @@ -39,3 +35,78 @@ jobs: - run: node eng/scripts/validate-core-submodule.js name: Check that core submodule is merged to core repo + + # Validate spell check + spellcheck: + name: Spell check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: ./.github/actions/setup + + - run: pnpm install + name: Install dependencies + + - run: pnpm run cspell + name: Spell check + + # Validate formatting + format: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: ./.github/actions/setup + + - run: pnpm install + name: Install dependencies + + - run: pnpm --filter="@typespec/prettier-plugin-typespec..." run build + name: Build prettier plugin + + - run: pnpm run format:check + name: Check formatting + + # Lint + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: ./.github/actions/setup + + - run: pnpm install + name: Install dependencies + + - run: pnpm --filter="@typespec/eslint-plugin..." run build + name: Build prettier plugin + + - run: pnpm run lint + name: Lint + + # Verify Arm OpenAPI common types are up to date + common-types-up-to-date: + name: Common types up to date + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: ./.github/actions/setup + + - run: pnpm install + name: Install dependencies + + - run: node eng/scripts/download-common-types.js v3 + name: Swagger - Fetch common-types v3 + + - run: node eng/scripts/check-for-changed-files.js + name: Check Git Status For Changed Files diff --git a/eng/pipelines/ci.yml b/eng/pipelines/ci.yml index ac7099a670..d8cf2f49c4 100644 --- a/eng/pipelines/ci.yml +++ b/eng/pipelines/ci.yml @@ -41,7 +41,7 @@ extends: - template: /eng/pipelines/templates/build.yml@self - - script: pnpm run test-official + - script: pnpm run test:ci displayName: Test - template: /eng/pipelines/templates/upload-coverage.yml@self diff --git a/eng/pipelines/jobs/build-and-test.yml b/eng/pipelines/jobs/build-and-test.yml index d5094a280b..a9bdd9c435 100644 --- a/eng/pipelines/jobs/build-and-test.yml +++ b/eng/pipelines/jobs/build-and-test.yml @@ -14,58 +14,22 @@ steps: parameters: nodeVersion: ${{ parameters.nodeVersion }} - # Only running UI test on linux - - ${{ if ne(variables['Agent.OS'], 'Windows_NT') }}: - - template: /eng/pipelines/templates/install-browsers.yml - - - script: pnpm run check-version-mismatch - displayName: Check version mismatch - - template: /eng/pipelines/templates/build.yml - - script: pnpm run test-official + - script: pnpm run test:ci displayName: Test - template: /eng/pipelines/templates/upload-coverage.yml - - script: pnpm run check-format - displayName: Check Formatting - condition: ne(variables['Agent.OS'], 'Windows_NT') - - - script: pnpm run lint - displayName: Lint - condition: ne(variables['Agent.OS'], 'Windows_NT') - - - script: node eng/scripts/download-common-types.js v3 - displayName: Swagger - Fetch common-types v3 - condition: ne(variables['Agent.OS'], 'Windows_NT') - - script: node eng/scripts/check-for-changed-files.js displayName: Check Git Status For Changed Files - - script: pnpm run cspell - displayName: Spell check - condition: ne(variables['Agent.OS'], 'Windows_NT') - # Unlink node_modules folders to significantly improve performance of subsequent tasks # which need to walk the directory tree (and are hardcoded to follow symlinks). - script: pnpm run purge displayName: "Purge dependencies" condition: always() - # It's important for performance to pass "packages" as "searchFolder" to avoid looking under root "node_modules". - # PublishTestResults.searchFolder only supports absolute paths, not relative. - - task: PublishTestResults@2 - inputs: - testResultsFormat: "JUnit" - searchFolder: "$(System.DefaultWorkingDirectory)/core/packages" - testResultsFiles: "*/test-results.xml" - mergeTestResults: true - failTaskOnFailedTests: false - testRunTitle: "[CORE] Test os: ${{ parameters.osName }}, node: ${{ parameters.nodeVersion }}" - displayName: Publish core test results - condition: always() - - task: PublishTestResults@2 inputs: testResultsFormat: "JUnit" @@ -73,14 +37,6 @@ steps: testResultsFiles: "*/test-results.xml" mergeTestResults: true failTaskOnFailedTests: false - testRunTitle: "[NON-CORE] Test os: ${{ parameters.osName }}, node: ${{ parameters.nodeVersion }}" - displayName: Publish non-core test results + testRunTitle: "Test os: ${{ parameters.osName }}, node: ${{ parameters.nodeVersion }}" + displayName: Publish test results condition: always() - - # Disable for now as e2e test are disabled - REMOVE BEFORE MERGING - # - task: 1ES.PublishPipelineArtifact@1 - # displayName: Publish UI tests artifacts - # condition: ne(variables['Agent.OS'], 'Windows_NT') - # inputs: - # path: : ./core/packages/playground-website/test-results - # artifact: "uitestresults-${{ parameters.osName }}-node-${{ parameters.nodeVersion }}" diff --git a/eng/pipelines/jobs/e2e-job.yml b/eng/pipelines/jobs/e2e-job.yml index 27b123c637..86a2592323 100644 --- a/eng/pipelines/jobs/e2e-job.yml +++ b/eng/pipelines/jobs/e2e-job.yml @@ -1,5 +1,6 @@ jobs: - job: e2e + displayName: "E2E Tests" pool: name: $(LINUXPOOL) @@ -15,10 +16,12 @@ jobs: submodules: true - template: /eng/pipelines/templates/install.yml + - template: /eng/pipelines/templates/install-browsers.yml - template: /eng/pipelines/templates/build.yml - parameters: - nodeVersion: "20.x" - script: node packages/e2e-tests/e2e-tests.mjs - displayName: Run E2E tests + displayName: Cadl Ranch e2e tests + + - script: pnpm test:e2e + displayName: UI Tests diff --git a/eng/pipelines/jobs/policies.yml b/eng/pipelines/jobs/policies.yml new file mode 100644 index 0000000000..989239396e --- /dev/null +++ b/eng/pipelines/jobs/policies.yml @@ -0,0 +1,29 @@ +parameters: + +steps: + - checkout: self + submodules: true + + - template: /eng/pipelines/templates/install.yml + + - script: pnpm run check-version-mismatch + displayName: Check version mismatch + + - script: pnpm run check-format + displayName: Check Formatting + condition: ne(variables['Agent.OS'], 'Windows_NT') + + - script: pnpm run lint + displayName: Lint + condition: ne(variables['Agent.OS'], 'Windows_NT') + + - script: node eng/scripts/download-common-types.js v3 + displayName: Swagger - Fetch common-types v3 + condition: ne(variables['Agent.OS'], 'Windows_NT') + + - script: node eng/scripts/check-for-changed-files.js + displayName: Check Git Status For Changed Files + + - script: pnpm run cspell + displayName: Spell check + condition: ne(variables['Agent.OS'], 'Windows_NT') diff --git a/eng/pipelines/jobs/publish-artifacts.yml b/eng/pipelines/jobs/publish-artifacts.yml index f09efcbe06..2cf31da5d5 100644 --- a/eng/pipelines/jobs/publish-artifacts.yml +++ b/eng/pipelines/jobs/publish-artifacts.yml @@ -1,6 +1,7 @@ jobs: - job: publish_artifacts displayName: Publish Artifacts + condition: eq(variables['Build.Reason'], 'PullRequest') # Don't publish artifacts for merge queue builds variables: TYPESPEC_VS_CI_BUILD: true # Enable official Visual Studio extension build diff --git a/eng/pipelines/pr.yml b/eng/pipelines/pr.yml index 6eb3b7bb5a..6ecd8dd7c6 100644 --- a/eng/pipelines/pr.yml +++ b/eng/pipelines/pr.yml @@ -1,4 +1,7 @@ -trigger: none +trigger: + branches: # Used to trigger for GitHub merge queues + include: + - gh-readonly-queue/* pr: - main - release/* @@ -9,9 +12,9 @@ extends: variables: - template: /eng/pipelines/templates/variables/globals.yml@self stages: - - stage: Build_And_Test + - stage: CI jobs: - - job: Build_And_Test_Linux + - job: Linux variables: TYPESPEC_VS_CI_BUILD: true # Enable official Visual Studio extension build TYPESPEC_SKIP_DOCUSAURUS_BUILD: true # Disable docusaurus build @@ -35,11 +38,7 @@ extends: dotnetVersion: 8.0.x osName: linux - - template: /eng/pipelines/templates/swagger-checks.yml@self - parameters: - nodeVersion: $(nodeVersion) - - - job: Build_And_Test_Windows + - job: Windows variables: TYPESPEC_VS_CI_BUILD: true # Enable official Visual Studio extension build TYPESPEC_SKIP_DOCUSAURUS_BUILD: true # Disable docusaurus build @@ -63,9 +62,16 @@ extends: dotnetVersion: 8.0.x osName: windows + - template: /eng/pipelines/jobs/e2e-job.yml@self + - job: AutorestChecks + displayName: "Autorest Checks" + pool: + name: $(LINUXPOOL) + image: $(LINUXVMIMAGE) + os: linux + + steps: - template: /eng/pipelines/templates/swagger-checks.yml@self parameters: - nodeVersion: $(nodeVersion) - - - template: /eng/pipelines/jobs/e2e-job.yml@self + nodeVersion: 20.x - template: /eng/pipelines/jobs/publish-artifacts.yml@self diff --git a/eng/pipelines/templates/install.yml b/eng/pipelines/templates/install.yml index d24ab9fa1c..0717d63a82 100644 --- a/eng/pipelines/templates/install.yml +++ b/eng/pipelines/templates/install.yml @@ -3,7 +3,9 @@ parameters: - name: nodeVersion type: string default: 20.x - + - name: pnpmStorePath + type: string + default: $(Pipeline.Workspace)/.pnpm-store steps: - task: UseDotNet@2 inputs: @@ -15,8 +17,17 @@ steps: displayName: Install Node.js retryCountOnTaskFailure: 3 - - script: npm install -g pnpm@8.13.1 + - task: Cache@2 + inputs: + key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml' + path: ${{ parameters.pnpmStorePath }} + displayName: Cache pnpm store + - script: | + corepack enable + corepack prepare pnpm@latest-8 --activate displayName: Install pnpm + - script: pnpm config set store-dir ${{ parameters.pnpmStorePath }} + displayName: Setup pnpm cache dir - script: | echo "Node:" diff --git a/eng/pipelines/templates/swagger-checks.yml b/eng/pipelines/templates/swagger-checks.yml index 5a96d6d3f5..c8a8addca5 100644 --- a/eng/pipelines/templates/swagger-checks.yml +++ b/eng/pipelines/templates/swagger-checks.yml @@ -3,21 +3,21 @@ parameters: type: string steps: - - bash: | - NodeVer=$(node -v) - echo "##vso[task.setvariable variable=nodeBase]${NodeVer}" - displayName: Swagger - Set execution variable - - script: | - npm install -g autorest && cd eng/scripts && npm install - echo "nodeBase:" $NODEBASE + - checkout: self + submodules: true + + - template: /eng/pipelines/templates/install.yml + parameters: + nodeVersion: ${{ parameters.nodeVersion }} + + - script: pnpm --filter "@typespec/internal-build-utils..." run build + displayName: Build internal tools + + - script: npm install -g autorest && cd eng/scripts && npm install displayName: Swagger - Install Dependencies - condition: and(succeeded(), contains(variables.nodeBase, 'v18'), ne(variables['Agent.OS'], 'Windows_NT')) - script: node eng/scripts/lint-resourcemanager.js "packages/samples/test/output/azure/resource-manager" displayName: Swagger - Resource Manager Linting - condition: and(succeeded(), contains(variables.nodeBase, 'v18'), ne(variables['Agent.OS'], 'Windows_NT')) - script: node eng/scripts/gen-sdk.js python "packages/samples/test/output/azure/resource-manager" displayName: Swagger - Generate Python SDK - condition: and(succeeded(), contains(variables.nodeBase, 'v18'), ne(variables['Agent.OS'], 'Windows_NT')) - script: node eng/scripts/gen-sdk.js javascript "packages/samples/test/output/azure/resource-manager" displayName: Swagger - Generate JavaScript SDK - condition: and(succeeded(), contains(variables.nodeBase, 'v18'), ne(variables['Agent.OS'], 'Windows_NT')) diff --git a/eng/pipelines/templates/upload-coverage.yml b/eng/pipelines/templates/upload-coverage.yml index 198bb63725..f909f1435c 100644 --- a/eng/pipelines/templates/upload-coverage.yml +++ b/eng/pipelines/templates/upload-coverage.yml @@ -1,9 +1,5 @@ steps: - - script: pnpm run merge-coverage - displayName: Merge code coverage - - - task: PublishCodeCoverageResults@1 + - task: PublishCodeCoverageResults@2 inputs: - codeCoverageTool: "Cobertura" - summaryFileLocation: $(Build.SourcesDirectory)/coverage/cobertura-coverage.xml + summaryFileLocation: $(Build.SourcesDirectory)/packages/*/coverage/cobertura-coverage.xml displayName: Publish code coverage diff --git a/package.json b/package.json index 9719d307a2..4e32b69a5d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "scripts": { "run-all": "pnpm -r --filter=!./core/", "build": "pnpm run-all --workspace-concurrency=Infinity --aggregate-output --reporter=append-only build ", - "check-format": "pnpm run prettier --check", "check-version-mismatch": "syncpack list-mismatches", "change": "chronus", "clean": "pnpm run-all run clean", @@ -14,8 +13,8 @@ "dogfood": "pnpm install && pnpm build && pnpm run-all dogfood", "fix-version-mismatch": "syncpack fix-mismatches", "format": "pnpm run prettier --write", + "format:check": "pnpm run prettier --check", "lint": "pnpm run-all --parallel --aggregate-output --reporter=append-only run lint", - "merge-coverage": "c8 -- report --reporter=cobertura --reporter=text", "pack:all": "chronus pack --pack-destination ./temp/artifacts", "preinstall": "npx only-allow pnpm", "prepare-publish": "node ./eng/scripts/prepare-publish.js", @@ -23,9 +22,9 @@ "purge": "rimraf --glob \"packages/*/node_modules/\" --glob \"core/packages/*/node_modules/\"", "regen-docs": "pnpm run-all --parallel --aggregate-output --reporter=append-only run regen-docs", "regen-samples": "pnpm run-all run regen-samples", - "test-official": "pnpm run-all --aggregate-output --reporter=append-only test-official", - "test:e2e": "pnpm run-all run e2e", - "test": "pnpm run-all --aggregate-output --reporter=append-only run test", + "test:ci": "pnpm -r --filter=!./core/ --filter=!./core/** --aggregate-output --reporter=append-only --sequential test:ci", + "test:e2e": "pnpm run-all run test:e2e", + "test": "pnpm run-all run test", "update-latest-docs": "pnpm run-all run update-latest-docs", "watch": "tsc --build ./tsconfig.ws.json --watch" }, diff --git a/packages/samples/README.md b/packages/samples/README.md index 0840408dc0..f382cc7ff0 100644 --- a/packages/samples/README.md +++ b/packages/samples/README.md @@ -2,7 +2,7 @@ ```bash npm run test # Check Samples match snapshots -npm run test-official # run test same as CI +npm run test:ci # run test same as CI npm run test:regen -- -g "" # Regen of this name diff --git a/packages/samples/package.json b/packages/samples/package.json index 58b059ae27..7d4ade9844 100644 --- a/packages/samples/package.json +++ b/packages/samples/package.json @@ -28,7 +28,7 @@ "watch": "tsc -p . --watch", "test": "vitest run", "test:watch": "vitest -w", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "test:regen": "cross-env RECORD=true vitest run", "regen-samples": "cross-env RECORD=true vitest run" }, diff --git a/packages/typespec-autorest-canonical/package.json b/packages/typespec-autorest-canonical/package.json index 5f43305497..cc4e42a900 100644 --- a/packages/typespec-autorest-canonical/package.json +++ b/packages/typespec-autorest-canonical/package.json @@ -42,7 +42,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/emitters/typespec-autorest-canonical/reference" diff --git a/packages/typespec-autorest-canonical/src/openapi.ts b/packages/typespec-autorest-canonical/src/openapi.ts index 3ab853f947..41ce9918fe 100644 --- a/packages/typespec-autorest-canonical/src/openapi.ts +++ b/packages/typespec-autorest-canonical/src/openapi.ts @@ -28,7 +28,6 @@ import { NumericLiteral, Operation, Program, - ProjectedNameView, Scalar, Service, StringLiteral, @@ -40,7 +39,6 @@ import { Union, UnionVariant, compilerAssert, - createProjectedNameProgram, emitFile, getAllTags, getDiscriminator, @@ -56,6 +54,7 @@ import { getMinValue, getNamespaceFullName, getPattern, + getProjectedName, getProperty, getPropertyType, getService, @@ -309,8 +308,6 @@ function createOAPIEmitter( const globalConsumes = new Set(["application/json"]); let outputFile: string; - let jsonView: ProjectedNameView; - let clientView: ProjectedNameView; let context: AutorestCanonicalEmitterContext; async function emitOpenAPI() { @@ -320,8 +317,6 @@ function createOAPIEmitter( } for (const service of services) { currentService = service; - jsonView = createProjectedNameProgram(program, "json"); - clientView = createProjectedNameProgram(program, "client"); context = { program, service, @@ -936,19 +931,19 @@ function createOAPIEmitter( return placeholder; } - function getJsonName(type: Type & { name: string }) { - const viaProjection = jsonView.getProjectedName(type); + function getJsonName(type: Type & { name: string }): string { + const viaProjection = getProjectedName(program, type, "json"); const encodedName = resolveEncodedName(program, type, "application/json"); // Pick the value set via `encodedName` or default back to the legacy projection otherwise. // `resolveEncodedName` will return the original name if no @encodedName so we have to do that check - return encodedName === type.name ? viaProjection : encodedName; + return encodedName === type.name ? viaProjection ?? type.name : encodedName; } function getClientName(type: Type & { name: string }): string { - const viaProjection = clientView.getProjectedName(type); + const viaProjection = getProjectedName(program, type, "client"); const clientName = getClientNameOverride(tcgcSdkContext, type); - return clientName ?? viaProjection; + return clientName ?? viaProjection ?? type.name; } function emitEndpointParameters(methodParams: HttpOperationParameters, visibility: Visibility) { @@ -1557,8 +1552,8 @@ function createOAPIEmitter( continue; } - const jsonName = jsonView.getProjectedName(prop); - const clientName = clientView.getProjectedName(prop); + const jsonName = getJsonName(prop); + const clientName = getClientName(prop); const description = getDoc(program, prop); diff --git a/packages/typespec-autorest-canonical/vitest.config.ts b/packages/typespec-autorest-canonical/vitest.config.ts index 3bddbdcd20..dd8d9aa35f 100644 --- a/packages/typespec-autorest-canonical/vitest.config.ts +++ b/packages/typespec-autorest-canonical/vitest.config.ts @@ -1,4 +1,11 @@ import { defineConfig, mergeConfig } from "vitest/config"; import { defaultTypeSpecVitestConfig } from "../../core/vitest.workspace"; -export default mergeConfig(defaultTypeSpecVitestConfig, defineConfig({})); +export default mergeConfig( + defaultTypeSpecVitestConfig, + defineConfig({ + test: { + testTimeout: 10000, + }, + }) +); diff --git a/packages/typespec-autorest/package.json b/packages/typespec-autorest/package.json index 07ae46dc1e..540a3add66 100644 --- a/packages/typespec-autorest/package.json +++ b/packages/typespec-autorest/package.json @@ -42,7 +42,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/emitters/typespec-autorest/reference" diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index b0a4ca4e49..ed616d2145 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -31,7 +31,6 @@ import { NumericLiteral, Operation, Program, - ProjectedNameView, Scalar, Service, StringLiteral, @@ -43,7 +42,6 @@ import { Union, UnionVariant, compilerAssert, - createProjectedNameProgram, emitFile, getAllTags, getDirectoryPath, @@ -60,6 +58,7 @@ import { getMinValue, getNamespaceFullName, getPattern, + getProjectedName, getProperty, getPropertyType, getRelativePathFromDirectory, @@ -320,8 +319,6 @@ function createOAPIEmitter( let operationExamplesMap: Map; let operationIdsWithExample: Set; let outputFile: string; - let jsonView: ProjectedNameView; - let clientView: ProjectedNameView; let context: AutorestEmitterContext; async function emitOpenAPI() { @@ -340,8 +337,6 @@ function createOAPIEmitter( if (record.projections.length > 0) { projectedProgram = program = projectProgram(originalProgram, record.projections); } - jsonView = createProjectedNameProgram(program, "json"); - clientView = createProjectedNameProgram(program, "client"); context = { program, service, @@ -1019,19 +1014,19 @@ function createOAPIEmitter( return placeholder; } - function getJsonName(type: Type & { name: string }) { - const viaProjection = jsonView.getProjectedName(type); + function getJsonName(type: Type & { name: string }): string { + const viaProjection = getProjectedName(program, type, "json"); const encodedName = resolveEncodedName(program, type, "application/json"); // Pick the value set via `encodedName` or default back to the legacy projection otherwise. // `resolveEncodedName` will return the original name if no @encodedName so we have to do that check - return encodedName === type.name ? viaProjection : encodedName; + return encodedName === type.name ? viaProjection ?? type.name : encodedName; } function getClientName(type: Type & { name: string }): string { - const viaProjection = clientView.getProjectedName(type); + const viaProjection = getProjectedName(program, type, "client"); const clientName = getClientNameOverride(tcgcSdkContext, type); - return clientName ?? viaProjection; + return clientName ?? viaProjection ?? type.name; } function emitEndpointParameters(methodParams: HttpOperationParameters, visibility: Visibility) { diff --git a/packages/typespec-autorest/vitest.config.ts b/packages/typespec-autorest/vitest.config.ts index bd5b317b12..dd8d9aa35f 100644 --- a/packages/typespec-autorest/vitest.config.ts +++ b/packages/typespec-autorest/vitest.config.ts @@ -1,15 +1,11 @@ -import { defineConfig } from "vitest/config"; +import { defineConfig, mergeConfig } from "vitest/config"; -export default defineConfig({ - test: { - environment: "node", - testTimeout: 10000, - isolate: false, - coverage: { - reporter: ["cobertura", "json", "text"], +import { defaultTypeSpecVitestConfig } from "../../core/vitest.workspace"; +export default mergeConfig( + defaultTypeSpecVitestConfig, + defineConfig({ + test: { + testTimeout: 10000, }, - outputFile: { - junit: "./test-results.xml", - }, - }, -}); + }) +); diff --git a/packages/typespec-azure-core/package.json b/packages/typespec-azure-core/package.json index 02ffa4ffe9..711ec8e8c8 100644 --- a/packages/typespec-azure-core/package.json +++ b/packages/typespec-azure-core/package.json @@ -41,7 +41,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/azure-core/reference" diff --git a/packages/typespec-azure-playground-website/package.json b/packages/typespec-azure-playground-website/package.json index 92cbe1e9ae..03e3947b07 100644 --- a/packages/typespec-azure-playground-website/package.json +++ b/packages/typespec-azure-playground-website/package.json @@ -39,8 +39,8 @@ "test": "vitest run", "test:watch": "vitest -w", "watch": "vite --port 5174", - "e2e": "cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test -c e2e", - "e2e:headed": "cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test -c e2e --headed", + "test:e2e": "cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test -c e2e", + "test:e2e:headed": "cross-env PW_EXPERIMENTAL_TS_ESM=1 playwright test -c e2e --headed", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts" }, diff --git a/packages/typespec-azure-portal-core/package.json b/packages/typespec-azure-portal-core/package.json index 6183832bbf..17d3d634da 100644 --- a/packages/typespec-azure-portal-core/package.json +++ b/packages/typespec-azure-portal-core/package.json @@ -14,7 +14,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/azure-portal-core/reference" diff --git a/packages/typespec-azure-resource-manager/package.json b/packages/typespec-azure-resource-manager/package.json index 9d5bd2b0df..ad50f1501d 100644 --- a/packages/typespec-azure-resource-manager/package.json +++ b/packages/typespec-azure-resource-manager/package.json @@ -41,7 +41,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/azure-resource-manager/reference" diff --git a/packages/typespec-client-generator-core/package.json b/packages/typespec-client-generator-core/package.json index e1e26f1ec9..7ec4ac0625 100644 --- a/packages/typespec-client-generator-core/package.json +++ b/packages/typespec-client-generator-core/package.json @@ -42,7 +42,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/typespec-client-generator-core/reference" diff --git a/packages/typespec-service-csharp/package.json b/packages/typespec-service-csharp/package.json index e3fbdee4ab..062d600456 100644 --- a/packages/typespec-service-csharp/package.json +++ b/packages/typespec-service-csharp/package.json @@ -35,7 +35,7 @@ "test": "vitest run", "test:watch": "vitest -w", "test:ui": "vitest --ui", - "test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism", + "test:ci": "vitest run --coverage --reporter=junit --reporter=default", "lint": "eslint . --ext .ts --max-warnings=0", "lint:fix": "eslint . --fix --ext .ts", "regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/emitters/typespec-service-csharp/reference"