From 2b95e8b1c9f13d0c5f45114059d3c600b3628ddd Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Wed, 28 May 2025 13:40:21 +0200 Subject: [PATCH 1/2] Add check versions CI step --- ci/build-common-packages.yml | 4 ++ ci/check-versions.js | 92 ++++++++++++++++++++++++++++++++++++ tsconfig.json | 17 +++++++ 3 files changed, 113 insertions(+) create mode 100644 ci/check-versions.js create mode 100644 tsconfig.json diff --git a/ci/build-common-packages.yml b/ci/build-common-packages.yml index 2578bf61..56ed460f 100644 --- a/ci/build-common-packages.yml +++ b/ci/build-common-packages.yml @@ -31,6 +31,10 @@ jobs: displayName: Verify task source changes condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main')) + - script: node ./ci/check-versions.js + displayName: Verify tasks' versions + condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main')) + - script: | npm run test displayName: Test Common Npm packages diff --git a/ci/check-versions.js b/ci/check-versions.js new file mode 100644 index 00000000..8e660684 --- /dev/null +++ b/ci/check-versions.js @@ -0,0 +1,92 @@ +const { execSync } = require('node:child_process'); +const { readFileSync } = require('node:fs'); +const { join } = require('node:path'); +const { styleText } = require('node:util'); + +const packages = [ + 'artifacts-common', + 'az-blobstorage-provider', + 'azure-arm-rest', + 'azurermdeploycommon', + 'codeanalysis-common', + 'codecoverage-tools', + 'docker-common', + 'ios-signing-common', + 'java-common', + 'kubernetes-common', + 'msbuildhelpers', + 'packaging-common', + 'securefiles-common', + 'utility-common', + 'webdeployment-common', +]; + +const gitDiffResult = execSync('git diff --name-only main', { encoding: 'utf8' }).split('\n'); +const changedFolders = new Set(); + +for (const filePath of gitDiffResult) { + for (const pkg of packages) { + // Check if the file path starts with the package folder name + if (filePath.startsWith(`common-npm-packages/${pkg}/`)) { + changedFolders.add(pkg); + } + } +} + +if (changedFolders.size > 0) { + const errors = []; + + for (const pkg of changedFolders) { + const pkgJsonPath = join(__dirname, '../common-npm-packages', pkg, 'package.json'); + try { + const pkgJson = JSON.parse(readFileSync(pkgJsonPath, 'utf8')); + const currentVersion = pkgJson.version; + // Get package.json from main branch + let mainVersion = null; + try { + const mainPkgJsonRaw = execSync(`git show main:common-npm-packages/${pkg}/package.json`, { encoding: 'utf8' }); + const mainPkgJson = JSON.parse(mainPkgJsonRaw); + mainVersion = mainPkgJson.version; + } catch (err) { + // If package.json doesn't exist in main, treat as new package + } + + if (mainVersion && compareVersions(mainVersion, currentVersion) >= 0) { + errors.push({ + pkg, + mainVersion, + currentVersion + }); + } + } catch (err) { + console.warn(`Could not read version for ${pkg}:`, err.message); + } + } + if (errors.length > 0) { + console.error(styleText('red', 'Error: The following packages have not been updated correctly:')); + errors.forEach(error => { + console.error(`Local version ${styleText('green', error.currentVersion)} <= main version ${styleText('redBright', error.mainVersion)} for package ${styleText('blueBright', error.pkg)}.`); + }); + process.exit(1); + } +} else { + console.log('No changed package folders detected.'); +} + +/** + * Compare two semver strings. Returns 1 if a > b, 0 if a == b, -1 if a < b + * @param {string} a - The first version string to compare + * @param {string} b - The second version string to compare + * @returns + */ +function compareVersions(a, b) { + const pa = a.split('.').map(Number); + const pb = b.split('.').map(Number); + for (let i = 0; i < Math.max(pa.length, pb.length); i++) { + const na = pa[i] || 0; + const nb = pb[i] || 0; + if (na > nb) return 1; + if (na < nb) return -1; + } + return 0; +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..2fdc2e26 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noEmit": true, + "skipLibCheck": true, + "allowJs": true, + "checkJs": true, + "useUnknownInCatchVariables": false + }, + "include": [ + "ci" + ] +} From 3580c2a71563cdadd580b21824b647c1e8f17439 Mon Sep 17 00:00:00 2001 From: Ivan Duplenskikh <115665590+ivanduplenskikh@users.noreply.github.com> Date: Mon, 2 Jun 2025 14:18:00 +0200 Subject: [PATCH 2/2] Update --- ci/build-common-packages.yml | 23 ++++++++----------- ci/check-versions.js | 2 +- .../webdeployment-common/webconfigutil.ts | 5 ++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/ci/build-common-packages.yml b/ci/build-common-packages.yml index 56ed460f..377529a4 100644 --- a/ci/build-common-packages.yml +++ b/ci/build-common-packages.yml @@ -18,25 +18,21 @@ jobs: - script: npm i -g npm@8.19.4 --force displayName: Use npm version 8.19.4 - - script: | - npm install + - script: npm install displayName: Npm install - - script: | - npm run build + - script: node ./ci/check-versions.js + displayName: Verify tasks' versions + condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main')) + + - script: npm run build displayName: Build Common Npm packages - - script: | - node ./ci/verify-source-changes.js + - script: node ./ci/verify-source-changes.js displayName: Verify task source changes condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main')) - - script: node ./ci/check-versions.js - displayName: Verify tasks' versions - condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main')) - - - script: | - npm run test + - script: npm run test displayName: Test Common Npm packages - task: PublishTestResults@2 @@ -52,8 +48,7 @@ jobs: summaryFileLocation: $(System.DefaultWorkingDirectory)/test-results/*coverage.xml # For CI runs on master, automatically publish packages - - bash: | - npm run publish + - bash: npm run publish condition: and(succeeded(), in(variables['build.reason'], 'IndividualCI', 'BatchedCI', 'Manual'), eq(variables['Agent.OS'], 'Windows_NT')) env: NPM_TOKEN: $(npm-automation.token) diff --git a/ci/check-versions.js b/ci/check-versions.js index 8e660684..e486785d 100644 --- a/ci/check-versions.js +++ b/ci/check-versions.js @@ -21,7 +21,7 @@ const packages = [ 'webdeployment-common', ]; -const gitDiffResult = execSync('git diff --name-only main', { encoding: 'utf8' }).split('\n'); +const gitDiffResult = execSync('git --no-pager diff --name-only origin/master', { encoding: 'utf8' }).split('\n'); const changedFolders = new Set(); for (const filePath of gitDiffResult) { diff --git a/common-npm-packages/azurermdeploycommon/webdeployment-common/webconfigutil.ts b/common-npm-packages/azurermdeploycommon/webdeployment-common/webconfigutil.ts index 8c182378..db1222eb 100644 --- a/common-npm-packages/azurermdeploycommon/webdeployment-common/webconfigutil.ts +++ b/common-npm-packages/azurermdeploycommon/webdeployment-common/webconfigutil.ts @@ -19,6 +19,7 @@ function replaceMultiple(text: string, substitutions: any): string { return text; } + function addMissingParametersValue(appType: string, webConfigParameters) { var paramDefaultValue = { 'node': { @@ -95,14 +96,14 @@ export function addWebConfigFile(folderPath: any, webConfigParameters, rootDirec } } else if(appType == 'Go') { if (util.isNullOrUndefined(webConfigParameters['GoExeFileName']) - || util.isNullOrUndefined(webConfigParameters['GoExeFileName'].value) + || util.isNullOrUndefined(webConfigParameters['GoExeFileName'].value) || webConfigParameters['GoExeFileName'].value.length <=0) { throw Error(tl.loc('GoExeNameNotPresent')); } selectedAppTypeParams['GoExeFilePath'] = rootDirectoryPath + "\\" + webConfigParameters['GoExeFileName'].value; } else if(appType == 'java_springboot') { if (util.isNullOrUndefined(webConfigParameters['JAR_PATH']) - || util.isNullOrUndefined(webConfigParameters['JAR_PATH'].value) + || util.isNullOrUndefined(webConfigParameters['JAR_PATH'].value) || webConfigParameters['JAR_PATH'].value.length <= 0) { throw Error(tl.loc('JarPathNotPresent')); }