Skip to content

Commit

Permalink
chore: Action schema handling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed May 14, 2024
1 parent 83c73f4 commit 5f6fafd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private final String updateSchema(String actionText) {
}
var schemaVersion = ActionSchemaHelper.getSchemaVersion(schemaUri);
if ( !ActionSchemaHelper.isSupportedSchemaVersion(schemaVersion) ) {
LOG.warn("WARN: Action was designed for fcli version "+schemaVersion+" and may fail");
LOG.warn("WARN: Action uses unsupported schema version "+schemaVersion+" and may fail");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,33 @@ public static void main(String[] args) throws Exception {
var newSchema = generateSchema();
var existingSchema = loadExistingSchema(actionSchemaVersion);
checkSchemaCompatibility(actionSchemaVersion, existingSchema, newSchema);
writeGitHubWarning(actionSchemaVersion, existingSchema);

// If this is an fcli development release, we output the schema as a development release.
// Note that the same output file name will be used for any branch.
var outputVersion = isDevelopmentRelease.equals("true") ? DEV_VERSION : actionSchemaVersion;
if ( existingSchema!=null && !DEV_VERSION.equals(outputVersion) ) {
System.out.println("Fortify CLI action schema not being generated as "+outputVersion+" schema already exists");
} else {
writeSchema(outputPath, newSchema, outputVersion);
}
}

private static void writeSchema(Path outputPath, JsonNode newSchema, String outputVersion) throws IOException {
Files.createDirectories(outputPath);
var outputFile = outputPath.resolve(String.format("fcli-action-schema-%s.json", outputVersion));
Files.writeString(outputFile, newSchema.toPrettyString(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
System.out.println("Fortify CLI action schema written to "+outputFile.toString());
}

private static void writeGitHubWarning(String actionSchemaVersion, JsonNode existingSchema) {
if ( existingSchema==null ) {
System.out.println("::warning ::New fcli action schema version "+actionSchemaVersion+
" will be published upon fcli release. Please ensure that this version number" +
" properly represents schema changes (patch increase for non-structural changes" +
" like description changes, minor increase for backward-compatible structural" +
" changes like new optional properties, major increase for non-backward-compatible" +
" structural changes like new required properties or removed properties).");
} else if ( !DEV_VERSION.equals(outputVersion) ) {
System.out.println("Fortify CLI action schema not being generated as "+outputVersion+" schema already exists");
} else {
Files.createDirectories(outputPath);
var outputFile = outputPath.resolve(String.format("fcli-action-schema-%s.json", outputVersion));
Files.writeString(outputFile, newSchema.toPrettyString(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
System.out.println("Fortify CLI action schema written to "+outputFile.toString());
}
}

Expand Down

0 comments on commit 5f6fafd

Please sign in to comment.