Skip to content

Commit 41e2ecd

Browse files
committed
chore: add oss clearance readme file copy step
1 parent 9bfe585 commit 41e2ecd

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.1",

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 { chmod, cp, ensureFileExists, exec, mkdir, popd, pushd, rm, unzip, zip } from "./shell";
15+
import { chmod, cp, ensureFileExists, exec, find, mkdir, popd, pushd, rm, unzip, zip } from "./shell";
1616
import chalk from "chalk";
1717

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

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

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)