Skip to content

Commit

Permalink
migration from cadl-ranch to spector (#2977)
Browse files Browse the repository at this point in the history
* update cadl-ranch to spector

* update ignore

* Update dependencies (2024-12-18 06:19:16)

* Regenerate for typespec-python (2024-12-18 06:23:49)

* fix ci

* Fix ci

* review

* update package.json

* add changelog

* fix sub name in ci

* Rename subdirectory variables for clarity

* update internal-ci with specific coverage file name

* update internal-ci for spector coverage upload

* fix ci

---------

Co-authored-by: AutoPrFromHttpClientPython <AutoPrFromHttpClientPython>
Co-authored-by: Chenjie Shi <[email protected]>
  • Loading branch information
msyyc and tadelesh authored Jan 2, 2025
1 parent 156bf9b commit 720f248
Show file tree
Hide file tree
Showing 123 changed files with 11,149 additions and 1,179 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/auto-spector-migration-2024-11-19-16-4-12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-python"
---

Migrate cadl-ranch to spector
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
cadl-ranch/

# Translations
*.mo
Expand Down
4 changes: 0 additions & 4 deletions eng/pipelines/ci-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ steps:
displayName: Install TypeSpec
condition: and(succeeded(), ${{ parameters.installTypeSpec }})

- script: npm install -g @azure-tools/cadl-ranch
displayName: Install Cadl Ranch
condition: and(succeeded(), ${{ parameters.installCadlRanch }})

- script: npx @azure-tools/typespec-bump-deps package.json packages/typespec-python/package.json
displayName: Update typespec packages to latest dev version
workingDirectory: $(Build.SourcesDirectory)/autorest.python/
Expand Down
7 changes: 4 additions & 3 deletions eng/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ jobs:
package: "typespec-python"
folderName: "unbranded"

- script: cadl-ranch check-coverage http/
- script: tsp-spector check-coverage http/
displayName: Check Coverage
workingDirectory: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs
workingDirectory: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/azure-http-specs
continueOnError: true

- publish: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs/cadl-ranch-coverage.json
- publish: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/azure-http-specs/spec-coverage.json
artifact: CoverageReport
continueOnError: true
12 changes: 6 additions & 6 deletions eng/pipelines/internal-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ steps:
- task: AzureCLI@2
displayName: Upload scenario manifest for unbranded
inputs:
azureSubscription: "Cadl Ranch Storage"
azureSubscription: "TypeSpec Storage"
scriptType: "bash"
scriptLocation: "inlineScript"
inlineScript: cadl-ranch upload-coverage --generatorName python --storageAccountName azuresdkcadlranch --generatorVersion $(node -p -e "require('$(Build.SourcesDirectory)/autorest.python/packages/typespec-python/package.json').version") --generatorMode standard
workingDirectory: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs
inlineScript: npx tsp-spector upload-coverage --coverageFile ./spec-coverage.json --generatorName "@typespec/http-client-python" --storageAccountName typespec --generatorVersion $(node -p -e "require('$(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@typespec/http-client-python/package.json').version") --containerName coverages --generatorMode standard
workingDirectory: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/azure-http-specs

- script: |
tox run -e ci
Expand All @@ -44,8 +44,8 @@ steps:
- task: AzureCLI@2
displayName: Upload scenario manifest for azure
inputs:
azureSubscription: "Cadl Ranch Storage"
azureSubscription: "TypeSpec Storage"
scriptType: "bash"
scriptLocation: "inlineScript"
inlineScript: cadl-ranch upload-coverage --generatorName python --storageAccountName azuresdkcadlranch --generatorVersion $(node -p -e "require('$(Build.SourcesDirectory)/autorest.python/packages/typespec-python/package.json').version") --generatorMode azure
workingDirectory: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/cadl-ranch-specs
inlineScript: npx tsp-spector upload-coverage --coverageFile ./spec-coverage.json --generatorName "@azure-tools/typespec-python" --storageAccountName typespec --generatorVersion $(node -p -e "require('$(Build.SourcesDirectory)/autorest.python/packages/typespec-python/package.json').version") --containerName coverages --generatorMode azure
workingDirectory: $(Build.SourcesDirectory)/autorest.python/packages/typespec-python/node_modules/@azure-tools/azure-http-specs
3 changes: 0 additions & 3 deletions eng/pipelines/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ extends:
- script: npm install -g [email protected]
displayName: Install PNPM 9.5.0

- script: npm install -g @azure-tools/cadl-ranch
displayName: Install cadl ranch

- script: pnpm install
displayName: Install dependencies

Expand Down
5 changes: 2 additions & 3 deletions packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@
"@azure-tools/typespec-azure-rulesets": "~0.49.0",
"@azure-tools/typespec-autorest": "~0.49.0",
"@azure-tools/typespec-client-generator-core": "~0.49.0",
"@azure-tools/cadl-ranch-expect": "~0.15.7",
"@azure-tools/cadl-ranch-specs": "~0.39.6",
"@azure-tools/cadl-ranch": "~0.16.2",
"@azure-tools/azure-http-specs": "0.1.0-alpha.4",
"@typespec/http-specs": "0.1.0-alpha.5",
"@types/js-yaml": "~4.0.5",
"@types/node": "~22.5.4",
"@types/yargs": "~17.0.33",
Expand Down
14 changes: 9 additions & 5 deletions packages/typespec-python/scripts/eng/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const exec = promisify(execCallback);

// Get the directory of the current file
const PLUGIN_DIR = resolve(fileURLToPath(import.meta.url), "../../../");
const CADL_RANCH_DIR = resolve(PLUGIN_DIR, "node_modules/@azure-tools/cadl-ranch-specs/http");
const AZURE_HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@azure-tools/azure-http-specs/specs");
const HTTP_SPECS = resolve(PLUGIN_DIR, "node_modules/@typespec/http-specs/specs");
interface TspCommand {
outputDir: string;
command: string;
Expand Down Expand Up @@ -111,7 +112,8 @@ function toPosix(dir: string): string {
}

function getEmitterOption(spec: string): Record<string, string>[] {
const relativeSpec = toPosix(relative(CADL_RANCH_DIR, spec));
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
const relativeSpec = toPosix(relative(specDir, spec));
const key = relativeSpec.includes("resiliency/srv-driven/old.tsp") ? relativeSpec : dirname(relativeSpec);
const result = EMITTER_OPTIONS[key] || [{}];
return Array.isArray(result) ? result : [result];
Expand Down Expand Up @@ -205,7 +207,8 @@ async function getSubdirectories(baseDir: string, flags: RegenerateFlags): Promi
}

function defaultPackageName(spec: string): string {
return toPosix(relative(CADL_RANCH_DIR, dirname(spec)))
const specDir = spec.includes("azure") ? AZURE_HTTP_SPECS : HTTP_SPECS;
return toPosix(relative(specDir, dirname(spec)))
.replace(/\//g, "-")
.toLowerCase();
}
Expand Down Expand Up @@ -259,8 +262,9 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
await regenerate({ ...flags, flavor: "unbranded" });
} else {
const flagsResolved = { debug: false, flavor: flags.flavor, ...flags };
const CADL_RANCH_DIR = resolve(PLUGIN_DIR, "node_modules/@azure-tools/cadl-ranch-specs/http");
const subdirectories = await getSubdirectories(CADL_RANCH_DIR, flagsResolved);
const subdirectoriesForAzure = await getSubdirectories(AZURE_HTTP_SPECS, flagsResolved);
const subdirectoriesForNonAzure = await getSubdirectories(HTTP_SPECS, flagsResolved);
const subdirectories = [...subdirectoriesForAzure, ...subdirectoriesForNonAzure];
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
_getCmdList(subdirectory, flagsResolved),
);
Expand Down
Loading

0 comments on commit 720f248

Please sign in to comment.