diff --git a/.github/actions/build-vsix/action.yml b/.github/actions/build-vsix/action.yml index 775d04f1..fb2e2027 100644 --- a/.github/actions/build-vsix/action.yml +++ b/.github/actions/build-vsix/action.yml @@ -35,8 +35,8 @@ runs: run: python -m pip install -U pip pipx wheel shell: bash - - name: Install Node dependencies through Microsoft feeds - run: npm run ci:msft + - name: Install Node dependencies + run: npm ci env: npm_config_prefer_offline: 'true' shell: bash diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 22a8ee0f..84469a6f 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -20,7 +20,7 @@ runs: shell: bash - name: Install Node dependencies - run: npm run ci:msft + run: npm ci shell: bash - name: Lint TypeScript code diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 0effe3b0..9e4016e1 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -20,10 +20,6 @@ on: schedule: - cron: '15 16 * * 2' -env: - NPM_CONFIG_REGISTRY: https://packagefeedproxy.microsoft.io/npm/ - PIP_INDEX_URL: https://packagefeedproxy.microsoft.io/pypi/simple/ - jobs: analyze: name: Analyze diff --git a/.github/workflows/info-needed-closer.yml b/.github/workflows/info-needed-closer.yml index f1db26d7..e74976c2 100644 --- a/.github/workflows/info-needed-closer.yml +++ b/.github/workflows/info-needed-closer.yml @@ -12,6 +12,9 @@ permissions: jobs: main: runs-on: ubuntu-latest + permissions: + contents: read + issues: write steps: - name: Checkout Actions uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/.github/workflows/issue-labels.yml b/.github/workflows/issue-labels.yml index bd034bbc..04496546 100644 --- a/.github/workflows/issue-labels.yml +++ b/.github/workflows/issue-labels.yml @@ -15,6 +15,9 @@ jobs: add-classify-label: name: "Add 'triage-needed' and remove assignees" runs-on: ubuntu-latest + permissions: + contents: read + issues: write steps: - name: Checkout Actions uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 diff --git a/.github/workflows/localization.yml b/.github/workflows/localization.yml index 8d50a03b..b07ce200 100644 --- a/.github/workflows/localization.yml +++ b/.github/workflows/localization.yml @@ -28,3 +28,4 @@ jobs: with: app-id: ${{ vars.PYTHON_LOCALIZATION_APP_ID }} private-key: ${{ secrets.PYTHON_LOCALIZATION_PRIVATE_KEY }} + npm-registry: https://registry.npmjs.org/ diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 47812b0c..f2b9994e 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -6,7 +6,6 @@ on: permissions: {} env: - PIP_INDEX_URL: https://packagefeedproxy.microsoft.io/pypi/simple/ NODE_VERSION: 22.17.0 TEST_RESULTS_DIRECTORY: . # Force a path with spaces and unicode chars to test extension works in these scenarios @@ -17,6 +16,8 @@ jobs: build-vsix: name: Create VSIX runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -31,6 +32,8 @@ jobs: lint: name: Lint runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -45,6 +48,8 @@ jobs: tests: name: Tests runs-on: ${{ matrix.os }} + permissions: + contents: read defaults: run: working-directory: ${{ env.special-working-directory }} @@ -85,7 +90,7 @@ jobs: cache-dependency-path: ${{ env.special-working-directory-relative }}/package-lock.json - name: Install dependencies (npm ci) - run: npm run ci:msft + run: npm ci # Now that the bundle is installed to target using python 3.9 # switch back the python we want to test with diff --git a/.github/workflows/push-check.yml b/.github/workflows/push-check.yml index c958f625..e8ae6510 100644 --- a/.github/workflows/push-check.yml +++ b/.github/workflows/push-check.yml @@ -11,7 +11,6 @@ on: permissions: {} env: - PIP_INDEX_URL: https://packagefeedproxy.microsoft.io/pypi/simple/ NODE_VERSION: 22.17.0 TEST_RESULTS_DIRECTORY: . # Force a path with spaces and unicode chars to test extension works in these scenarios @@ -22,6 +21,8 @@ jobs: build-vsix: name: Create VSIX runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -36,6 +37,8 @@ jobs: lint: name: Lint runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -50,6 +53,8 @@ jobs: tests: name: Tests runs-on: ${{ matrix.os }} + permissions: + contents: read defaults: run: working-directory: ${{ env.special-working-directory }} @@ -90,7 +95,7 @@ jobs: cache-dependency-path: ${{ env.special-working-directory-relative }}/package-lock.json - name: Install dependencies (npm ci) - run: npm run ci:msft + run: npm ci # Now that the bundle is installed to target using python 3.9 # switch back the python we want to test with diff --git a/README.md b/README.md index 75731974..fe1ed3aa 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The Debugpy Extension for Visual Studio Code collects usage data and sends it to ### Local package feeds -Use Node.js supported by this repository and Python 3.10 or later. Both setup commands create or reuse `.venv` and install the Python bundling tools. Choose the appropriate setup below before installing dependencies. Committed lockfiles use public npm URLs; Microsoft setup rewrites working copies for proxy installs. +Use Node.js supported by this repository and Python 3.10 or later. Both setup commands create or reuse `.venv` and install the Python bundling tools. Choose the appropriate setup below before installing dependencies. Committed lockfiles use public npm URLs; Microsoft setup rewrites working copies for Microsoft feed installs. #### Public contributors (non-Microsoft employees) @@ -75,13 +75,13 @@ For subsequent npm installs, use `npm ci`. Public contributors do not need the M > **Microsoft users only:** The commands in this section configure Microsoft package feeds. Public contributors should use the public setup above. -Use the Microsoft setup, which selects `https://packagefeedproxy.microsoft.io/npm/` and `https://packagefeedproxy.microsoft.io/pypi/simple/` for its child processes: +Use the Microsoft setup, which selects the `Pylance_PublicPackages` npm and PyPI feeds in `build/package-feeds.json`. Configure credentials for both feeds before running it; setup does not authenticate: ```bash npm run setup:msft ``` -Microsoft setup rewrites public npm and Yarn `resolved` URLs in the root `package-lock.json` to the npm proxy before running `npm ci`. Versions, integrity hashes, formatting, and private-feed URLs are preserved. The public setup leaves lockfiles unchanged. +Microsoft setup rewrites public npm and Yarn `resolved` URLs in the root `package-lock.json` to the Microsoft npm feed before running `npm ci`. Versions, integrity hashes, formatting, and private-feed URLs are preserved. The public setup leaves lockfiles unchanged. After pulling a new lockfile from GitHub, rerun `npm run setup:msft`, or run the dependency-free rewrite step alone before your next install/build: @@ -97,7 +97,7 @@ For subsequent root npm installs, use: npm run ci:msft ``` -This rewrites the root lockfile, then runs root `npm ci` with the proxy registry explicitly selected for package, audit, and metadata requests. Use `npm run setup:msft` for full setup, including Python dependencies. +This rewrites the root lockfile, then runs root `npm ci` with the Microsoft registry explicitly selected for package, audit, and metadata requests. Use `npm run setup:msft` for full setup, including Python dependencies. Local setup, lockfile rewriting, and `ci:msft` share the feed URLs in `build/package-feeds.json`. @@ -121,17 +121,11 @@ To normalize manually, run `npm run normalize-lockfile`, review the changes, and ### GitHub Actions package feeds -The PR and push workflows set `PIP_INDEX_URL` to `https://packagefeedproxy.microsoft.io/pypi/simple/` for pip and nox installs. Their Node installation steps select `https://packagefeedproxy.microsoft.io/npm/` explicitly through `npm run ci:msft`, so these workflows do not set `NPM_CONFIG_REGISTRY`. CodeQL retains both environment variables because its autobuild step does not use the install helper. The npm endpoint follows the [TypeScript CI package-feed-proxy job](https://github.com/microsoft/TypeScript/blob/main/.github/workflows/ci.yml). - -The shared lint and VSIX build actions and applicable PR/push test jobs use `npm run ci:msft`, rewriting working-copy lockfile URLs before installation and explicitly selecting the proxy for npm requests. Workflows do not commit these rewrites or change local registry configuration or Dependabot configuration. Existing dependency caches are retained; the VSIX build also retains its offline-cache preference. CodeQL retains workflow-level feed settings for its autobuild step. +GitHub Actions use public npm and PyPI without feed authentication, including for fork PRs. Localization explicitly selects public npm because the shared action defaults to a proxy. ### Azure release package feeds -The DevDiv Azure stable/prerelease pipelines pass the npm proxy to their build/publish templates using `customNPMRegistry`. Their dependency install steps use `npm run ci:msft` to rewrite the root npm lockfile and install through the proxy. - -Each Python bootstrap and bundled-library install step explicitly sets `PIP_INDEX_URL` from `PIP_PROXY_INDEX_URL`, selecting the pip proxy even when a template's authentication setup changes the job-level index. Release triggers, approval gates, signing, and publishing behavior are unchanged. - -Dependabot continues to use public registries and its existing update settings. Legacy Azure stable, prerelease, and validation definitions are unchanged. +The DevDiv stable and prerelease pipelines pass the `Pylance_PublicPackages` npm feed to the shared template, which authenticates npm and the `DevDiv/debugpy` Python feed before build steps. Release triggers, approval gates, signing, and publishing are unchanged. ### Localization @@ -139,7 +133,7 @@ The **Localization** GitHub workflow submits English strings using the [shared c Both paths use `microsoft/vscode-python-extensions-loc`, branch **`dev`**, with canonical extension ID **`ms-python.debugpy`**. English XLF is stored in `src/en/ms-python.debugpy` and handbacks in `out/ms-python.debugpy`. The action and Azure tooling checkout are pinned to the same reviewed revision. -Configure the `PYTHON_LOCALIZATION_APP_ID` Actions variable and `PYTHON_LOCALIZATION_PRIVATE_KEY` secret here, or grant access to organization-level credentials. The app needs Contents write access only to the localization drop; the caller's repository token stays read-only. The shared action uses the Microsoft npm proxy and pinned localization CLI. Authorize the literal `Github-Pylance` service connection for the [pipeline templates](https://github.com/microsoft/pylance-eng), translation, and shared-tooling repository resources in both release pipelines. +Configure the `PYTHON_LOCALIZATION_APP_ID` Actions variable and `PYTHON_LOCALIZATION_PRIVATE_KEY` secret here, or grant access to organization-level credentials. The app needs Contents write access only to the localization drop; the caller's repository token stays read-only. The shared action uses public npm and a pinned localization CLI. Authorize the literal `Github-Pylance` service connection for the [pipeline templates](https://github.com/microsoft/pylance-eng), translation, and shared-tooling repository resources in both release pipelines. Keep English `package.nls.json` tracked. Root `package.nls..json` and `l10n/` runtime files are generated, git-ignored release outputs. VSCE must include generated locale files despite Git ignores. Local builds are English-only unless translations are imported explicitly (debugger pre-built assets remain available, but the release import runs after their overlay and is authoritative). diff --git a/build/azure-devdiv-pipeline.pre-release.yml b/build/azure-devdiv-pipeline.pre-release.yml index 8ad15e48..7162ce31 100644 --- a/build/azure-devdiv-pipeline.pre-release.yml +++ b/build/azure-devdiv-pipeline.pre-release.yml @@ -33,10 +33,8 @@ variables: value: VSCode-python-debugger - name: VsixName value: python-debugger.vsix - - name: NPM_CONFIG_REGISTRY - value: 'https://packagefeedproxy.microsoft.io/npm/' - - name: PIP_PROXY_INDEX_URL - value: 'https://packagefeedproxy.microsoft.io/pypi/simple/' + - name: AZURE_ARTIFACTS_FEED + value: 'https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/Pylance_PublicPackages/npm/registry/' parameters: - name: publishExtension @@ -74,28 +72,20 @@ parameters: - name: buildSteps type: stepList default: - - script: npm run ci:msft + - script: npm ci displayName: Install NPM dependencies - script: python -m pip install -U pip displayName: Upgrade pip - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python -m pip install wheel displayName: Install wheel - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python -m pip install nox displayName: Install nox - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python -m nox --session install_bundled_libs displayName: Install Python dependencies - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python ./build/update_ext_version.py --for-publishing displayName: Update build number @@ -112,7 +102,7 @@ extends: buildPlatforms: ${{ parameters.buildPlatforms }} buildSteps: ${{ parameters.buildSteps }} standardizedVersioning: true - customNPMRegistry: $(NPM_CONFIG_REGISTRY) + customNPMRegistry: $(AZURE_ARTIFACTS_FEED) publishExtension: ${{ parameters.publishExtension }} teamName: $(TeamName) ghCreateTag: true diff --git a/build/azure-devdiv-pipeline.stable.yml b/build/azure-devdiv-pipeline.stable.yml index feaccba7..1aabf87d 100644 --- a/build/azure-devdiv-pipeline.stable.yml +++ b/build/azure-devdiv-pipeline.stable.yml @@ -28,10 +28,8 @@ variables: value: VSCode-python-debugger - name: VsixName value: python-debugger.vsix - - name: NPM_CONFIG_REGISTRY - value: 'https://packagefeedproxy.microsoft.io/npm/' - - name: PIP_PROXY_INDEX_URL - value: 'https://packagefeedproxy.microsoft.io/pypi/simple/' + - name: AZURE_ARTIFACTS_FEED + value: 'https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/Pylance_PublicPackages/npm/registry/' parameters: - name: publishExtension @@ -69,28 +67,20 @@ parameters: - name: buildSteps type: stepList default: - - script: npm run ci:msft + - script: npm ci displayName: Install NPM dependencies - script: python -m pip install -U pip displayName: Upgrade pip - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python -m pip install wheel displayName: Install wheel - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python -m pip install nox displayName: Install nox - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python -m nox --session install_bundled_libs displayName: Install Python dependencies - env: - PIP_INDEX_URL: $(PIP_PROXY_INDEX_URL) - script: python ./build/update_ext_version.py --release --for-publishing displayName: Update build number @@ -107,7 +97,7 @@ extends: buildPlatforms: ${{ parameters.buildPlatforms }} buildSteps: ${{ parameters.buildSteps }} standardizedVersioning: true - customNPMRegistry: $(NPM_CONFIG_REGISTRY) + customNPMRegistry: $(AZURE_ARTIFACTS_FEED) publishExtension: ${{ parameters.publishExtension }} teamName: $(TeamName) ghCreateTag: true diff --git a/build/package-feeds.json b/build/package-feeds.json index c32a71a0..e6bde26c 100644 --- a/build/package-feeds.json +++ b/build/package-feeds.json @@ -4,7 +4,7 @@ "pip": "https://pypi.org/simple/" }, "microsoft": { - "npm": "https://packagefeedproxy.microsoft.io/npm/", - "pip": "https://packagefeedproxy.microsoft.io/pypi/simple/" + "npm": "https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/Pylance_PublicPackages/npm/registry/", + "pip": "https://pkgs.dev.azure.com/devdiv/DevDiv/_packaging/Pylance_PublicPackages/pypi/simple/" } } diff --git a/build/setup-npm-registry.js b/build/setup-npm-registry.js index 8f084651..f902c595 100644 --- a/build/setup-npm-registry.js +++ b/build/setup-npm-registry.js @@ -6,7 +6,11 @@ const { readFileSync, writeFileSync } = require('node:fs'); const path = require('node:path'); const { microsoft } = require('./package-feeds.json'); -function rewritePackageLock(source) { +function normalizeRegistry(registry) { + return registry.endsWith('/') ? registry : `${registry}/`; +} + +function rewritePackageLock(source, registry = microsoft.npm) { const lockfile = JSON.parse(source); if ( ![2, 3].includes(lockfile.lockfileVersion) || @@ -17,18 +21,19 @@ function rewritePackageLock(source) { throw new Error('Expected an npm lockfile with lockfileVersion 2 or 3 and a packages section.'); } + const normalizedRegistry = normalizeRegistry(registry); return source.replace(/("resolved"\s*:\s*)("(?:\\.|[^"\\])*")/g, (match, prefix, encodedUrl) => { const url = JSON.parse(encodedUrl); - const rewritten = url.replace(/^https:\/\/registry\.(?:npmjs\.org|yarnpkg\.com)\//, microsoft.npm); + const rewritten = url.replace(/^https:\/\/registry\.(?:npmjs\.org|yarnpkg\.com)\//, normalizedRegistry); return rewritten === url ? match : prefix + JSON.stringify(rewritten); }); } -function rewritePackageLocks(root = path.resolve(__dirname, '..')) { +function rewritePackageLocks(root = path.resolve(__dirname, '..'), registry = microsoft.npm) { const files = [path.join(root, 'package-lock.json')]; const updates = files.map((file) => { const source = readFileSync(file, 'utf8'); - return { file, source, rewritten: rewritePackageLock(source) }; + return { file, source, rewritten: rewritePackageLock(source, registry) }; }); for (const { file, source, rewritten } of updates) { if (rewritten !== source) { @@ -48,13 +53,15 @@ if (require.main === module) { if (install && !process.env.npm_execpath) { throw new Error('Run npm install using npm run ci:msft.'); } - rewritePackageLocks(); + const registry = normalizeRegistry( + process.env.npm_config_registry || process.env.NPM_CONFIG_REGISTRY || microsoft.npm, + ); + rewritePackageLocks(undefined, registry); if (install) { - const result = spawnSync( - process.execPath, - [process.env.npm_execpath, 'ci', `--registry=${microsoft.npm}`], - { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }, - ); + const result = spawnSync(process.execPath, [process.env.npm_execpath, 'ci', `--registry=${registry}`], { + cwd: path.resolve(__dirname, '..'), + stdio: 'inherit', + }); if (result.error || result.signal || result.status !== 0) { const reason = result.error?.message || result.signal || `exit code ${result.status}`; const error = new Error(`npm ci failed: ${reason}`); diff --git a/build/setup-npm-registry.test.js b/build/setup-npm-registry.test.js index 3d7eae5c..485cb169 100644 --- a/build/setup-npm-registry.test.js +++ b/build/setup-npm-registry.test.js @@ -11,7 +11,7 @@ const { rewritePackageLock, rewritePackageLocks } = require('./setup-npm-registr const { normalizePackageLock } = require('./normalize-package-lock'); const publicRegistry = 'https://registry.npmjs.org/'; -const proxyRegistry = 'https://packagefeedproxy.microsoft.io/npm/'; +const microsoftRegistry = 'https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/Pylance_PublicPackages/npm/registry/'; const source = `${JSON.stringify( { lockfileVersion: 3, @@ -34,20 +34,27 @@ const source = `${JSON.stringify( test('rewrites public resolved URLs without changing versions, integrity or formatting', () => { const expected = source - .replaceAll(publicRegistry, proxyRegistry) - .replace('https://registry.yarnpkg.com/', proxyRegistry); + .replaceAll(publicRegistry, microsoftRegistry) + .replace('https://registry.yarnpkg.com/', microsoftRegistry); assert.equal(rewritePackageLock(source), expected); assert.equal(rewritePackageLock(expected), expected); assert.equal(normalizePackageLock(expected), source.replace('https://registry.yarnpkg.com/', publicRegistry)); }); +test('normalizes slashless registry overrides before rewriting resolved URLs', () => { + for (const registry of [publicRegistry, microsoftRegistry]) { + const expected = source.replaceAll(publicRegistry, registry).replace('https://registry.yarnpkg.com/', registry); + assert.equal(rewritePackageLock(source, registry.slice(0, -1)), expected); + } +}); + test('supports version 2 legacy dependencies as well as packages', () => { const legacy = JSON.stringify({ lockfileVersion: 2, packages: {}, dependencies: { example: { resolved: `${publicRegistry}example/-/example.tgz` } }, }); - assert.equal(rewritePackageLock(legacy), legacy.replace(publicRegistry, proxyRegistry)); + assert.equal(rewritePackageLock(legacy), legacy.replace(publicRegistry, microsoftRegistry)); }); test('preserves other fields, private feeds, Git dependencies and lookalike hosts', () => { @@ -100,12 +107,12 @@ test('missing or invalid root lockfile fails explicitly', (t) => { assert.throws(() => rewritePackageLocks(root), /Expected an npm lockfile/); }); -function runCli({ args = ['--ci'], npmCli = 'npm-cli.js', result = { status: 0 } } = {}) { +function runCli({ args = ['--ci'], npmCli = 'npm-cli.js', result = { status: 0 }, env = {} } = {}) { const calls = []; const errors = []; const process = { argv: ['node', 'setup-npm-registry.js', ...args], - env: { npm_execpath: npmCli }, + env: { npm_execpath: npmCli, ...env }, execPath: 'node', }; const module = { exports: {} }; @@ -113,7 +120,7 @@ function runCli({ args = ['--ci'], npmCli = 'npm-cli.js', result = { status: 0 } if (name === 'node:fs') { return { readFileSync: () => source, - writeFileSync: (file) => calls.push({ file }), + writeFileSync: (file, source) => calls.push({ file, source }), }; } if (name === 'node:child_process') { @@ -137,12 +144,12 @@ function runCli({ args = ['--ci'], npmCli = 'npm-cli.js', result = { status: 0 } return { calls, errors, process }; } -test('ci:msft rewrites the root lockfile before installing with the shared proxy registry', () => { +test('ci:msft rewrites the root lockfile before installing with the Microsoft registry', () => { const context = runCli(); assert.equal(context.calls.length, 2); assert.ok(context.calls[0].file.endsWith('package-lock.json')); assert.equal(context.calls[1].command, 'node'); - assert.deepEqual(context.calls[1].args, ['npm-cli.js', 'ci', `--registry=${proxyRegistry}`]); + assert.deepEqual(context.calls[1].args, ['npm-cli.js', 'ci', `--registry=${microsoftRegistry}`]); assert.equal(context.calls[1].cwd, path.resolve(__dirname, '..')); assert.equal(context.calls[1].stdio, 'inherit'); assert.equal(context.errors.length, 0); @@ -150,6 +157,33 @@ test('ci:msft rewrites the root lockfile before installing with the shared proxy assert.equal(scripts['ci:msft'], 'node ./build/setup-npm-registry.js --ci'); }); +test('ci:msft preserves template authentication for the configured internal registry', () => { + const registry = 'https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/Pylance_PublicPackages/npm/registry/'; + for (const settings of [ + { NPM_CONFIG_REGISTRY: registry }, + { npm_config_registry: registry }, + { NPM_CONFIG_REGISTRY: registry.slice(0, -1) }, + { npm_config_registry: registry.slice(0, -1) }, + { NPM_CONFIG_REGISTRY: 'https://stale.example/npm/', npm_config_registry: registry }, + ]) { + const env = { + ...settings, + NPM_CONFIG_USERCONFIG: path.join(tmpdir(), 'authenticated.npmrc'), + NODE_AUTH_TOKEN: 'test-token', + }; + const context = runCli({ env }); + const install = context.calls.at(-1); + assert.deepEqual(install.args, ['npm-cli.js', 'ci', `--registry=${registry}`]); + assert.equal(install.env, undefined); + assert.equal(context.process.env.NPM_CONFIG_USERCONFIG, env.NPM_CONFIG_USERCONFIG); + assert.equal(context.process.env.NODE_AUTH_TOKEN, env.NODE_AUTH_TOKEN); + for (const write of context.calls.slice(0, -1)) { + assert.equal(write.source, rewritePackageLock(source, registry)); + } + assert.equal(context.errors.length, 0); + } +}); + for (const result of [{ status: 7 }, { status: null, signal: 'SIGTERM' }, { error: new Error('not found') }]) { test(`ci:msft reports npm failure: ${result.signal || result.error?.message || result.status}`, () => { const context = runCli({ result }); diff --git a/build/setup.test.js b/build/setup.test.js index e75ac2f6..5ade924a 100644 --- a/build/setup.test.js +++ b/build/setup.test.js @@ -90,11 +90,15 @@ for (const platform of ['win32', 'linux']) { for (const call of calls) { assert.equal( call.env.npm_config_registry, - microsoft ? 'https://packagefeedproxy.microsoft.io/npm/' : 'https://registry.npmjs.org/', + microsoft + ? 'https://devdiv.pkgs.visualstudio.com/DevDiv/_packaging/Pylance_PublicPackages/npm/registry/' + : 'https://registry.npmjs.org/', ); assert.equal( call.env.PIP_INDEX_URL, - microsoft ? 'https://packagefeedproxy.microsoft.io/pypi/simple/' : 'https://pypi.org/simple/', + microsoft + ? 'https://pkgs.dev.azure.com/devdiv/DevDiv/_packaging/Pylance_PublicPackages/pypi/simple/' + : 'https://pypi.org/simple/', ); assert.equal(call.env.NPM_CONFIG_REGISTRY, undefined); assert.equal(call.env.HTTPS_PROXY, context.originalEnv.HTTPS_PROXY); @@ -178,18 +182,25 @@ test('Microsoft entry point selects the shared Microsoft setup implementation', assert.equal(scripts['setup:msft'], 'node ./build/setup-msft.js'); }); -test('PR and push installs use the npm helper without a redundant registry environment setting', () => { +test('CI uses public registries and releases use the authenticated feed', () => { const root = path.join(__dirname, '..'); - for (const file of ['pr-check.yml', 'push-check.yml']) { + for (const file of ['pr-check.yml', 'push-check.yml', 'codeql-analysis.yml']) { const workflow = readFileSync(path.join(root, '.github', 'workflows', file), 'utf8'); - assert.doesNotMatch(workflow, /^\s*NPM_CONFIG_REGISTRY:/m); - assert.match(workflow, /^\s*PIP_INDEX_URL: https:\/\/packagefeedproxy\.microsoft\.io\/pypi\/simple\//m); - assert.doesNotMatch(workflow, /^\s*run: npm ci\b/m); + assert.doesNotMatch( + workflow, + /packagefeedproxy\.microsoft\.io|authenticate-feeds|id-token: write|NPM_CONFIG_REGISTRY|PIP_INDEX_URL|npm run ci:msft/, + ); } for (const action of ['lint', 'build-vsix']) { const workflow = readFileSync(path.join(root, '.github', 'actions', action, 'action.yml'), 'utf8'); - assert.match(workflow, /^\s*run: npm run ci:msft\s*$/m); + assert.match(workflow, /^\s*run: npm ci\s*$/m); + assert.doesNotMatch(workflow, /authenticate-feeds|npm run ci:msft/); + } + const localization = readFileSync(path.join(root, '.github', 'workflows', 'localization.yml'), 'utf8'); + assert.match(localization, /^\s*npm-registry: https:\/\/registry\.npmjs\.org\/\s*$/m); + for (const release of ['stable', 'pre-release']) { + const pipeline = readFileSync(path.join(root, 'build', `azure-devdiv-pipeline.${release}.yml`), 'utf8'); + assert.doesNotMatch(pipeline, /packagefeedproxy\.microsoft\.io|PIP_PROXY_INDEX_URL/); + assert.match(pipeline, /customNPMRegistry: \$\(AZURE_ARTIFACTS_FEED\)/); } - const codeql = readFileSync(path.join(root, '.github', 'workflows', 'codeql-analysis.yml'), 'utf8'); - assert.match(codeql, /^\s*NPM_CONFIG_REGISTRY: https:\/\/packagefeedproxy\.microsoft\.io\/npm\//m); });