Path: blob/main/build/azure-pipelines/product-npm-package-validate.yml
5366 views
trigger: none12pr:3branches:4include: ["main"]56variables:7- name: NPM_REGISTRY8value: "https://pkgs.dev.azure.com/monacotools/Monaco/_packaging/vscode/npm/registry/"9- name: VSCODE_QUALITY10value: oss1112jobs:13- job: ValidateNpmPackages14displayName: Valiate NPM packages against Terrapin15pool:16name: 1es-ubuntu-22.04-x6417os: linux18timeoutInMinutes: 4000019variables:20VSCODE_ARCH: x6421steps:22- task: NodeTool@023inputs:24versionSource: fromFile25versionFilePath: .nvmrc2627- script: |28set -e29echo "Checking if package.json or package-lock.json files were modified..."3031# Get the list of changed files in the PR32git fetch origin main33CHANGED_FILES=$(git diff --name-only origin/main...HEAD)34echo "Changed files:"35echo "$CHANGED_FILES"3637# Check if package.json or package-lock.json are in the changed files38if echo "$CHANGED_FILES" | grep -E '(^|/)package(-lock)?\.json$'; then39echo "##vso[task.setvariable variable=SHOULD_VALIDATE]true"40echo "Package files were modified, proceeding with validation"41else42echo "##vso[task.setvariable variable=SHOULD_VALIDATE]false"43echo "No package files were modified, skipping validation"44echo "##vso[task.complete result=Succeeded;]Pipeline completed successfully - no package validation needed"45fi46displayName: Check if package files were modified4748- script: node build/setup-npm-registry.ts $NPM_REGISTRY49condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'), eq(variables['SHOULD_VALIDATE'], 'true'))50displayName: Setup NPM Registry5152- script: |53set -e54# Set the private NPM registry to the global npmrc file55# so that authentication works for subfolders like build/, remote/, extensions/ etc56# which does not have their own .npmrc file57echo "NPMRC Path: $(npm config get userconfig)"58echo "NPM Registry: $(npm config get registry)"59npm config set registry "$NPM_REGISTRY"60echo "##vso[task.setvariable variable=NPMRC_PATH]$(npm config get userconfig)"61condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'), eq(variables['SHOULD_VALIDATE'], 'true'))62displayName: Setup NPM6364- task: npmAuthenticate@065inputs:66workingFile: $(NPMRC_PATH)67condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'), eq(variables['SHOULD_VALIDATE'], 'true'))68displayName: Setup NPM Authentication6970- script: sudo apt update -y && sudo apt install -y build-essential pkg-config libx11-dev libx11-xcb-dev libxkbfile-dev libnotify-bin libkrb5-dev71displayName: Install build tools72condition: and(succeeded(), eq(variables['SHOULD_VALIDATE'], 'true'))7374- script: |75set -e7677for attempt in {1..12}; do78if [ $attempt -gt 1 ]; then79echo "Attempt $attempt: Waiting for 30 minutes before retrying..."80sleep 180081fi8283echo "Attempt $attempt: Running npm ci"84if npm i --ignore-scripts; then85if node build/npm/postinstall.ts; then86echo "npm i succeeded on attempt $attempt"87exit 088else89echo "node build/npm/postinstall.ts failed on attempt $attempt"90fi91else92echo "npm i failed on attempt $attempt"93fi94done9596echo "npm i failed after 12 attempts"97exit 198env:99npm_command: 'install --ignore-scripts'100ELECTRON_SKIP_BINARY_DOWNLOAD: 1101PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1102GITHUB_TOKEN: "$(github-distro-mixin-password)"103displayName: Install dependencies with retries104timeoutInMinutes: 400105condition: and(succeeded(), eq(variables['SHOULD_VALIDATE'], 'true'))106107- script: |108set -e109find . -name 'package-lock.json' -exec sed -i "s|$NPM_REGISTRY|https://registry.npmjs.org/|g" {} \;110displayName: Restore registry URLs in package-lock.json111condition: and(succeeded(), ne(variables['NPM_REGISTRY'], 'none'), eq(variables['SHOULD_VALIDATE'], 'true'))112113- script: .github/workflows/check-clean-git-state.sh114displayName: Check clean git state115condition: and(succeeded(), eq(variables['SHOULD_VALIDATE'], 'true'))116117118