Skip to content
Merged
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
19 changes: 17 additions & 2 deletions .github/workflows/verify-pr/identify-affected-workspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function main() {
displayList('THE FOLLOWING FILES WERE CHANGED:', changedFiles);

const changedPackages = identifyChangedPackages(changedFiles);

if (changedPackages.length === 0) {
console.log(`No package-level changes. Using empty workspace arg to test all packages.`);
fs.writeFileSync(tmpFilePath, '');
Expand All @@ -34,7 +35,17 @@ function main() {
console.log(`NO PACKAGES HAVE DEPENDENCIES ON CHANGED PACKAGES.\n`);
}

const affectedPackages = [...(new Set([...changedPackages, ...dependentPackages]).keys())];
const undeletedChangedPackages = changedPackages.filter(pkgLocation => {
const packageName = pkgLocation.replace("packages","").replace("/","").replace("\\","");
if(fs.existsSync(getPackageJsonFile(packageName))) {
return true;
} else {
console.log(`Removing package '${packageName}' from list of workspaces since it seems to have been deleted.`);
}
});


const affectedPackages = [...(new Set([...undeletedChangedPackages, ...dependentPackages]).keys())];
displayList('BASED ON THE ABOVE, THE FOLLOWING PACKAGES ARE AFFECTED BY CHANGES, AND WILL REQUIRE TESTING:', affectedPackages);

const correspondingWorkspaceArgs = affectedPackages.map(name => `--workspace ${name}`);
Expand Down Expand Up @@ -100,8 +111,12 @@ function getAllPackageJsons() {
return packagesDir.filter(f => fs.statSync(path.join(pathToRoot, 'packages', f)).isDirectory()).map(getPackageJson);
}

function getPackageJsonFile(packageName) {
return path.join(pathToRoot, 'packages', packageName, 'package.json');
}

function getPackageJson(packageName) {
const packageJsonPath = path.join(pathToRoot, 'packages', packageName, 'package.json');
const packageJsonPath = getPackageJsonFile(packageName);
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
}

Expand Down
14 changes: 8 additions & 6 deletions .node-scripts/validate-changed-package-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ function isFileInTestFolder(changedFile) {

function identifyIncorrectlyVersionedPackages(changedPackages) {
const incorrectlyVersionedPackages = [];

for (const changedPackage of changedPackages) {
const packageVersion = getPackageVersion(changedPackage);

const packageJsonPath = path.join(changedPackage, 'package.json');
if (!fs.existsSync(packageJsonPath)) {
continue; // This means the package was deleted, so we ignore this package

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice forward cleanup 👍

}
const packageVersion = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')).version;

if (!packageVersion.endsWith('-SNAPSHOT')) {
incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) lacks a trailing "-SNAPSHOT"`);
continue;
Expand All @@ -102,9 +109,4 @@ function getLatestReleasedVersion(changedPackage) {
}
}

function getPackageVersion(changedPackage) {
const packageJsonPath = path.join(changedPackage, 'package.json');
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')).version;
}

main();
Loading
Loading