diff --git a/eng/1es-redirect.yml b/eng/1es-redirect.yml index ab01ac4..769c103 100644 --- a/eng/1es-redirect.yml +++ b/eng/1es-redirect.yml @@ -36,6 +36,7 @@ extends: - 1ES.PT.Tag-refs/tags/canary settings: skipBuildTagsForGitHubPullRequests: true + networkIsolationPolicy: Permissive, CFSClean sdl: git: longpaths: true diff --git a/eng/test-steps.yml b/eng/test-steps.yml index a064524..11a9e5a 100644 --- a/eng/test-steps.yml +++ b/eng/test-steps.yml @@ -8,17 +8,30 @@ steps: - task: UseDotNet@2 inputs: version: 6.x + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + parameters: + npmrcPath: $(Agent.TempDirectory)/oad.npmrc + - script: npm ci displayName: npm ci + env: + NPM_CONFIG_USERCONFIG: $(Agent.TempDirectory)/oad.npmrc + - script: npm run lint displayName: lint + - script: npm run prettier displayName: prettier + - script: npm test displayName: test + env: + NPM_CONFIG_USERCONFIG: $(Agent.TempDirectory)/oad.npmrc + - script: npm pack displayName: pack + - task: CopyFiles@2 displayName: "Copy Files to Staging" inputs: diff --git a/src/lib/validators/openApiDiff.ts b/src/lib/validators/openApiDiff.ts index 363f2b2..3c1e19b 100644 --- a/src/lib/validators/openApiDiff.ts +++ b/src/lib/validators/openApiDiff.ts @@ -19,6 +19,16 @@ const _ = require("lodash") const execFile = util.promisify(child_process.execFile) +const getAutoRestNpmrcPath = (): string | undefined => { + const candidates = [process.env.npm_config_userconfig, process.env.NPM_CONFIG_USERCONFIG] + return candidates.find(value => typeof value === "string" && value.trim().length > 0) +} + +const getAutoRestCoreVersion = (): string => { + const configuredVersion = process.env.OAD_AUTOREST_CORE_VERSION?.trim() + return configuredVersion?.length ? configuredVersion : "3.10.9" +} + export type Options = { readonly consoleLogLevel?: unknown readonly logFilepath?: unknown @@ -232,8 +242,10 @@ export class OpenApiDiff { const swaggerArgs = tagName ? [swaggerPath, `--tag=${tagName}`] : [`--input-file=${swaggerPath}`] + const autoRestCoreVersion = getAutoRestCoreVersion() + const commonArgs = [ - "--v2", + `--version=${autoRestCoreVersion}`, "--output-artifact=swagger-document.json", "--output-artifact=swagger-document.map", `--output-file=${outputFileName}`, @@ -241,13 +253,24 @@ export class OpenApiDiff { ] const args = [...autoRestArgs, ...swaggerArgs, ...commonArgs] + const autoRestNpmrcPath = getAutoRestNpmrcPath() + const env = { + ...process.env, + NODE_OPTIONS: "--max-old-space-size=8192", + ...(autoRestNpmrcPath ? { npm_config_userconfig: autoRestNpmrcPath, NPM_CONFIG_USERCONFIG: autoRestNpmrcPath } : {}) + } + + if (autoRestNpmrcPath) { + log.debug(`Using npm user config for AutoRest: ${autoRestNpmrcPath}`) + } + log.debug(`Using AutoRest core version: ${autoRestCoreVersion}`) log.debug(`Executing: "${autoRestFile} ${args.join(" ")}"`) const { stderr } = await execFile(autoRestFile, args, { encoding: "utf8", maxBuffer: 1024 * 1024 * 64, - env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=8192" } + env }) if (stderr) { // autorest 3.8.0 emits deprecation message to stderr with exit code 0