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

SDK-365 and SDK-369 - Ensure content package validation occurs prior … #318

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

mseaton
Copy link
Member

@mseaton mseaton commented Dec 10, 2024

…to destructive changes, and do not automatically change distribution/server based on content package requirements.

see https://openmrs.atlassian.net/browse/SDK-365
see https://openmrs.atlassian.net/browse/SDK-369

…to destructive changes, and do not automatically change distribution/server based on content package requirements.
@mseaton mseaton requested a review from ibacher December 10, 2024 00:08
verifier.resetStreams();
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This allows us to create any content packages we wish for testing, without relying on published versions in the cloud

assertLogContains("requires module org.openmrs.module:o3forms-omod version >=2.2.0");
assertLogContains("requires esm @openmrs/esm-patient-chart-app version >=8.1.0");
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added integration tests for the 3 impacted goals with respect to content package validation. In each case, the new default behavior is to fail, and provide a clear message as to why the build failed and what is needed to fix it.

@@ -54,6 +54,9 @@ public void upgradeToDistro(Server server, Distribution distribution, boolean ig
return;
}
}

parentTask.distroHelper.validateDistribution(distroProperties);
Copy link
Member Author

Choose a reason for hiding this comment

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

Per SDK-365, this moves the validation earlier in the process. Previously this was not running until after war/module/etc changes had already been applied to the server.

try {
FileUtils.deleteDirectory(tempDirectory);
} catch (IOException e) {
log.warn("Failed to delete temporary directory: {}", tempDirectory.getAbsolutePath(), e);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a convenience method that gets the missing dependencies, iterates over them, formats these into friendly error messages for display, and throws an exception with this.

throws MojoExecutionException {

Properties contentProperties = new Properties();

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what actually retrieves and calculates missing dependencies. If we wanted to add back in some interactivity with the wizard and allow the user to choose whether to upgrade their server/distribution to the necessary artifacts and versions, we would change the goal from calling the validateDistribution method to calling this method and then using the list of missing dependencies to drive the wizard and support the user upgrading.

String latestVersion = findLatestMatchingVersion(dependency, versionRange);
if (latestVersion == null) {
throw new MojoExecutionException(
"No matching version found for dependency " + dependency + " in " + zipFileName);
Copy link
Member Author

Choose a reason for hiding this comment

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

This method is a bit of a hack to support what PIH is currently doing, which is building our frontend in a separate project and publishing it to Maven, and then including that Maven zip in our distribution. In this case, we don't have the spa-assemble or spa-build config files in that artifact (though as an alternative to this below, we could potentially add it in). This downloads the artifact, unpacks it, and inspects the file/directory contents, translating the directory names back into ESM names and versions. Interested in review/thoughts on this in particular @ibacher . There is an integration test in DistroHelperIT that demonstrates this.

}
} catch (SemverException e) {
throw new MojoExecutionException("Invalid version range format for " + contentDependencyKey
+ " in content package " + contentPackageName + ": " + contentDependencyVersionRange, e);
Copy link
Member Author

Choose a reason for hiding this comment

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

Per slack discussion this new method is what checks for version incompatibility, accounting for things like "next", and also allowing snapshot and pre-releases that are otherwise higher than a release version to satisfy that release version. See unit test in DistroHelperTest for examples.

@mseaton mseaton merged commit e1e7fad into master Dec 10, 2024
2 checks passed
@mseaton mseaton deleted the SDK-369 branch December 10, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant