Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .tekton/tasks/execute-tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,21 @@ spec:
npm install npm@$(params.npm-version) -g
fi
bin/clean-aws.js --service=s3
bin/clean-aws.js --service=s3
bin/clean-aws.js --service=dynamodb
bin/clean-aws.js --service=sqs
bin/clean-aws.js --service=kinesis
bin/clean-aws.js --service=kinesis
- name: generate-test-folders
image: public.ecr.aws/docker/library/node:$(params.node-version)
imagePullPolicy: IfNotPresent
script: |
#!/bin/bash
ARTIFACTS_PATH="$(workspaces.output.path)"
cd $ARTIFACTS_PATH
if [ -n "$(params.npm-version)" ]; then
npm install npm@$(params.npm-version) -g
fi
node bin/create-version-test-folders.js
2 changes: 1 addition & 1 deletion bin/add-test-aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const addAliasIfNotExists = (aliasCommand, configFile) => {
}
};

const output = execSync('lerna list --json', { encoding: 'utf-8' });
const output = execSync('npx lerna list --json', { encoding: 'utf-8' });
const packages = JSON.parse(output);
const scopeNames = packages.map(pkg => pkg.name);
const shellArg = process.argv[2];
Expand Down
218 changes: 218 additions & 0 deletions bin/create-version-test-folders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#!/usr/bin/env node
/*
* (c) Copyright IBM Corp. 2025
*/

'use strict';

const fs = require('fs');
const path = require('path');
const semver = require('semver');

const rootDir = path.resolve(__dirname, '..');
const currenciesPath = path.join(rootDir, 'currencies.json');
const collectorTestDir = path.join(rootDir, 'packages', 'collector', 'test');

function main() {
const currencies = JSON.parse(fs.readFileSync(currenciesPath, 'utf8'));

currencies.forEach(currency => {
if (!currency.versions || currency.versions.length === 0) {
return;
}

function findTestDirectory(dir) {
let entries;
try {
entries = fs.readdirSync(dir, { withFileTypes: true });
} catch (err) {
return null;
}

for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
if (entry.isDirectory()) {
if (entry.name === 'node_modules') {
return null;
}
if (entry.name === currency.name) {
return path.join(dir, entry.name);
}

const found = findTestDirectory(path.join(dir, entry.name));
if (found) {
return found;
}
}
}
return null;
}

function createSymlink(sourcePath, targetPath) {
if (fs.existsSync(targetPath)) {
if (fs.lstatSync(targetPath).isDirectory() || !fs.lstatSync(targetPath).isSymbolicLink()) {
return;
}
fs.unlinkSync(targetPath);
}
fs.symlinkSync(path.relative(path.dirname(targetPath), sourcePath), targetPath);
}

function symlinkContents(sourceDir, targetDir) {
const entries = fs.readdirSync(sourceDir, { withFileTypes: true });
for (const entry of entries) {
if (entry.name === 'node_modules' || entry.name.startsWith('_v')) {
continue;
}

const sourceEntryPath = path.join(sourceDir, entry.name);
const targetEntryPath = path.join(targetDir, entry.name);

if (entry.isDirectory()) {
if (!fs.existsSync(targetEntryPath)) {
fs.mkdirSync(targetEntryPath);
}
symlinkContents(sourceEntryPath, targetEntryPath);
} else if (entry.isFile()) {
const ext = path.extname(entry.name);
if (ext === '.js' || ext === '.mjs') {
createSymlink(sourceEntryPath, targetEntryPath);
}
}
}
}

const testDir = findTestDirectory(collectorTestDir);
if (!testDir) {
return;
}

console.log(`Found test directory: ${testDir}`);

const testBasePath = path.join(testDir, 'test_base.js');
if (!fs.existsSync(testBasePath)) {
console.log(`test_base.js not found in ${testDir}, skipping generation...`);
return;
}

const sortedVersions = currency.versions.map(v => (typeof v === 'string' ? v : v.v)).sort(semver.rcompare);
const latestVersion = sortedVersions[0];

// cleanup
const versionDirs = fs.readdirSync(testDir).filter(name => name.startsWith('_v'));
versionDirs.forEach(dir => {
const dirPath = path.join(testDir, dir);
console.log(`Deleting ${dirPath}`);
fs.rmSync(dirPath, { recursive: true, force: true });
});


const usedDirs = new Set();
const versionToDir = new Map();

sortedVersions.forEach(v => {
const versionStr = typeof v === 'string' ? v : v.v;
const versionDirName = `_v${versionStr}`;

usedDirs.add(versionDirName);
versionToDir.set(versionStr, versionDirName);
});

currency.versions.forEach(versionObj => {
const version = typeof versionObj === 'string' ? versionObj : versionObj.v;
const isLatest = version === latestVersion;
const majorVersion = semver.major(version);

const dirName = versionToDir.get(version);
if (!dirName) {
return;
}

const versionDir = path.join(testDir, dirName);

if (!fs.existsSync(versionDir)) {
fs.mkdirSync(versionDir, { recursive: true });
}

const modesPath = path.join(testDir, 'modes.json');
let modes = [null];
if (fs.existsSync(modesPath)) {
try {
modes = JSON.parse(fs.readFileSync(modesPath, 'utf8'));
} catch (err) {
console.error(`Failed to parse ${modesPath}:`, err);
}
}

modes.forEach(mode => {
const currentYear = new Date().getFullYear();

const testContent = `/*
* (c) Copyright IBM Corp. ${currentYear}
*/

'use strict';

/** THIS IS A GENERATED FILE. DO NOT MODIFY IT. */

const { execSync } = require('child_process');
const path = require('path');
const testBase = require('./test_base');
const config = require('@_instana/core/test/config');
const supportedVersion = require('@_instana/core').tracing.supportedVersion;
const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : describe.skip;

mochaSuiteFn('tracing/${currency.name}@${dirName.substring(1)}${mode ? ` (${mode})` : ''}', function () {
this.timeout(config.getTestTimeout());

before(() => {
execSync('rm -rf node_modules', { cwd: __dirname, stdio: 'inherit' });
execSync('npm install --no-audit --prefix ./', { cwd: __dirname, stdio: 'inherit' });
});

testBase.call(this, '${currency.name}', '${version}', ${isLatest}${mode ? `, '${mode}'` : ''});
});
`;
const fileName = mode ? `test_${mode}.js` : 'test.js';
fs.writeFileSync(path.join(versionDir, fileName), testContent);
});

const packageJsonPath = path.join(testDir, 'package.json');
let versionPackageJson = {
name: `${currency.name}-v${majorVersion}`
};

if (fs.existsSync(packageJsonPath)) {
const templatePackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
versionPackageJson = Object.assign(versionPackageJson, templatePackageJson);
}

if (!versionPackageJson.dependencies) {
versionPackageJson.dependencies = {};
}

const tgzDir = path.join(collectorTestDir, 'instana-tgz');
const relativeTgzPath = path.relative(versionDir, tgzDir).replace(/\\/g, '/');

versionPackageJson.dependencies['@instana/collector'] = `file:${relativeTgzPath}/collector.tgz`;
versionPackageJson.dependencies['@instana/core'] = `file:${relativeTgzPath}/core.tgz`;
versionPackageJson.dependencies['@instana/shared-metrics'] = `file:${relativeTgzPath}/shared-metrics.tgz`;

const matchingVersion = currency.versions.find(vObj => {
const v = typeof vObj === 'string' ? vObj : vObj.v;
const parsed = semver.parse(v);
return parsed && parsed.major === majorVersion;
});
if (matchingVersion) {
const actualVersion = typeof matchingVersion === 'string' ? matchingVersion : matchingVersion.v;
versionPackageJson.dependencies[currency.name] = actualVersion;
}

fs.writeFileSync(path.join(versionDir, 'package.json'), `${JSON.stringify(versionPackageJson, null, 2)}\n`);

symlinkContents(testDir, versionDir);
});
});
}

main();
57 changes: 0 additions & 57 deletions bin/dependencies/currency/bump-sub-currency-versions.js

This file was deleted.

13 changes: 3 additions & 10 deletions bin/dependencies/currency/generate-currency-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,18 @@ currencies = currencies.map(currency => {
console.log('\n###############################################');
console.log(`Checking ${currency.name}...`);

let installedVersion = utils.getRootDependencyVersion(currency.name);
const versionObj = currency.versions[0];
let installedVersion = typeof versionObj === 'string' ? versionObj : versionObj.v;
let latestVersion;
let upToDate;
let latestVersionPublishedAt = 'N/A';
let daysBehind = '0';

if (!installedVersion) {
installedVersion = utils.getPackageDependencyVersion(currency.name);
}

// CASE: core pkg
if (currency.core) {
installedVersion = latestVersion = 'latest';
upToDate = true;
} else {
// CASE: remove tilde or caret
if (installedVersion) {
installedVersion = installedVersion.replace(/[^0-9.]/g, '');
}

latestVersion = utils.getLatestVersion({
pkgName: currency.name,
installedVersion: installedVersion,
Expand Down Expand Up @@ -116,6 +108,7 @@ currencies = currencies.map(currency => {
: latestVersionPublishedAt,
daysBehind
};

return currency;
});

Expand Down
Loading