Skip to content
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

Allow filtering by version level #534

Merged
merged 3 commits into from
Jan 29, 2025
Merged
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
64 changes: 49 additions & 15 deletions src/scripts/check_dependencies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ dependencies:
archetype: 1.0.26
---

List the current versions of the tools in the config file at ./dependencies.json and this script will print the pages that have been tested only on older versions of the tools.

Arguments:

You can pass individual tools to check, as in npm run check-dependencies -- smartpy taquito and it will check only those dependencies.

By default, this script checks for differences down to the fixpack level.
You can pass --major or --minor to ignore differences up to the specified level.
NicNomadic marked this conversation as resolved.
Show resolved Hide resolved

*/

import path, { dirname } from 'path';
Expand All @@ -18,32 +27,57 @@ import matter from 'gray-matter';
import semver from 'semver';
import minimist from 'minimist';

const argv = minimist(process.argv.slice(2));
const params = argv['_'];

const __dirname = dirname(fileURLToPath(import.meta.url));
const baseFolder = path.resolve(__dirname, '../..');
const docsFolder = path.resolve(baseFolder, 'docs');

// List the current versions of the tools in the config file and this script will print the pages that have been tested only on older versions of the tools

// You can pass individual tools to check, as in
// npm run check-dependencies smartpy taquito
// and it will check only those dependencies

// Import config file
// Not sure why I can't import a JSON file directly in MJS
const dependencyConfig = fs.readFileSync(path.resolve(__dirname, 'dependencies.json'), 'utf8');
const { currentVersions } = JSON.parse(dependencyConfig);

// Verify the passed dependencies parameters
const unrecognizedParams = params.filter((oneParam) => !currentVersions[oneParam]);
if (unrecognizedParams.length > 0) {
console.error('Unrecognized tool names in parameters:');
console.log(unrecognizedParams.join('\n'));
const argv = minimist(process.argv.slice(2), {
boolean: ['major', 'minor'],
unknown: (unknownArg) => {
if (currentVersions[unknownArg]) {
return true;
}
console.error('Error: unknown argument or tool name: ', unknownArg);
process.exit(1);
}
});
const params = argv['_'];

const checkMajor = argv.major;
const checkMinor = argv.minor;
if (checkMajor && checkMinor) {
console.error('Include either --major or --minor, not both');
process.exit(1);
}

// Function to compare versions based on whether we care about major, minor, or patch versions
// diff(v1, v2): Returns the difference between two versions by the release type (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null if the versions are the same.
const isOldVersion = (v1String, v2String) => {
const v1 = semver.coerce(v1String);
const v2 = semver.coerce(v2String);
const diff = semver.diff(v1, v2);
if (!diff) {
// Versions match
return false;
}

if (diff === 'major') {
return true;
}
if (diff === 'minor' && !checkMajor) {
return true;
}
if (diff === 'fixpack' && !checkMinor) {
return true;
}
return false;
}

const printDependencies = async () => {
// Get all MD and MDX files
const files = await glob(docsFolder + '/**/*.{md,mdx}');
Expand Down Expand Up @@ -97,7 +131,7 @@ const printDependencies = async () => {
// Tool has no current version
prevWarnings.push(`Error: Unknown dependency: ${oneTool}`);
} else {
if (semver.gt(semver.coerce(currentVersion).version, semver.coerce(usedVersion).version)) {
if (isOldVersion(currentVersion, usedVersion)) {
// The listed version of the dependency is less than the current version in the config file
prevWarnings.push(`Outdated: ${oneTool} ${usedVersion} < ${currentVersion}`);
}
Expand Down
Loading