Skip to content

Commit 8b954c2

Browse files
committed
chore: add oss clearance readme file copy step
1 parent ceb276e commit 8b954c2

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

automation/scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint": "echo 'Lint disabled for now, please update package scripts'",
1515
"lint:enableme": "eslint . --ext .mjs",
1616
"root-script:commitlint": "commitlint",
17-
"root-script:format-staged": "pretty-quick --staged --config \"./.prettierrc.cjs\" --pattern \"**/{src,script,typings,test,**}/**/*.{cjs,mjs,js,jsx,ts,tsx,scss,html,xml,md,json}\""
17+
"root-script:format-staged": "pretty-quick --staged --config \"./.prettierrc.cjs\" --pattern \"**/{src,script,typings,test,**}/**/*.{cjs,mjs,js,jsx,ts,tsx,scss,xml,md,json}\""
1818
},
1919
"dependencies": {
2020
"@commitlint/cli": "^19.8.0",

automation/utils/src/changelog.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ export async function updateChangelogsAndCreatePR(
1010
const releaseBranchName = `${releaseTag}-update-changelog`;
1111
const appName = info.marketplace.appName;
1212

13+
// Check if branch already exists on remote
14+
try {
15+
const { stdout: remoteOutput } = await exec(`git ls-remote --heads ${remoteName} ${releaseBranchName}`, {
16+
stdio: "pipe"
17+
});
18+
if (remoteOutput.trim()) {
19+
// Branch exists on remote, get its commit hash and rename it
20+
const remoteCommitHash = remoteOutput.split("\t")[0].substring(0, 7); // Get short hash from remote output
21+
const renamedBranchName = `${releaseBranchName}-${remoteCommitHash}`;
22+
23+
console.log(
24+
`Branch '${releaseBranchName}' already exists on remote. Renaming it to '${renamedBranchName}'...`
25+
);
26+
27+
// Create new branch on remote with the renamed name pointing to the same commit
28+
await exec(`git push ${remoteName} ${remoteName}/${releaseBranchName}:refs/heads/${renamedBranchName}`);
29+
// Delete the old branch on remote
30+
await exec(`git push ${remoteName} --delete ${releaseBranchName}`);
31+
}
32+
} catch (error) {
33+
// Branch doesn't exist on remote, continue with original name
34+
console.log(`Using branch name '${releaseBranchName}'`);
35+
}
36+
1337
console.log(`Creating branch '${releaseBranchName}'...`);
1438
await exec(`git checkout -b ${releaseBranchName}`);
1539

automation/utils/src/steps.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { copyMpkFiles, getMpkPaths } from "./monorepo";
1212
import { createModuleMpkInDocker } from "./mpk";
1313
import { ModuleInfo, PackageInfo, WidgetInfo } from "./package-info";
1414
import { addFilesToPackageXml, PackageType } from "./package-xml";
15-
import { cp, ensureFileExists, exec, mkdir, popd, pushd, rm, unzip, zip, chmod } from "./shell";
15+
import { cp, ensureFileExists, exec, mkdir, popd, pushd, rm, unzip, zip, chmod, find } from "./shell";
1616
import chalk from "chalk";
1717

1818
type Step<Info, Config> = (params: { info: Info; config: Config }) => Promise<void>;
@@ -194,6 +194,57 @@ export async function addWidgetsToMpk({ config }: ModuleStepParams): Promise<voi
194194
rm("-rf", target);
195195
}
196196

197+
export async function addREADMEOSSToMpk({ config, info }: ModuleStepParams): Promise<void> {
198+
logStep("Add READMEOSS to mpk");
199+
200+
// Check that READMEOSS file exists in package root and find it by name pattern
201+
const packageRoot = config.paths.package;
202+
const widgetName = info.mxpackage.name;
203+
const version = info.version.format();
204+
205+
// We'll search for files matching the name and version, ignoring timestamp
206+
const readmeossPattern = `*${widgetName}__${version}__READMEOSS_*.html`;
207+
208+
console.info(`Looking for READMEOSS file matching pattern: ${readmeossPattern}`);
209+
210+
// Find files matching the pattern in package root
211+
const matchingFiles = find(packageRoot).filter(file => {
212+
const fileName = parse(file).base;
213+
// Check if filename contains the widget name, version, and READMEOSS
214+
return fileName.includes(`${widgetName}__${version}__READMEOSS_`) && fileName.endsWith(".html");
215+
});
216+
217+
if (matchingFiles.length === 0) {
218+
console.warn(
219+
`⚠️ READMEOSS file not found for ${widgetName} version ${version}. Expected pattern: ${readmeossPattern}`
220+
);
221+
console.warn(` Skipping READMEOSS addition to mpk.`);
222+
return;
223+
}
224+
225+
const readmeossFile = matchingFiles[0];
226+
console.info(`Found READMEOSS file: ${parse(readmeossFile).base}`);
227+
228+
const mpk = config.output.files.modulePackage;
229+
const widgets = await getMpkPaths(config.dependencies);
230+
const mpkEntry = parse(mpk);
231+
const target = join(mpkEntry.dir, "tmp");
232+
233+
rm("-rf", target);
234+
235+
console.info("Unzip module mpk");
236+
await unzip(mpk, target);
237+
chmod("-R", "a+rw", target);
238+
239+
console.info(`Add READMEOSS file to ${mpkEntry.base}`);
240+
// Copy the READMEOSS file to the target directory
241+
cp(readmeossFile, target);
242+
243+
console.info("Create module zip archive");
244+
await zip(target, mpk);
245+
rm("-rf", target);
246+
}
247+
197248
export async function moveModuleToDist({ info, config }: ModuleStepParams): Promise<void> {
198249
logStep("Move module to dist");
199250

packages/modules/data-widgets/scripts/release.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
removeDist,
1212
runModuleSteps,
1313
writeModuleVersion,
14-
copyActionsFiles
14+
copyActionsFiles,
15+
addREADMEOSSToMpk
1516
} from "@mendix/automation-utils/steps";
1617

1718
import { bundleXLSX } from "./steps/bundle-xlsx";
@@ -30,6 +31,7 @@ async function main(): Promise<void> {
3031
copyModuleLicense,
3132
createModuleMpk,
3233
addWidgetsToMpk,
34+
addREADMEOSSToMpk,
3335
moveModuleToDist
3436
]
3537
});

0 commit comments

Comments
 (0)