diff --git a/.github/workflows/BuildMpk.yml b/.github/workflows/BuildMpk.yml new file mode 100644 index 000000000..4a3019af7 --- /dev/null +++ b/.github/workflows/BuildMpk.yml @@ -0,0 +1,64 @@ +name: Build MPK + +on: + workflow_dispatch: + inputs: + module: + description: "Select the module to create MPK for" + required: true + type: choice + options: + - mobile-resources-native + - nanoflow-actions-native + version: + description: "Version to increase" + required: true + type: choice + default: patch + options: + - patch + - minor + - major + +jobs: + publish_release: + name: "Build MPK" + runs-on: ubuntu-latest + + steps: + - name: "Checking-out code" + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3 + with: + submodules: false + - name: "Defining node version" + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3 + with: + node-version-file: ".nvmrc" + - name: "Setup pnpm" + uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4 + - name: "Installing dependencies" + run: pnpm install + - name: "Bumping version" + id: bump_version + run: | + NEW_VER=$(npm --prefix "./packages/jsActions/${{ inputs.module }}" version "${{ inputs.version }}" --no-git-tag-version) + echo "VERSION=${NEW_VER}" >> "$GITHUB_OUTPUT" + - name: "Building native widgets and js actions" + run: pnpm -r run release + - name: "Updating Native Mobile Resources project" + run: pnpm run build-mpk + env: + MODULE: ${{ inputs.module }} + VERSION: ${{ steps.bump_version.outputs.VERSION }} + + - name: "Upload MPK artifact" + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #v4 + with: + name: ${{ env.ARTIFACT_NAME }} + path: ${{ env.ARTIFACT_PATH }} + if-no-files-found: error + + - name: "Cleanup tmp folder" + if: ${{ always() }} + run: | + sudo rm -rf tmp || true diff --git a/LICENSE b/LICENSE index 51dfbf50d..d0579ce07 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Apache License + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -186,7 +186,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2020 Mendix Technology BV + Copyright 2022 Mendix Technology B.V. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -198,4 +198,4 @@ Apache License distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. + limitations under the License. \ No newline at end of file diff --git a/package.json b/package.json index e5461d2d7..c76cb7919 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "release": "pnpm -r run release", "release:marketplace": "pnpm -r run release:marketplace", "release-github:widget": "node ./scripts/release/createWidgetRelease.js", - "create-modules": "node ./scripts/release/createNativeModules.js", + "create-modules": "ts-node --project ./scripts/tsconfig.json ./scripts/release/createNativeModules.js", + "build-mpk": "ts-node --project ./scripts/tsconfig.json ./scripts/release/build-mpk.ts", "version": "ts-node --project ./scripts/tsconfig.json ./scripts/release/BumpVersion.ts", "validate-staged-widget-versions": "node scripts/validation/validate-versions-staged-files.js", "setup-mobile": "pnpm setup-android && pnpm setup-ios", diff --git a/packages/jsActions/nanoflow-actions-native/LICENSE b/packages/jsActions/mobile-resources-native/License.txt similarity index 99% rename from packages/jsActions/nanoflow-actions-native/LICENSE rename to packages/jsActions/mobile-resources-native/License.txt index 564e56569..d0579ce07 100644 --- a/packages/jsActions/nanoflow-actions-native/LICENSE +++ b/packages/jsActions/mobile-resources-native/License.txt @@ -1,4 +1,4 @@ -Apache License + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -186,7 +186,7 @@ Apache License same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2019 Mendix BV + Copyright 2022 Mendix Technology B.V. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -198,5 +198,4 @@ Apache License distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and - limitations under the License. - \ No newline at end of file + limitations under the License. \ No newline at end of file diff --git a/packages/jsActions/nanoflow-actions-native/License.txt b/packages/jsActions/nanoflow-actions-native/License.txt new file mode 100644 index 000000000..d0579ce07 --- /dev/null +++ b/packages/jsActions/nanoflow-actions-native/License.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 Mendix Technology B.V. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/scripts/release/build-mpk.ts b/scripts/release/build-mpk.ts new file mode 100644 index 000000000..37c013f62 --- /dev/null +++ b/scripts/release/build-mpk.ts @@ -0,0 +1,236 @@ +import { basename, join, dirname } from "path"; +import { readdir, copyFile, rm, mkdir } from "fs/promises"; +import { appendFileSync } from "fs"; +import { + execShellCommand, + getFiles, + getPackageInfo, + cloneRepo, + createMPK, + exportModuleWithWidgets, + regex +} from "./module-automation/commons"; +import { copyFilesToMpk, getOssFiles } from "./module-automation/utils"; + +const repoRootPath = join(__dirname, "../../"); + +const LOG_PREFIX = "[buildMpk]"; +function log(message: string): void { + console.log(`${LOG_PREFIX} ${message}`); +} + +type ArtifactResult = { + artifactPath: string; + artifactName: string; +}; + +function setGithubActionsVars(artifact: ArtifactResult): void { + const githubEnvPath = process.env.GITHUB_ENV; + if (githubEnvPath) { + appendFileSync(githubEnvPath, `ARTIFACT_PATH=${artifact.artifactPath}\n`); + appendFileSync(githubEnvPath, `ARTIFACT_NAME=${artifact.artifactName}\n`); + log(`Exported ARTIFACT_PATH and ARTIFACT_NAME to GITHUB_ENV`); + } + + const githubOutputPath = process.env.GITHUB_OUTPUT; + if (githubOutputPath) { + appendFileSync(githubOutputPath, `artifact_path=${artifact.artifactPath}\n`); + appendFileSync(githubOutputPath, `artifact_name=${artifact.artifactName}\n`); + log(`Exported artifact_path and artifact_name to GITHUB_OUTPUT`); + } +} + +type InputVariables = { + module: string; + version: string; +}; + +const inputs: InputVariables = { + module: "", + version: "" +}; + +main() + .then(writeArtifactEnvVariable) + .catch(e => { + console.error(e); + process.exit(1); + }); + +function writeArtifactEnvVariable(artifact: ArtifactResult): void { + if (!artifact?.artifactPath || !artifact?.artifactName) { + throw new Error(`${LOG_PREFIX} Expected an artifact result from main(), but got: ${JSON.stringify(artifact)}`); + } + + log(`Setting environment variable ARTIFACT_PATH=${artifact.artifactPath}`); + process.env.ARTIFACT_PATH = artifact.artifactPath; + log(`Setting environment variable ARTIFACT_NAME=${artifact.artifactName}`); + process.env.ARTIFACT_NAME = artifact.artifactName; + log("Artifact environment variables set successfully."); + + setGithubActionsVars(artifact); +} + +function validateInput(): void { + const moduleName = process.env.MODULE; + let version = process.env.VERSION; + + const modules = ["mobile-resources-native", "nanoflow-actions-native"]; + if (!moduleName || !modules.includes(moduleName)) { + throw new Error(`${LOG_PREFIX} Invalid MODULE="${moduleName}". Expected one of: ${modules.join(", ")}`); + } + if (!version) { + throw new Error(`${LOG_PREFIX} Invalid VERSION="${version}"`); + } + if (version?.startsWith("v")) { + version = version.split("v")[1]; + } + inputs.module = moduleName; + inputs.version = version; + log(`Starting (MODULE=${inputs.module}, VERSION=${inputs.version})`); +} + +async function main(): Promise { + validateInput(); + switch (inputs.module) { + case "mobile-resources-native": + return createNativeMobileResourcesModule(); + case "nanoflow-actions-native": + return createNanoflowCommonsModule(); + } + throw new Error(`${LOG_PREFIX} No implementation for MODULE="${inputs.module}"`); +} + +async function createNativeMobileResourcesModule(): Promise { + log("Creating the Native Mobile Resource module..."); + const moduleFolder = join(repoRootPath, "packages/jsActions", inputs.module); + log(`Module folder: ${moduleFolder}`); + const ossFiles = await getOssFiles(moduleFolder); + log(`OSS files to include: ${ossFiles.length}`); + const tmpFolder = join(repoRootPath, "tmp", inputs.module); + log(`Temp folder: ${tmpFolder}`); + const widgetFolders = await readdir(join(repoRootPath, "packages/pluggableWidgets")); + const nativeWidgetFolders = widgetFolders + .filter(folder => folder.includes("-native")) + .map(folder => join(repoRootPath, "packages/pluggableWidgets", folder)); + log(`Native widget folders found: ${nativeWidgetFolders.length}`); + const moduleInfo = { + ...(await getPackageInfo(moduleFolder)), + moduleNameInModeler: "NativeMobileResources", + moduleFolderNameInModeler: "nativemobileresources" + }; + log( + `Module info: nameWithSpace=${moduleInfo.nameWithSpace ?? ""}, minimumMXVersion=${ + moduleInfo.minimumMXVersion ?? "" + }, moduleNameInModeler=${moduleInfo.moduleNameInModeler}` + ); + await updateNativeComponentsTestProject(moduleInfo, tmpFolder, nativeWidgetFolders); + log("Creating MPK..."); + const mpkOutput = await createMPK(tmpFolder, moduleInfo, regex.excludeFiles); + log(`MPK created at: ${mpkOutput}`); + log("Exporting module with widgets into MPK..."); + await exportModuleWithWidgets(moduleInfo.moduleNameInModeler, mpkOutput, nativeWidgetFolders, ossFiles); + return { + artifactPath: mpkOutput, + artifactName: moduleInfo.moduleNameInModeler + }; +} + +async function createNanoflowCommonsModule(): Promise { + log("Creating the Nanoflow Commons module..."); + const moduleFolder = join(repoRootPath, "packages/jsActions", inputs.module); + log(`Module folder: ${moduleFolder}`); + const ossFiles = await getOssFiles(moduleFolder); + log(`OSS files to include: ${ossFiles.length}`); + const tmpFolder = join(repoRootPath, "tmp", inputs.module); + log(`Temp folder: ${tmpFolder}`); + const moduleInfo = { + ...(await getPackageInfo(moduleFolder)), + moduleNameInModeler: "NanoflowCommons", + moduleFolderNameInModeler: "nanoflowcommons" + }; + + log( + `Module info: nameWithSpace=${moduleInfo.nameWithSpace ?? ""}, minimumMXVersion=${ + moduleInfo.minimumMXVersion ?? "" + }, moduleNameInModeler=${moduleInfo.moduleNameInModeler}` + ); + + await updateNativeComponentsTestProject(moduleInfo, tmpFolder); + log("Creating MPK..."); + const mpkOutput = await createMPK(tmpFolder, moduleInfo, regex.excludeFiles); + log(`MPK created at: ${mpkOutput}`); + log("Copying OSS files into MPK..."); + await copyFilesToMpk(ossFiles, mpkOutput, moduleInfo.moduleNameInModeler); + return { + artifactPath: mpkOutput, + artifactName: moduleInfo.moduleNameInModeler + }; +} + +// Update test project with latest changes and update version in themesource +async function updateNativeComponentsTestProject( + moduleInfo: any, + tmpFolder: string, + nativeWidgetFolders?: string[] +): Promise { + const jsActionsPath = join(repoRootPath, `packages/jsActions/${inputs.module}/dist`); + const jsActions: string[] = await getFiles(jsActionsPath); + const tmpFolderActions = join(tmpFolder, `javascriptsource/${moduleInfo.moduleFolderNameInModeler}/actions`); + + log(`Updating NativeComponentsTestProject (repo=${moduleInfo.testProjectUrl ?? ""})...`); + log(`JS actions dist path: ${jsActionsPath}`); + log(`JS actions files found: ${jsActions.length}`); + await cloneRepo(moduleInfo.testProjectUrl, tmpFolder); + + log(`Deleting existing JS Actions from test project: ${tmpFolderActions}`); + await rm(tmpFolderActions, { force: true, recursive: true }); // this is useful to avoid retaining stale dependencies in the test project. + await mkdir(tmpFolderActions); + log("Copying widget resources JS actions into test project..."); + await Promise.all([ + ...jsActions.map(async file => { + const dest = join(tmpFolderActions, file.replace(jsActionsPath, "")); + await mkdir(dirname(dest), { recursive: true }); + await copyFile(file, dest); + }) + ]); + if (nativeWidgetFolders) { + log(`Deleting existing widgets from test project (widgets=${nativeWidgetFolders.length})...`); + const widgetsDir = join(tmpFolder, "widgets"); + + // backup two web widgets that are used in the test project + const tempBackup = join(tmpFolder, "widgets-backup"); + await mkdir(tempBackup); + + const htmlSnippetWidgetName = "HTMLSnippet.mpk"; + const htmlSnippetTempPath = join(tempBackup, htmlSnippetWidgetName); + const htmlSnippetPath = join(widgetsDir, htmlSnippetWidgetName); + await copyFile(htmlSnippetPath, htmlSnippetTempPath); + + const sprintrFeedbackWidgetName = "SprintrFeedbackWidget.mpk"; + const sprintFeedbackTempPath = join(tempBackup, sprintrFeedbackWidgetName); + const sprintrFeedbackPath = join(widgetsDir, sprintrFeedbackWidgetName); + await copyFile(sprintrFeedbackPath, sprintFeedbackTempPath); + + await rm(widgetsDir, { force: true, recursive: true }); // this is useful to avoid retaining stale widgets in the test project. + await mkdir(widgetsDir); + + await copyFile(htmlSnippetTempPath, htmlSnippetPath); + await copyFile(sprintFeedbackTempPath, sprintrFeedbackPath); + await rm(tempBackup, { force: true, recursive: true }); + + log("Copying widget resources widgets into test project..."); + await Promise.all([ + ...nativeWidgetFolders.map(async folder => { + const src = (await getFiles(folder, [`.mpk`]))[0]; + const dest = join(widgetsDir, basename(src)); + await copyFile(src, dest); + }) + ]); + } + log(`Writing themesource version file for ${moduleInfo.moduleFolderNameInModeler}...`); + await execShellCommand( + `echo ${inputs.version} > themesource/${moduleInfo.moduleFolderNameInModeler}/.version`, + tmpFolder + ); +} diff --git a/scripts/release/createNativeModules.js b/scripts/release/createNativeModules.js index 1c464bfe1..8d8d58e66 100644 --- a/scripts/release/createNativeModules.js +++ b/scripts/release/createNativeModules.js @@ -15,7 +15,7 @@ const { exportModuleWithWidgets, regex } = require("./module-automation/commons"); - +const { getOssFiles, copyFilesToMpk } = require("./module-automation/utils"); const repoRootPath = join(__dirname, "../../"); const [moduleFolderNameInRepo, version] = process.env.TAG.split("-v"); @@ -58,12 +58,16 @@ async function createNativeMobileResourcesModule() { }; moduleInfo = await bumpVersionInPackageJson(moduleFolder, moduleInfo); + const ossFiles = await getOssFiles(moduleFolder, { + package: moduleInfo.moduleNameInModeler, + version: moduleInfo.version + }); await githubAuthentication(moduleInfo); const moduleChangelogs = await updateChangelogs(nativeWidgetFolders, moduleInfo); await commitAndCreatePullRequest(moduleInfo); await updateNativeComponentsTestProject(moduleInfo, tmpFolder, nativeWidgetFolders); const mpkOutput = await createMPK(tmpFolder, moduleInfo, regex.excludeFiles); - await exportModuleWithWidgets(moduleInfo.moduleNameInModeler, mpkOutput, nativeWidgetFolders); + await exportModuleWithWidgets(moduleInfo.moduleNameInModeler, mpkOutput, nativeWidgetFolders, ossFiles); await createGithubRelease(moduleInfo, moduleChangelogs, mpkOutput); if (process.env.CI !== "true") { try { @@ -85,12 +89,17 @@ async function createNanoflowCommonsModule() { moduleFolderNameInModeler: "nanoflowcommons" }; moduleInfo = await bumpVersionInPackageJson(moduleFolder, moduleInfo); + const ossFiles = await getOssFiles(moduleFolder, { + package: moduleInfo.moduleNameInModeler, + version: moduleInfo.version + }); await githubAuthentication(moduleInfo); const moduleChangelogs = await updateModuleChangelogs(moduleInfo); await commitAndCreatePullRequest(moduleInfo); await updateNativeComponentsTestProject(moduleInfo, tmpFolder); const mpkOutput = await createMPK(tmpFolder, moduleInfo, regex.excludeFiles); + await copyFilesToMpk(ossFiles, mpkOutput, moduleInfo.moduleNameInModeler); await createGithubRelease(moduleInfo, moduleChangelogs, mpkOutput); if (process.env.CI !== "true") { try { diff --git a/scripts/release/module-automation/commons.d.ts b/scripts/release/module-automation/commons.d.ts new file mode 100644 index 000000000..24bed53ac --- /dev/null +++ b/scripts/release/module-automation/commons.d.ts @@ -0,0 +1,20 @@ +export const regex: { + excludeFiles: RegExp; +}; + +export function execShellCommand(command: string, cwd?: string): Promise; + +export function getFiles(folder: string, extensions?: string[]): Promise; + +export function getPackageInfo(folder: string): Promise; + +export function cloneRepo(githubUrl: string, localFolder: string): Promise; + +export function createMPK(tmpFolder: string, moduleInfo: any, excludeFilesRegExp: RegExp): Promise; + +export function exportModuleWithWidgets( + moduleNameInModeler: string, + mpkOutput: string, + nativeWidgetFolders: string[], + ossFiles?: Array<{ src: string; dest: string }> +): Promise; diff --git a/scripts/release/module-automation/commons.js b/scripts/release/module-automation/commons.js index e51de0002..717dde883 100644 --- a/scripts/release/module-automation/commons.js +++ b/scripts/release/module-automation/commons.js @@ -261,7 +261,7 @@ function unzip(src, dest) { } // Unzip the module, copy the widget and update package.xml -async function exportModuleWithWidgets(moduleName, mpkOutput, widgetsFolders) { +async function exportModuleWithWidgets(moduleName, mpkOutput, widgetsFolders, additionalFiles) { console.log(`Adding ${widgetsFolders.length} widgets to module ${moduleName}`); const projectPath = mpkOutput.replace(".mpk", ""); const packageXmlFile = join(projectPath, "package.xml"); @@ -298,6 +298,12 @@ async function exportModuleWithWidgets(moduleName, mpkOutput, widgetsFolders) { } catch (e) { throw new Error(`Including widgets in module failed. package.xml of widget/module ${moduleName} not found`); } + // Add additional files to the MPK + if (Array.isArray(additionalFiles)) { + for await (const file of additionalFiles) { + await copyFile(file.src, join(projectPath, file.dest)); + } + } // Re-zip and rename await zip(projectPath, moduleName); await rename(`${projectPath}.zip`, mpkOutput); diff --git a/scripts/release/module-automation/utils.ts b/scripts/release/module-automation/utils.ts new file mode 100644 index 000000000..b7ff2ab57 --- /dev/null +++ b/scripts/release/module-automation/utils.ts @@ -0,0 +1,114 @@ +import { access, copyFile, rename, rm } from "fs/promises"; +import { basename, join } from "path"; +import { globSync } from "glob"; +import { exec } from "child_process"; + +type OssReadMeValidationCriteria = { + package: string; + version: string; +}; + +export async function getOssFiles( + folderPath: string, + validationCriteria?: OssReadMeValidationCriteria +): Promise> { + if (!folderPath || typeof folderPath !== "string") { + throw new TypeError(`Invalid folderPath: ${folderPath}`); + } + + const license = join(folderPath, `License.txt`); + try { + await access(license); + } catch { + throw new Error(`License file not found at expected location: ${license}`); + } + + const readmePattern = "*__*__READMEOSS_*.html"; + const readme = globSync(readmePattern, { cwd: folderPath, absolute: true, ignore: "**/.*/**" })[0]; + if (validationCriteria) { + validateOssReadme(readme, validationCriteria); + } + return [{ src: license, dest: basename(license) }, ...(readme ? [{ src: readme, dest: basename(readme) }] : [])]; +} + +type FilePathPair = { src: string; dest: string }; + +export async function copyFilesToMpk(files: FilePathPair[], mpkOutput: string, moduleName: string): Promise { + const projectPath = mpkOutput.replace(".mpk", ""); + // Unzip the mpk + await unzip(mpkOutput, projectPath); + await rm(mpkOutput, { recursive: true, force: true }); + // Add additional files to the MPK + for await (const file of files) { + await copyFile(file.src, join(projectPath, file.dest)); + } + // Re-zip and rename + await zip(projectPath, moduleName); + await rename(`${projectPath}.zip`, mpkOutput); +} + +export function zip(src: string, fileName: string): Promise { + return execShellCommand(`cd "${src}" && zip -r ../${fileName} .`); +} + +export function unzip(src: string, dest: string): Promise { + return execShellCommand(`unzip "${src}" -d "${dest}"`); +} + +export function execShellCommand(cmd: string, workingDirectory = process.cwd()): Promise { + return new Promise((resolve, reject) => { + exec(cmd, { cwd: workingDirectory }, (error, stdout, stderr) => { + if (error) { + console.warn(stderr); + console.warn(stdout); + reject(error); + } + if (stderr) { + console.warn(stderr); + } + resolve(stdout); + }); + }); +} + +export function validateOssReadme(ossReadme: string, validationCriteria: OssReadMeValidationCriteria): void { + if (!ossReadme || typeof ossReadme !== "string") { + throw new TypeError(`Invalid OSS README path/name: ${ossReadme}`); + } + if (!validationCriteria.version || typeof validationCriteria.version !== "string") { + throw new TypeError(`Invalid version: ${validationCriteria.version}`); + } + if (!validationCriteria.package || typeof validationCriteria.package !== "string") { + throw new TypeError(`Invalid package name: ${validationCriteria.package}`); + } + + const fileName = basename(ossReadme); + const expectedPackage = validationCriteria.package.trim(); + const expectedVersion = validationCriteria.version.trim(); + + // File name pattern: SiemensMendix____READMEOSS_*.html + // Example: SiemensMendixNanoflowCommons__6.3.1__READMEOSS_2026-02-10__04-28-37.html + const parsed = fileName.match(/^SiemensMendix(.+?)__(.+?)__READMEOSS_(.+)\.html$/); + + if (!parsed) { + throw new Error( + `OSS README validation failed: '${fileName}' does not match expected pattern ` + + `'SiemensMendix____READMEOSS_*.html'.` + ); + } + + const foundPackage = parsed[1]; + const foundVersion = parsed[2]; + + if (foundPackage !== expectedPackage) { + throw new Error( + `OSS README validation failed: expected package '${expectedPackage}' but found '${foundPackage}' in '${fileName}'.` + ); + } + + if (foundVersion !== expectedVersion) { + throw new Error( + `OSS README validation failed: expected version '${expectedVersion}' but found '${foundVersion}' in '${fileName}'.` + ); + } +} diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json new file mode 100644 index 000000000..90f5c1494 --- /dev/null +++ b/scripts/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "@mendix/pluggable-widgets-tools/configs/tsconfig.base", + "compilerOptions": { + "module": "commonjs" + }, + "include": ["./**/*.ts"] +}