Skip to content

Commit afcbc1c

Browse files
refactor: update oss readme validation criteria
1 parent 7a85ec2 commit afcbc1c

3 files changed

Lines changed: 67 additions & 25 deletions

File tree

scripts/release/build-mpk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async function createNativeMobileResourcesModule(): Promise<ArtifactResult> {
105105
log("Creating the Native Mobile Resource module...");
106106
const moduleFolder = join(repoRootPath, "packages/jsActions", inputs.module);
107107
log(`Module folder: ${moduleFolder}`);
108-
const ossFiles = await getOssFiles(moduleFolder, false);
108+
const ossFiles = await getOssFiles(moduleFolder);
109109
log(`OSS files to include: ${ossFiles.length}`);
110110
const tmpFolder = join(repoRootPath, "tmp", inputs.module);
111111
log(`Temp folder: ${tmpFolder}`);
@@ -140,7 +140,7 @@ async function createNanoflowCommonsModule(): Promise<ArtifactResult> {
140140
log("Creating the Nanoflow Commons module...");
141141
const moduleFolder = join(repoRootPath, "packages/jsActions", inputs.module);
142142
log(`Module folder: ${moduleFolder}`);
143-
const ossFiles = await getOssFiles(moduleFolder, false);
143+
const ossFiles = await getOssFiles(moduleFolder);
144144
log(`OSS files to include: ${ossFiles.length}`);
145145
const tmpFolder = join(repoRootPath, "tmp", inputs.module);
146146
log(`Temp folder: ${tmpFolder}`);

scripts/release/createNativeModules.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ async function main() {
4646
async function createNativeMobileResourcesModule() {
4747
console.log("Creating the Native Mobile Resource module.");
4848
const moduleFolder = join(repoRootPath, "packages/jsActions", moduleFolderNameInRepo);
49-
const ossFiles = await getOssFiles(moduleFolder, true);
5049
const tmpFolder = join(repoRootPath, "tmp", moduleFolderNameInRepo);
5150
const widgetFolders = await readdir(join(repoRootPath, "packages/pluggableWidgets"));
5251
const nativeWidgetFolders = widgetFolders
@@ -59,6 +58,10 @@ async function createNativeMobileResourcesModule() {
5958
};
6059
moduleInfo = await bumpVersionInPackageJson(moduleFolder, moduleInfo);
6160

61+
const ossFiles = await getOssFiles(moduleFolder, {
62+
package: moduleInfo.moduleNameInModeler,
63+
version: moduleInfo.version
64+
});
6265
await githubAuthentication(moduleInfo);
6366
const moduleChangelogs = await updateChangelogs(nativeWidgetFolders, moduleInfo);
6467
await commitAndCreatePullRequest(moduleInfo);
@@ -79,14 +82,17 @@ async function createNativeMobileResourcesModule() {
7982
async function createNanoflowCommonsModule() {
8083
console.log("Creating the Nanoflow Commons module.");
8184
const moduleFolder = join(repoRootPath, "packages/jsActions", moduleFolderNameInRepo);
82-
const ossFiles = await getOssFiles(moduleFolder, true);
8385
const tmpFolder = join(repoRootPath, "tmp", moduleFolderNameInRepo);
8486
let moduleInfo = {
8587
...(await getPackageInfo(moduleFolder)),
8688
moduleNameInModeler: "NanoflowCommons",
8789
moduleFolderNameInModeler: "nanoflowcommons"
8890
};
8991
moduleInfo = await bumpVersionInPackageJson(moduleFolder, moduleInfo);
92+
const ossFiles = await getOssFiles(moduleFolder, {
93+
package: moduleInfo.moduleNameInModeler,
94+
version: moduleInfo.version
95+
});
9096

9197
await githubAuthentication(moduleInfo);
9298
const moduleChangelogs = await updateModuleChangelogs(moduleInfo);

scripts/release/module-automation/utils.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,32 @@ import { basename, join } from "path";
33
import { globSync } from "glob";
44
import { exec } from "child_process";
55

6+
type OssReadMeValidationCriteria = {
7+
package: string;
8+
version: string;
9+
};
10+
611
export async function getOssFiles(
712
folderPath: string,
8-
isOssReadmeRequired: boolean
13+
validationCriteria?: OssReadMeValidationCriteria
914
): Promise<Array<{ src: string; dest: string }>> {
1015
if (!folderPath || typeof folderPath !== "string") {
1116
throw new TypeError(`Invalid folderPath: ${folderPath}`);
1217
}
1318

14-
const licenseFile = join(folderPath, `License.txt`);
19+
const license = join(folderPath, `License.txt`);
1520
try {
16-
await access(licenseFile);
21+
await access(license);
1722
} catch {
18-
throw new Error(`License file not found at expected location: ${licenseFile}`);
23+
throw new Error(`License file not found at expected location: ${license}`);
1924
}
2025

21-
const readmeossPattern = "*__*__READMEOSS_*.html";
22-
const readmeossFiles = globSync(readmeossPattern, { cwd: folderPath, absolute: true, ignore: "**/.*/**" });
23-
24-
if (isOssReadmeRequired && readmeossFiles.length === 0) {
25-
throw new Error(`No OSS README file found in ${folderPath} matching ${readmeossPattern}`);
26+
const readmePattern = "*__*__READMEOSS_*.html";
27+
const readme = globSync(readmePattern, { cwd: folderPath, absolute: true, ignore: "**/.*/**" })[0];
28+
if (validationCriteria) {
29+
validateOssReadme(readme, validationCriteria);
2630
}
27-
28-
if (readmeossFiles.length === 0) {
29-
return [{ src: licenseFile, dest: basename(licenseFile) }];
30-
}
31-
32-
const ossReadmeFile = readmeossFiles[0];
33-
34-
return [
35-
{ src: licenseFile, dest: basename(licenseFile) },
36-
{ src: ossReadmeFile, dest: basename(ossReadmeFile) }
37-
];
31+
return [{ src: license, dest: basename(license) }, ...(readme ? [{ src: readme, dest: basename(readme) }] : [])];
3832
}
3933

4034
type FilePathPair = { src: string; dest: string };
@@ -61,7 +55,7 @@ export function unzip(src: string, dest: string): Promise<string> {
6155
return execShellCommand(`unzip "${src}" -d "${dest}"`);
6256
}
6357

64-
function execShellCommand(cmd: string, workingDirectory = process.cwd()): Promise<string> {
58+
export function execShellCommand(cmd: string, workingDirectory = process.cwd()): Promise<string> {
6559
return new Promise((resolve, reject) => {
6660
exec(cmd, { cwd: workingDirectory }, (error, stdout, stderr) => {
6761
if (error) {
@@ -76,3 +70,45 @@ function execShellCommand(cmd: string, workingDirectory = process.cwd()): Promis
7670
});
7771
});
7872
}
73+
74+
export function validateOssReadme(ossReadme: string, validationCriteria: OssReadMeValidationCriteria): void {
75+
if (!ossReadme || typeof ossReadme !== "string") {
76+
throw new TypeError(`Invalid OSS README path/name: ${ossReadme}`);
77+
}
78+
if (!validationCriteria.version || typeof validationCriteria.version !== "string") {
79+
throw new TypeError(`Invalid version: ${validationCriteria.version}`);
80+
}
81+
if (!validationCriteria.package || typeof validationCriteria.package !== "string") {
82+
throw new TypeError(`Invalid package name: ${validationCriteria.package}`);
83+
}
84+
85+
const fileName = basename(ossReadme);
86+
const expectedPackage = validationCriteria.package.trim();
87+
const expectedVersion = validationCriteria.version.trim();
88+
89+
// File name pattern: SiemensMendix<PACKAGE>__<VERSION>__READMEOSS_*.html
90+
// Example: SiemensMendixNanoflowCommons__6.3.1__READMEOSS_2026-02-10__04-28-37.html
91+
const parsed = fileName.match(/^SiemensMendix(.+?)__(.+?)__READMEOSS_(.+)\.html$/);
92+
93+
if (!parsed) {
94+
throw new Error(
95+
`OSS README validation failed: '${fileName}' does not match expected pattern ` +
96+
`'SiemensMendix<PACKAGE>__<VERSION>__READMEOSS_*.html'.`
97+
);
98+
}
99+
100+
const foundPackage = parsed[1];
101+
const foundVersion = parsed[2];
102+
103+
if (foundPackage !== expectedPackage) {
104+
throw new Error(
105+
`OSS README validation failed: expected package '${expectedPackage}' but found '${foundPackage}' in '${fileName}'.`
106+
);
107+
}
108+
109+
if (foundVersion !== expectedVersion) {
110+
throw new Error(
111+
`OSS README validation failed: expected version '${expectedVersion}' but found '${foundVersion}' in '${fileName}'.`
112+
);
113+
}
114+
}

0 commit comments

Comments
 (0)