diff --git a/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml b/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml new file mode 100644 index 0000000000..02e04dbbd5 --- /dev/null +++ b/eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml @@ -0,0 +1,42 @@ +parameters: + - name: npmrcPath + type: string + # When empty, defaults to the agent user's .npmrc ($HOME/.npmrc on + # Linux/macOS, %USERPROFILE%\.npmrc on Windows) so every subsequent + # npm / pnpm / npx call in the job inherits the registry + auth. + default: "" + - name: registryUrl + type: string + default: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/" + - name: CustomCondition + type: string + default: succeeded() + - name: ServiceConnection + type: string + default: "" + +steps: + - pwsh: | + $npmrcPath = '${{ parameters.npmrcPath }}' + if (-not $npmrcPath) { $npmrcPath = Join-Path $HOME '.npmrc' } + + Write-Host "Creating .npmrc file $npmrcPath for registry ${{ parameters.registryUrl }}" + $parentFolder = Split-Path -Path $npmrcPath -Parent + + if ($parentFolder -and -not (Test-Path $parentFolder)) { + Write-Host "Creating folder $parentFolder" + New-Item -Path $parentFolder -ItemType Directory | Out-Null + } + + "registry=${{ parameters.registryUrl }}" | Out-File $npmrcPath + Write-Host "##vso[task.setvariable variable=resolvedNpmrcPath]$npmrcPath" + Write-Host "##vso[task.setvariable variable=resolvedNpmRegistryUrl]${{ parameters.registryUrl }}" + displayName: "Create .npmrc" + condition: ${{ parameters.CustomCondition }} + + - task: npmAuthenticate@0 + displayName: Authenticate .npmrc + condition: ${{ parameters.CustomCondition }} + inputs: + workingFile: $(resolvedNpmrcPath) + azureDevOpsServiceConnection: ${{ parameters.ServiceConnection }} diff --git a/eng/pipelines/ci.yaml b/eng/pipelines/ci.yaml index ed9a4898a9..74a8ffdd9d 100644 --- a/eng/pipelines/ci.yaml +++ b/eng/pipelines/ci.yaml @@ -24,6 +24,8 @@ extends: - script: pnpm run test:ci displayName: Test + env: + autorest_registry: $(resolvedNpmRegistryUrl) - task: PublishCodeCoverageResults@2 inputs: diff --git a/eng/pipelines/templates/1es-redirect.yml b/eng/pipelines/templates/1es-redirect.yml index ebf7209d8b..102f39345f 100644 --- a/eng/pipelines/templates/1es-redirect.yml +++ b/eng/pipelines/templates/1es-redirect.yml @@ -27,6 +27,7 @@ extends: parameters: settings: skipBuildTagsForGitHubPullRequests: true + networkIsolationPolicy: Permissive, CFSClean authenticatedContainerRegistries: ${{ parameters.authenticatedContainerRegistries }} sdl: git: diff --git a/eng/pipelines/templates/build.yaml b/eng/pipelines/templates/build.yaml index 45715951a2..4e8522369d 100644 --- a/eng/pipelines/templates/build.yaml +++ b/eng/pipelines/templates/build.yaml @@ -5,8 +5,9 @@ steps: versionSpec: "22.x" displayName: "Install Node.js" - - script: corepack enable - displayName: "Enable corepack" + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + + - template: /eng/pipelines/templates/install-pnpm.yml - script: pnpm install --frozen-lockfile displayName: "Install dependencies" diff --git a/eng/pipelines/templates/install-pnpm.yml b/eng/pipelines/templates/install-pnpm.yml new file mode 100644 index 0000000000..c0aa81e312 --- /dev/null +++ b/eng/pipelines/templates/install-pnpm.yml @@ -0,0 +1,5 @@ +steps: + - pwsh: | + $packageJson = Get-Content -Raw "$(Build.SourcesDirectory)/package.json" | ConvertFrom-Json + npm install -g $packageJson.packageManager + displayName: Install pnpm diff --git a/eng/pipelines/templates/regression-tests.yaml b/eng/pipelines/templates/regression-tests.yaml index fe739b6c93..056fd7db5c 100644 --- a/eng/pipelines/templates/regression-tests.yaml +++ b/eng/pipelines/templates/regression-tests.yaml @@ -44,9 +44,14 @@ jobs: versionSpec: "3.11" displayName: "Use Python 3.11" + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + + - script: npm install -g npm + displayName: Install npm + + - template: /eng/pipelines/templates/install-pnpm.yml + - script: | - npm install -g npm - corepack enable pnpm install --frozen-lockfile pnpm run build displayName: Install and build @@ -70,8 +75,19 @@ jobs: displayName: Install dependencies workingDirectory: regression-tests + - task: PipAuthenticate@1 + displayName: "Pip Authenticate to feed" + inputs: + artifactFeeds: "public/azure-sdk-for-python" + onlyAddExtraIndex: false + - script: autorest-compare --compare:./regression-tests/regression-compare.yaml --language:python displayName: Regression Test - @autorest/python + env: + autorest_registry: $(resolvedNpmRegistryUrl) + PIP_INDEX_URL: https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/ - script: autorest-compare --compare:./regression-tests/regression-compare.yaml --language:typescript displayName: Regression Test - @autorest/typescript + env: + autorest_registry: $(resolvedNpmRegistryUrl) diff --git a/eng/pipelines/templates/smoke-tests.yaml b/eng/pipelines/templates/smoke-tests.yaml index 75db53a9c5..def89f36c8 100644 --- a/eng/pipelines/templates/smoke-tests.yaml +++ b/eng/pipelines/templates/smoke-tests.yaml @@ -38,6 +38,8 @@ jobs: versionSpec: ${{ parameters.nodeVersion }} displayName: "Install Node.js" + - template: /eng/common/pipelines/templates/steps/create-authenticated-npmrc.yml + - script: | # npm install -g autorest echo "Installing autorest from $AUTOREST_CLI_PKG" diff --git a/packages/libs/extension/src/main.ts b/packages/libs/extension/src/main.ts index b3ab05e0f2..bb57c349fd 100644 --- a/packages/libs/extension/src/main.ts +++ b/packages/libs/extension/src/main.ts @@ -213,7 +213,9 @@ export class ExtensionManager { * @returns List of semver versions */ public async getPackageVersions(name: string): Promise { - const packument = await pacote.packument(name); + const packument = await pacote.packument(name, { + registry: process.env.autorest_registry || "https://registry.npmjs.org", + }); return Object.keys(packument.versions); }