-
Notifications
You must be signed in to change notification settings - Fork 41
test: added lock file mechanism #2702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
62be608
test: added lock file mechanismn
kirrg001 db17150
chore: update non major bump
kirrg001 fe2b60c
chore: major updates bot
kirrg001 6097591
chore: update header
abhilash-sivan b95971a
chore: updated require-esm test suite to use pinned version
aryamohanan c57553b
chore: updated typeorm
aryamohanan 22ba9ba
chore: updated koa/router to pin dep
aryamohanan dc75d6b
chore: updated tsoa to pin runtime
aryamohanan 54893a7
chore: moved esbuild to example apps
aryamohanan 3b982d8
chore: graphql
aryamohanan 95f5cf3
chore: corrected the code style
aryamohanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| #!/usr/bin/env node | ||
| /* | ||
| * (c) Copyright IBM Corp. 2025 | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const { execSync } = require('child_process'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
|
|
||
| const rootDir = path.resolve(__dirname, '..'); | ||
| const currenciesPath = path.join(rootDir, 'currencies.json'); | ||
| const collectorTestDir = path.join(rootDir, 'packages', 'collector', 'test'); | ||
|
|
||
| const currencyFilter = (() => { | ||
| const idx = process.argv.indexOf('--currency'); | ||
| return idx !== -1 ? process.argv[idx + 1] : null; | ||
| })(); | ||
|
|
||
| const versionFilter = (() => { | ||
| const idx = process.argv.indexOf('--version'); | ||
| return idx !== -1 ? process.argv[idx + 1] : null; | ||
| })(); | ||
|
|
||
| function getInstanaVersion() { | ||
| try { | ||
| return execSync('npm view @instana/collector version', { encoding: 'utf8' }).trim(); | ||
| } catch (_) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| function findTestDirectories(baseDir, name) { | ||
| const results = []; | ||
| const parts = name.split('/'); | ||
|
|
||
| function search(dir) { | ||
| let entries; | ||
| try { | ||
| entries = fs.readdirSync(dir, { withFileTypes: true }); | ||
| } catch (_) { | ||
| return; | ||
| } | ||
| entries | ||
| .filter(entry => entry.isDirectory() && entry.name !== 'node_modules' && !entry.name.startsWith('_v')) | ||
| .forEach(entry => { | ||
| const full = path.join(dir, entry.name); | ||
| if (parts.length === 2) { | ||
| if (entry.name === parts[0]) { | ||
| const inner = path.join(full, parts[1]); | ||
| if (fs.existsSync(inner) && fs.statSync(inner).isDirectory()) { | ||
| results.push(inner); | ||
| } | ||
| } | ||
| } else if (entry.name === name) { | ||
| results.push(full); | ||
| } | ||
| search(full); | ||
| }); | ||
| } | ||
|
|
||
| search(baseDir); | ||
| return results; | ||
| } | ||
|
|
||
| function generateLockFile(currencyName, version, testDir, instanaVersion) { | ||
| const safeName = currencyName.replace(/\//g, '-').replace(/^@/, ''); | ||
| const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `instana-lock-${safeName}-${version}-`)); | ||
|
|
||
| try { | ||
| const dependencies = { [currencyName]: version }; | ||
| if (instanaVersion) { | ||
| dependencies['@instana/collector'] = instanaVersion; | ||
| dependencies['@instana/core'] = instanaVersion; | ||
| dependencies['@instana/shared-metrics'] = instanaVersion; | ||
| } | ||
| const pkgJson = { | ||
| name: `lock-gen-${safeName}-v${version}`, | ||
| dependencies | ||
| }; | ||
| fs.writeFileSync(path.join(tmpDir, 'package.json'), `${JSON.stringify(pkgJson, null, 2)}\n`); | ||
|
|
||
| console.log(` Generating lock file for ${currencyName}@${version}...`); | ||
| execSync('npm install --package-lock-only --no-audit --no-progress', { | ||
| cwd: tmpDir, | ||
| stdio: 'inherit', | ||
| timeout: 5 * 60 * 1000 | ||
| }); | ||
|
|
||
| const lockSrc = path.join(tmpDir, 'package-lock.json'); | ||
| if (!fs.existsSync(lockSrc)) { | ||
| console.warn(` WARNING: no package-lock.json generated for ${currencyName}@${version}`); | ||
| return; | ||
| } | ||
|
|
||
| fs.copyFileSync(lockSrc, path.join(testDir, `package-lock.json.v${version}`)); | ||
| console.log(` Saved → ${path.relative(rootDir, path.join(testDir, `package-lock.json.v${version}`))}`); | ||
| } finally { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| function removeOldLockFiles(testDir, keepVersions) { | ||
| fs.readdirSync(testDir) | ||
| .filter(f => f.startsWith('package-lock.json.v') && !keepVersions.includes(f.slice('package-lock.json.v'.length))) | ||
| .forEach(f => { | ||
| fs.rmSync(path.join(testDir, f)); | ||
| console.log(` Removed → ${path.relative(rootDir, path.join(testDir, f))}`); | ||
| }); | ||
| } | ||
|
|
||
| function generateLockFileFromTemplate(templatePath, instanaVersion) { | ||
| const testDir = path.dirname(templatePath); | ||
| const safeName = path.relative(collectorTestDir, testDir).replace(/[/@]/g, '-'); | ||
| const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `instana-lock-tpl-${safeName}-`)); | ||
|
|
||
| try { | ||
| const tpl = JSON.parse(fs.readFileSync(templatePath, 'utf8')); | ||
| const dependencies = {}; | ||
| ['dependencies', 'devDependencies', 'optionalDependencies'].forEach(section => { | ||
| if (!tpl[section]) return; | ||
| Object.entries(tpl[section]).forEach(([name, ver]) => { | ||
| if (!ver.startsWith('file:') && !ver.startsWith('{{')) { | ||
| dependencies[name] = ver; | ||
| } | ||
| }); | ||
| }); | ||
| if (instanaVersion) { | ||
| dependencies['@instana/collector'] = instanaVersion; | ||
| dependencies['@instana/core'] = instanaVersion; | ||
| dependencies['@instana/shared-metrics'] = instanaVersion; | ||
| } | ||
| if (Object.keys(dependencies).length === 0) return; | ||
|
|
||
| fs.writeFileSync( | ||
| path.join(tmpDir, 'package.json'), | ||
| `${JSON.stringify({ name: `lock-gen-tpl-${safeName}`, dependencies }, null, 2)}\n` | ||
| ); | ||
|
|
||
| console.log(` Generating lock file for template ${path.relative(rootDir, templatePath)}...`); | ||
| execSync('npm install --package-lock-only --no-audit --no-progress', { | ||
| cwd: tmpDir, | ||
| stdio: 'inherit', | ||
| timeout: 5 * 60 * 1000 | ||
| }); | ||
|
|
||
| const lockSrc = path.join(tmpDir, 'package-lock.json'); | ||
| if (!fs.existsSync(lockSrc)) { | ||
| console.warn(` WARNING: no package-lock.json generated for ${templatePath}`); | ||
| return; | ||
| } | ||
|
|
||
| fs.copyFileSync(lockSrc, path.join(testDir, 'package-lock.json.template')); | ||
| console.log(` Saved → ${path.relative(rootDir, path.join(testDir, 'package-lock.json.template'))}`); | ||
| } finally { | ||
| fs.rmSync(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| function findTemplateDirs(baseDir) { | ||
| const results = []; | ||
| function search(dir) { | ||
| let entries; | ||
| try { | ||
| entries = fs.readdirSync(dir, { withFileTypes: true }); | ||
| } catch (_) { | ||
| return; | ||
| } | ||
| entries | ||
| .filter(e => e.isDirectory() && e.name !== 'node_modules' && !e.name.startsWith('_v')) | ||
| .forEach(e => { | ||
| search(path.join(dir, e.name)); | ||
| }); | ||
| const tpl = path.join(dir, 'package.json.template'); | ||
| if (fs.existsSync(tpl)) results.push(tpl); | ||
| } | ||
| search(baseDir); | ||
| return results; | ||
| } | ||
|
|
||
| function main() { | ||
| const instanaVersion = getInstanaVersion(); | ||
| if (instanaVersion) { | ||
| console.log(`Using @instana/collector@${instanaVersion} for lock file generation`); | ||
| } | ||
|
|
||
| const currencies = JSON.parse(fs.readFileSync(currenciesPath, 'utf8')); | ||
|
|
||
| currencies.forEach(currency => { | ||
| if (currencyFilter && currency.name !== currencyFilter) return; | ||
| if (!currency.versions || currency.versions.length === 0) return; | ||
|
|
||
| const testDirs = findTestDirectories(collectorTestDir, currency.name); | ||
| if (testDirs.length === 0) return; | ||
|
|
||
| console.log(`\n[${currency.name}]`); | ||
| const allVersions = currency.versions.map(v => (typeof v === 'string' ? v : v.v)); | ||
| testDirs.forEach(testDir => { | ||
| allVersions.forEach(version => { | ||
| if (versionFilter && version !== versionFilter) return; | ||
| generateLockFile(currency.name, version, testDir, instanaVersion); | ||
| }); | ||
| removeOldLockFiles(testDir, allVersions); | ||
| }); | ||
| }); | ||
|
|
||
| if (!currencyFilter && !versionFilter) { | ||
| console.log('\n[templates]'); | ||
| findTemplateDirs(collectorTestDir).forEach(tpl => { | ||
| generateLockFileFromTemplate(tpl, instanaVersion); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.