diff --git a/CHANGELOG.md b/CHANGELOG.md index d6df4851c5..dee39f11ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to the Wazuh app project will be documented in this file. -## Wazuh v4.6.0 - OpenSearch Dashboards 2.8.0 - Revision 03 +## Wazuh v4.6.0 - OpenSearch Dashboards 2.8.0 - Revision 05 ### Added diff --git a/RELEASING.md b/RELEASING.md index fb8ae04435..d5d2b76786 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -10,23 +10,22 @@ The following files must be updated: -- `package.json`: Defines the package manifest. It contains the following properties: +- `plugins/*/package.json`: Defines the package manifest. It contains the following properties: - `version`: Plugin version. Schema: `{major}.{minor}.{patch}`. Example: 4.4.5 - `revision`: Plugin revision. Schema: number with 2 digits. This value is reset for each version to `01` and increament for following revisions. - `pluginPlatform.version`: version of the plugin platform. -- `opensearch_dashboards.json` or `kibana.json`: Defines the plugin manifest. It contains the following properties: +- `plugins/*/opensearch_dashboards.json` or `kibana.json`: Defines the plugin manifest. It contains the following properties: - `version`: Combination of version and revision of the plugin: `{version}-{revision}`. -- `README.md`: References to the version of server, indexer and dashboard applications. - `CHANGELOG.md`: Changelog of the new release. -- `common/api-info/endpoints.json`: Data related to endpoints and extracted from server's API -- `common/api-info/security-actions.json`: Data related to security actions of extracted from server's API +- `plugins/main/common/api-info/endpoints.json`: Data related to endpoints and extracted from server's API +- `plugins/maincommon/api-info/security-actions.json`: Data related to security actions of extracted from server's API - Unit tests To bump the version, see [# Bump](#Bump) #### Update the API info static files -We have a script to update the files that have information about the Wazuh API. This script uses the API specification +We have a script to update the files of the `plugins/main` that have information about the Wazuh API. This script uses the API specification file that is stored in the GitHub repository of [wazuh/wazuh](https://github.com/wazuh/wazuh) repository. This must run for each version. ```console @@ -74,7 +73,7 @@ git pull 3. Create the tag ``` -git tag {tag} -a -m "Wazuh {version} for {platform} {platform version}" +git tag {tag} -a -m "Wazuh {version} for OpenSearch Dashboards {platform version}" ``` > replace the placeholders: @@ -83,8 +82,7 @@ git tag {tag} -a -m "Wazuh {version} for {platform} {platform version}" > - pre-alpha: `-pre-alpha{number}`. Example: `-pre-alpha1`. > - release candidates: `-rc{number}`. Example: `-rc1`. > - `{version}`: plugin version -> - `{platform}`: platform name. One of `OpenSearch` or `Kibana` -> - `{platform}`: platform version. +> - `{platform version}`: platform version. 4. Push the tag @@ -98,38 +96,43 @@ git push origin {tag} #### Create tags - Script -The process to create all the required tags can be run through a script ( `scripts/release/tag` ). +The process to create the required tag can be run through a script ( `scripts/release/tag.js` ). -For each supported version defined in `scripts/release/tag` +- for each plugin in `plugins-directory`: + - edit `version`, `revision`, `pluginPlatfrom.version` in the package manifest file: `package.json` + - edit the `version` property in plugin manifest file: `opensearch_dashboards.json` +- edit the entry in the `CHANGELOG.md` file +- commit (if required) +- create local tag +- push local tag to remote -- edit `revision` package manifest file: `package.json` -- edit the `version` property in plugin manifest file: `opensearch_dashboards.json` or `kibana.json` -- commit -- create tag -- push tag +Steps: -The script can be run through the package script `yarn release:tag` too. This is the prefered method because defines some required parameters. +1. Ensure the others files are updated. -Steps: +2. Bump version/revision/platform version and create the local and remote tags using the script + +- Define the `version`, `revision` and `pluginPlatformVersion`: -1. Ensure the target versions are defined as the supported versions in `scripts/release/tag` and the others files are updated. - Currently there are 3 platforms: OpenDistro (Kibana 7.10.2), Kibana 7.16-7.17 and OpenSearch (Wazuh stack). +```console +node scripts/release/tag.js --plugins-directory ./plugins --version 4.6.0 --revision 03 --platform-version 2.8.0 +``` -2. Bump version/revision/platform version and create the local and remote tag using the package script +- Use a package manifest as base to take the `version`, `revision` and `pluginPlatformVersion` values: ```console -yarn release:tag --revision +node scripts/release/tag.js --plugins-directory ./plugins --manifest-plugin ./plugins/main/package.json ``` > If the version or the revision is not specified, then it will use the current values from the package manifest file (package.json). -> You can bump the `version` or `platform-version` too or combine them. -> :warning: if the `version` is set, the base branches must exist in the remote repository. +> You can bump the `version`, `revision` or `platform-version` too or combine them in this step. It is not recommended because these +> values should be bumped previously. ```console -yarn release:tag --version -yarn release:tag --revision -yarn release:tag --platform-version -yarn release:tag --version --revision --platform-version +node scripts/release/tag.js --plugins-directory ./plugins --version +node scripts/release/tag.js --plugins-directory ./plugins --revision +node scripts/release/tag.js --plugins-directory ./plugins --platform-version +node scripts/release/tag.js --plugins-directory ./plugins --version --revision --platform-version ``` Examples: @@ -137,49 +140,37 @@ Examples: - Change the plugin version ```console -yarn release:tag --version 4.5.0 +node scripts/release/tag.js --plugins-directory ./plugins --version 4.5.0 ``` - Change the plugin revision ```console -yarn release:tag --revision 02 +node scripts/release/tag.js --plugins-directory ./plugins --revision 02 ``` - Change the platform version ```console -yarn release:tag --platform-version 2.8.0 +node scripts/release/tag.js --plugins-directory ./plugins --platform-version 2.8.0 ``` - Change the plugin version, revision and platform version ```console -yarn release:tag --version 4.5.0 --revision 02 --platform-version 2.8.0 +node scripts/release/tag.js --plugins-directory ./plugins --version 4.5.0 --revision 02 --platform-version 2.8.0 ``` For tags that needs a suffix, use the `--tag-suffix ` flag. ```console -yarn release:tag --tag-suffix +node scripts/release/tag.js --plugins-directory ./plugins --tag-suffix ``` Example: ```console -yarn release:tag --tag-suffix -rc2 --revision 02 -``` - -If you want to get a report of the tags generated and stored locally, use the `--export-tags `. - -```console -yarn release:tag --revision --export-tags -``` - -Example: - -```console -yarn release:tag --version 4.5.0 --export-tags tags.log +node scripts/release/tag.js --plugins-directory ./plugins --tag-suffix -rc2 --revision 02 ``` 3. Review the new tags were pushed to the remote repository. @@ -194,18 +185,14 @@ yarn release:tag --version 4.5.0 --export-tags tags.log ### Bump -It means to increment the version number to a new, unique value. +It means to increment the version number to a new and unique value. -Bumping the version requires to do some changes in the source code of the application. See [# Files](#files). +Bumping the version requires to do some changes in the source code of the plugins. See [# Files](#files). -We have a script (`scripts/release/bump`) to update some of these files: +We have a script (`scripts/release/bump`) to update some of these files for each plugin: - package.json -- opensearch_dashboards.json or kibana.json - -This can be run through the `yarn release:bump` package script too. This is the prefered method because defines some required parameters. **The rest of the files should be changed manually.** - -> The package script sets some required parameters related to manifest files. +- opensearch_dashboards.json Steps: @@ -219,17 +206,16 @@ git checkout -b 2. Bump the version/revision/platform version using the package script +- Define the values for `version`, `revision` and `platform-version`: + ```console -yarn release:bump --version +node scripts/release/bump.js --plugins-directory ./plugins --version --revision --platform-version ``` -> You can bump the `revision` or `platform-version` too or combine them. +- Take the values from a package manifest file and replace some value ```console -yarn release:bump --version -yarn release:bump --revision -yarn release:bump --platform-version -yarn release:bump --version --revision --platform-version +node scripts/release/bump.js --plugins-directory ./plugins --manifest-package ./plugins/main/package.json --revision ``` Examples: @@ -237,25 +223,25 @@ Examples: - Change the plugin version ```console -yarn release:bump --version 4.5.0 +node scripts/release/bump.js --plugins-directory ./plugins --manifest-package ./plugins/main/package.json --version 4.5.0 ``` - Change the plugin revision ```console -yarn release:bump --revision 02 +node scripts/release/bump.js --plugins-directory ./plugins --manifest-package ./plugins/main/package.json --revision 02 ``` - Change the platform version ```console -yarn release:bump --platform-version 2.8.0 +node scripts/release/bump.js --plugins-directory ./plugins --manifest-package ./plugins/main/package.json --platform-version 2.8.0 ``` - Change the plugin version, revision and platform version ```console -yarn release:bump --version 4.5.0 --revision 02 --platform-version 2.8.0 +node scripts/release/bump.js --plugins-directory ./plugins --version 4.5.0 --revision 02 --platform-version 2.8.0 ``` 3. Apply manually the changes to the rest of files if needed it. See [# Files](#Files). diff --git a/plugins/main/opensearch_dashboards.json b/plugins/main/opensearch_dashboards.json index d0438c38bc..faeee73c80 100644 --- a/plugins/main/opensearch_dashboards.json +++ b/plugins/main/opensearch_dashboards.json @@ -1,6 +1,6 @@ { "id": "wazuh", - "version": "4.6.0-03", + "version": "4.6.0-05", "opensearchDashboardsVersion": "opensearchDashboards", "configPath": [ "wazuh" @@ -26,4 +26,4 @@ ], "server": true, "ui": true -} +} \ No newline at end of file diff --git a/plugins/main/package.json b/plugins/main/package.json index 5c79eae172..da7e13dc9c 100644 --- a/plugins/main/package.json +++ b/plugins/main/package.json @@ -1,7 +1,7 @@ { "name": "wazuh", "version": "4.6.0", - "revision": "03", + "revision": "05", "pluginPlatform": { "version": "2.8.0" }, @@ -41,8 +41,6 @@ "test:jest": "node scripts/jest", "test:jest:runner": "node scripts/runner test", "generate:api-data": "node scripts/generate-api-data.js --spec https://raw.githubusercontent.com/wazuh/wazuh/$(node -e \"console.log(require('./package.json').version.split('.').splice(0,2).join('.'))\")/api/api/spec/spec.yaml --output file --output-directory common/api-info --display-configuration", - "release:bump": "node scripts/release/bump --manifest-package package.json --manifest-plugin opensearch_dashboards.json --manifest-changelog ../../CHANGELOG.md", - "release:tag": "node scripts/release/tag --manifest-package package.json --manifest-changelog ../../CHANGELOG.md", "prebuild": "node scripts/generate-build-version" }, "dependencies": { @@ -87,4 +85,4 @@ "tslint": "^6.1.3", "typescript-eslint-parser": "^22.0.0" } -} +} \ No newline at end of file diff --git a/plugins/main/scripts/release/bump.js b/plugins/main/scripts/release/bump.js index 27c4ec0409..0d95f01281 100644 --- a/plugins/main/scripts/release/bump.js +++ b/plugins/main/scripts/release/bump.js @@ -1,328 +1,7 @@ -// NodeJS script which receives a version, revision and/or platform version and updates -// the package.json file -// Usage: node bump.js -// Help: node bump.js --help -// Examples: node bump.js --examples +// Specific process to bump this plugin -// Process -// 1. Take values from stdin -// 2. Edit the package and plugin manifest files -// 3. Display warning about manual changes - -const cliName = 'bump'; -const cliDescription = `Bump the plugin version, revision and/or platform version -Some warning messages are sent to stderr.`; - -// Default configuration -const defaultConfiguration = { - displayConfiguration: false, - displayExamples: false, - displayHelp: false, - version: '', - revision: '', - platformVersion: '', - manifestPackage: '', - manifestPlugin: '', - manifestChangelog: '', -}; - -const logger = require('./lib/logger'); - -const { readPackageManifest } = require('./lib/read-manifest-package'); -const { updatePackageManifest } = require('./lib/update-manifest-package'); -const { updatePluginManifest } = require('./lib/update-manifest-plugin'); -const { updateChangelog } = require('./lib/update-changelog'); - -/** - * - * @param {String[]} input Input parameters - * @returns {Object} the configuration values - */ -function parse(input) { - const configuration = {}; - // Parse the input parameters - while (input.length) { - // Extract the first parameter - const [parameter] = input.splice(0, 1); - - // Compare the parameter - switch (parameter) { - case '--debug': - // Set the logger to debug mode - logger.setLevel(0); - break; - case '--display-configuration': - // Display the configuration - configuration.displayConfiguration = true; - break; - case '--examples': - // Display the examples - configuration.displayExamples = true; - break; - case '--help': - // Display the help - configuration.displayHelp = true; - break; - case '--version': { - // Set the version - const version = typeof input[0] === 'string' && input[0]; - - if (version) { - if (/\d+\.\d+\.\d+/.test(version)) { - configuration.version = version; - input.splice(0, 1); - } else { - logger.error( - 'version parameter is not valid. Expected format: X.Y.Z where X,Y, and Z are numbers.', - ); - process.exit(1); - } - } else { - logger.error('version parameter is not defined.'); - process.exit(1); - } - break; - } - case '--revision': { - // Set the version - const revision = typeof input[0] === 'string' && input[0]; - - if (revision) { - if (/\d{2}/.test(revision)) { - configuration.revision = revision; - input.splice(0, 1); - } else { - logger.error( - 'revision parameter is not valid. Expected format: Number', - ); - process.exit(1); - } - } else { - logger.error('revision parameter is not defined.'); - process.exit(1); - } - break; - } - case '--platform-version': { - // Set the version - const platformVersion = typeof input[0] === 'string' && input[0]; - - if (platformVersion) { - if (/\d+\.\d+\.\d+/.test(platformVersion)) { - configuration.platformVersion = platformVersion; - input.splice(0, 1); - } else { - logger.error( - 'platform-version parameter is not valid. Expected format: X.Y.Z where X,Y, and Z are numbers.', - ); - process.exit(1); - } - } else { - logger.error('platform-version parameter is not defined.'); - process.exit(1); - } - break; - } - case '--manifest-package': { - // Set the version - const manifestPackage = typeof input[0] === 'string' && input[0]; - - if (manifestPackage) { - configuration.manifestPackage = manifestPackage; - input.splice(0, 1); - } else { - logger.error('manifest-package parameter is not defined.'); - process.exit(1); - } - break; - } - case '--manifest-plugin': { - // Set the version - const manifestPlugin = typeof input[0] === 'string' && input[0]; - - if (manifestPlugin) { - configuration.manifestPlugin = manifestPlugin; - input.splice(0, 1); - } else { - logger.error('manifest-plugin parameter is not defined.'); - process.exit(1); - } - break; - } - case '--manifest-changelog': { - // Set the manifest changelog - const manifestChangelog = typeof input[0] === 'string' && input[0]; - - if (manifestChangelog) { - configuration.manifestChangelog = manifestChangelog; - input.splice(0, 1); - } else { - logger.error('manifest-changelog parameter is not defined.'); - process.exit(1); - } - break; - } - default: { - } - } - } - return configuration; -} - -const usageOptionsMessage = `Options: - --debug Set the logger to debug mode. - --display-configuration Display the configuration. Log to sterr. - --examples Display examples of usage. - --help Display the help. - --manifest-changelog Set the changelog manifest file location. - --manifest-package Set the package manifest file location. - --manifest-plugin Set the plugin platform manifest file location. - --platform-version Set the platform version. - --revision Set the revision. - --version Set the version.`; - -/** - * Display the CLI help - */ -function displayHelp() { - console.log(`${cliName} - Help -${cliDescription} - -Usage: node ${cliFilePath} [options] - -${usageOptionsMessage} -`); -} - -/** - * Display the examples - */ -function displayExamples() { - console.log(` -- Change the plugin version -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --version 4.5.0 - -- Change the plugin revision -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --revision 02 --manifest-package ../package.json - -- Change the platform version -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --platform-version 2.8.0 - -- Change the plugin version, revision and platform version -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --version 4.5.0 --revision 02 --platform-version 2.8.0 -`); -} - -// Display the message to do manual changes -function displayMessageManualChanges() { - logger.warn( - 'Some files could require to do changes manually. See RELEASING.md.', - ); -} - -function run(configuration) { - const { - version, - revision, - platformVersion, - manifestPackage, - manifestPlugin, - manifestChangelog, - } = configuration; - version && logger.info(`Version: ${version}`); - revision && logger.info(`Revision: ${revision}`); - platformVersion && logger.info(`Platform version: ${platformVersion}`); - manifestPackage && logger.info(`Package manifest: ${manifestPackage}`); - manifestPlugin && logger.info(`Plugin manifest: ${manifestPlugin}`); - manifestChangelog && logger.info(`Changelog: ${manifestChangelog}`); - - logger.info( - 'This will update the manifest files: package and platform plugin.', - ); - - updatePackageManifest(manifestPackage, { - version, - revision, - platformVersion, - }); - - updatePluginManifest(manifestPlugin, { - version, - revision, - }); - - updateChangelog(manifestChangelog, { - version, - revision, - platformVersion, - }); - - displayMessageManualChanges(); -} - -function main(input) { - try { - // Display the help information and exit if there is no parameters - if (input.length === 0) { - displayHelp(); - process.exit(1); - } - - const configuration = { - ...defaultConfiguration, - ...parse(input), - }; - - // Display the configuration - if (configuration.displayConfiguration) { - /* Send to stderr. This does the configuration can be displayed and redirect the stdout output - to a file */ - console.error(configuration); - } - - // Display the help - if (configuration.displayHelp) { - displayHelp(); - process.exit(0); - } - - // Display the examples of usage - if (configuration.displayExamples) { - displayExamples(); - process.exit(0); - } - - // Check version is set - if (!configuration.version || !configuration.revision) { - const { version: manifestVersion, revision: manifestRevision } = - readPackageManifest(configuration.manifestPackage); - if (!configuration.version) { - logger.warn( - `version is not defined. Using from the current package manifest ${configuration.manifestPackage}: ${manifestVersion}`, - ); - configuration.version = manifestVersion; - } - if (!configuration.revision) { - logger.warn( - `revision is not defined. Using from the current package manifest ${configuration.manifestPackage}: ${manifestRevision}`, - ); - configuration.revision = manifestRevision; - } - } - - run(configuration); - } catch (error) { - logger.error(`An unexpected error: ${error}. ${error.stack}`); - process.exit(1); - } +function run({ logger, ...rest }) { + logger.warn('This plugin must update the API data'); } module.exports = run; - -let cliFilePath = __dirname; - -if (require.main === module) { - cliFilePath = process.argv[1]; - const consoleInputParameters = [...process.argv].slice(2); - main(consoleInputParameters); -} diff --git a/plugins/main/scripts/release/lib/logger.js b/plugins/main/scripts/release/lib/logger.js deleted file mode 100644 index 17659895e3..0000000000 --- a/plugins/main/scripts/release/lib/logger.js +++ /dev/null @@ -1,20 +0,0 @@ -let minimumLevel = 1; - -function setLevel(level) { - minimumLevel = level; -} - -function createLogLevel(tag, level, fn) { - return function (message) { - level >= minimumLevel && fn(`[${tag}]: ${message}`); - }; -} - -module.exports = { - info: createLogLevel('INFO', 2, console.log), - warn: createLogLevel('WARN', 1, console.log), - error: createLogLevel('ERROR', 2, console.log), - debug: createLogLevel('DEBUG', 0, console.log), - getLevel: () => minimumLevel, - setLevel: setLevel, -}; diff --git a/plugins/main/scripts/release/lib/read-manifest-package.js b/plugins/main/scripts/release/lib/read-manifest-package.js deleted file mode 100644 index e4bdbbff2f..0000000000 --- a/plugins/main/scripts/release/lib/read-manifest-package.js +++ /dev/null @@ -1,20 +0,0 @@ -const logger = require('./logger'); - -function readPackageManifest(manifestPath) { - if (!manifestPath) { - logger.error( - `package manifest file is not defined. Use --manifest-package .`, - ); - process.exit(1); - } - const fs = require('fs'); - logger.debug(`Reading file ${manifestPath}`); - const packageJson = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); - logger.debug(`Read file ${manifestPath}: ${JSON.stringify(packageJson)}`); - - return packageJson; -} - -module.exports = { - readPackageManifest: readPackageManifest, -}; diff --git a/plugins/main/scripts/release/lib/update-changelog.js b/plugins/main/scripts/release/lib/update-changelog.js deleted file mode 100644 index cb24a07d13..0000000000 --- a/plugins/main/scripts/release/lib/update-changelog.js +++ /dev/null @@ -1,63 +0,0 @@ -const logger = require('./logger'); - -function updateChangelog( - changelogPath, - { version, revision, platformVersion }, -) { - if (!changelogPath) { - logger.error( - `changelog file is not defined. Use --manifest-changelog .`, - ); - process.exit(1); - } - const fs = require('fs'); - logger.debug(`Reading file ${changelogPath}`); - const content = fs.readFileSync(changelogPath, 'utf8'); - logger.debug(`Read file ${changelogPath}`); - const reChangelogEntry = `(Wazuh v${version.replace( - /\./g, - '\\.', - )} - [\\w\\s]+) ([\\d.]+) - Revision (\\d+)`; - if (version && (revision || platformVersion)) { - logger.debug( - 'Regular expression to find in changelog: ' + reChangelogEntry, - ); - if (content.search(reChangelogEntry) > -1) { - const textReplaceEntry = - '$1' + - ' ' + - (platformVersion || '$2') + - ' ' + - '- Revision' + - ' ' + - (revision || '$3'); - logger.debug( - `Update changelog: regular expression ${reChangelogEntry}: ${textReplaceEntry}`, - ); - const newContent = content.replace( - new RegExp(reChangelogEntry), - textReplaceEntry, - ); - if (newContent !== content) { - logger.debug(`Updating ${changelogPath}`); - fs.writeFileSync(changelogPath, newContent); - logger.info(`Updated ${changelogPath}`); - } - } else { - logger.warn( - `Changelog entry not found for ${[ - { text: 'version', value: version }, - { text: 'revision', value: revision }, - { text: 'platformVersion', value: platformVersion }, - ] - .filter(({ value }) => value) - .map(({ text, value }) => `${text}: ${value}`) - .join(', ')}. YOU SHOULD ADD THE ENTRY TO THE CHANGELOG FILE.`, - ); - } - } -} - -module.exports = { - updateChangelog: updateChangelog, -}; diff --git a/plugins/main/scripts/release/lib/update-manifest-package.js b/plugins/main/scripts/release/lib/update-manifest-package.js deleted file mode 100644 index a3e7490a0b..0000000000 --- a/plugins/main/scripts/release/lib/update-manifest-package.js +++ /dev/null @@ -1,36 +0,0 @@ -const logger = require('./logger'); - -function updatePackageManifest( - manifestPath, - { version, revision, platformVersion }, -) { - if (!manifestPath) { - logger.error( - `package manifest file is not defined. Use --manifest-package .`, - ); - process.exit(1); - } - const fs = require('fs'); - logger.debug(`Reading file ${manifestPath}`); - const packageJson = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); - logger.debug(`Read file ${manifestPath}: ${JSON.stringify(packageJson)}`); - version && - (packageJson.version = version) && - logger.debug(`Change version to ${packageJson.version}`); - revision && - (packageJson.revision = revision) && - logger.debug(`Change revision to ${packageJson.revision}`); - platformVersion && - (packageJson.pluginPlatform.version = platformVersion) && - logger.debug( - `Change platform version to ${packageJson.pluginPlatform.version}`, - ); - - logger.debug(`Updating ${manifestPath}: ${JSON.stringify(packageJson)}`); - fs.writeFileSync(manifestPath, JSON.stringify(packageJson, null, 2)); - logger.info(`Updated ${manifestPath}`); -} - -module.exports = { - updatePackageManifest: updatePackageManifest, -}; diff --git a/plugins/main/scripts/release/lib/update-manifest-plugin.js b/plugins/main/scripts/release/lib/update-manifest-plugin.js deleted file mode 100644 index dcacfebe9b..0000000000 --- a/plugins/main/scripts/release/lib/update-manifest-plugin.js +++ /dev/null @@ -1,35 +0,0 @@ -const logger = require('./logger'); - -function updatePluginManifest(manifestPath, { version, revision }) { - if (!manifestPath) { - logger.error( - `plugin manifest file is not defined. Use --manifest-plugin .`, - ); - process.exit(1); - } - - if (!version) { - logger.error(`version is not defined. Use --version .`); - process.exit(1); - } - - if (!revision) { - logger.error(`revision is not defined. Use --revision .`); - process.exit(1); - } - - const fs = require('fs'); - logger.debug(`Reading file ${manifestPath}`); - const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); - logger.debug(`Read file ${manifestPath}: ${JSON.stringify(manifest)}`); - manifest.version = `${version}-${revision}`; - logger.debug(`Change version to: ${manifestPath}: ${manifest.version}`); - - logger.debug(`Updating ${manifestPath}: ${JSON.stringify(manifest)}`); - fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2)); - logger.info(`Updated ${manifestPath}`); -} - -module.exports = { - updatePluginManifest: updatePluginManifest, -}; diff --git a/plugins/main/scripts/release/tag.js b/plugins/main/scripts/release/tag.js deleted file mode 100644 index 1ffeb231b4..0000000000 --- a/plugins/main/scripts/release/tag.js +++ /dev/null @@ -1,484 +0,0 @@ -// NodeJS script which creates the tags in local and remote for the supported versions. -// It receives a version, revision and/or platform version and for each -// supported version: updates the package and plugin manifest files and create the tag. -// Usage: node tag.js -// Help: node tag.js --help -// Examples: node tag.js --examples - -// Process -// 1. Parse stdin -// 2. For each supported platform version -// 2.1. Checkout to the platform base branch -// 2.2. Prune local branches and tags -// 2.3. Edit the package manifest file -// 2.4. Edit the plugin manifest file -// 2.5. Commit -// 2.6. Create tag -// 2.7. Push tag -// 2.8. Reset local branch to remote branch -// 3. Optional. Export tags to file - -const cliName = 'tag'; -const cliDescription = `Create the tags in remote repository for the supported versions. -Some warning messages are sent to stderr.`; - -// Default configuration -const defaultConfiguration = { - displayConfiguration: false, - displayExamples: false, - displayHelp: false, - version: '', - revision: '', - platformVersion: '', - ignoreConfirmation: false, - manifestPackage: '', - manifestPlugin: '', - manifestChangelog: '', - tagSuffix: '', - exportTagsToFile: '', -}; - -const logger = require('./lib/logger'); - -const { readPackageManifest } = require('./lib/read-manifest-package'); -const bump = require('./bump'); -const readline = require('readline'); - -// Supported versions -function getSupportedVersions(pluginVersion) { - return { - OpenSearch: { - branch: pluginVersion, - versions: ['2.8.0'], - manifestPluginPath: 'opensearch_dashboards.json', - }, - }; -} - -/** - * - * @param {String[]} input Input parameters - * @returns {Object} the configuration values - */ -function parse(input) { - const configuration = {}; - // Parse the input parameters - while (input.length) { - // Extract the first parameter - const [parameter] = input.splice(0, 1); - - // Compare the parameter - switch (parameter) { - case '--debug': - // Set the logger to debug mode - logger.setLevel(0); - break; - case '--display-configuration': - // Display the configuration - configuration.displayConfiguration = true; - break; - case '--export-tags': { - // Export tags to file - const exportTagsToFile = typeof input[0] === 'string' && input[0]; - if (exportTagsToFile) { - configuration.exportTagsToFile = exportTagsToFile; - input.splice(0, 1); - } else { - logger.error('export-tags parameter is not defined.'); - process.exit(1); - } - break; - } - case '--examples': - // Display the examples - configuration.displayExamples = true; - break; - case '--help': - // Display the help - configuration.displayHelp = true; - break; - case '--ignore-confirmation': - // Display the help - configuration.ignoreConfirmation = true; - break; - case '--version': { - // Set the version - const version = typeof input[0] === 'string' && input[0]; - - if (version) { - if (/\d+\.\d+\.\d+/.test(version)) { - configuration.version = version; - input.splice(0, 1); - } else { - logger.error( - 'version parameter is not valid. Expected format: X.Y.Z where X,Y, and Z are numbers.', - ); - process.exit(1); - } - } else { - logger.error('version parameter is not defined.'); - process.exit(1); - } - break; - } - case '--revision': { - // Set the version - const revision = typeof input[0] === 'string' && input[0]; - - if (revision) { - if (/\d{2}/.test(revision)) { - configuration.revision = revision; - input.splice(0, 1); - } else { - logger.error( - 'revision parameter is not valid. Expected format: Number', - ); - process.exit(1); - } - } else { - logger.error('revision parameter is not defined.'); - process.exit(1); - } - break; - } - case '--platform-version': { - // Set the version - const platformVersion = typeof input[0] === 'string' && input[0]; - - if (platformVersion) { - if (/\d+\.\d+\.\d+/.test(platformVersion)) { - configuration.platformVersion = platformVersion; - input.splice(0, 1); - } else { - logger.error( - 'platform-version parameter is not valid. Expected format: X.Y.Z where X,Y, and Z are numbers.', - ); - process.exit(1); - } - } else { - logger.error('platform-version parameter is not defined.'); - process.exit(1); - } - break; - } - case '--tag-suffix': { - // Set the version - const tagSuffix = typeof input[0] === 'string' && input[0]; - - if (tagSuffix) { - configuration.tagSuffix = tagSuffix; - input.splice(0, 1); - } else { - logger.error('tag-suffix parameter is not defined.'); - process.exit(1); - } - break; - } - case '--manifest-package': { - // Set the version - const manifestPackage = typeof input[0] === 'string' && input[0]; - - if (manifestPackage) { - configuration.manifestPackage = manifestPackage; - input.splice(0, 1); - } else { - logger.error('manifest-package parameter is not defined.'); - process.exit(1); - } - break; - } - case '--manifest-plugin': { - // Set the version - const manifestPlugin = typeof input[0] === 'string' && input[0]; - - if (manifestPlugin) { - configuration.manifestPlugin = manifestPlugin; - input.splice(0, 1); - } else { - logger.error('manifest-plugin parameter is not defined.'); - process.exit(1); - } - break; - } - case '--manifest-changelog': { - // Set the manifest changelog - const manifestChangelog = typeof input[0] === 'string' && input[0]; - - if (manifestChangelog) { - configuration.manifestChangelog = manifestChangelog; - input.splice(0, 1); - } else { - logger.error('manifest-changelog parameter is not defined.'); - process.exit(1); - } - break; - } - default: { - } - } - } - return configuration; -} - -const usageOptionsMessage = `Options: - --debug Set the logger to debug mode. - --display-configuration Display the configuration. Log to sterr. - --examples Display examples of usage. - --export-tags Export tags to file. - --help Display the help. - --ignore-confirmation Ignore the confirmation. - --manifest-changelog Set the changelog manifest file location. - --manifest-package Set the package manifest file location. - --manifest-plugin Set the plugin platform manifest file location. - --platform-version Set the platform version. - --revision Set the revision. - --tag-suffix Set the tag suffix. - --version Set the version.`; - -/** - * Display the CLI help - */ -function displayHelp() { - console.log(`${cliName} - Help -${cliDescription} - -Usage: node ${cliFilePath} [options] - -${usageOptionsMessage} -`); -} - -/** - * Display the examples - */ -function displayExamples() { - console.log(` -- Change the plugin version -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --version 4.5.0 - -- Change the plugin revision -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --revision 02 - -- Change the platform version -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --platform-version 2.8.0 - -- Change the plugin version, revision and platform version -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --version 4.5.0 - -- Change plugin revision and export tags to file -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --export-tags tags.log --revision 02 - -- Change plugin revision and ignoring the confirmation -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --ignore-confirmation --revision 02 - -- Change plugin revision and redirect the stdout and stderr to a file -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --ignore-confirmation --revision 02 &> /path/to/create_tags.log - -- Change plugin revision, redirect the stdout and stderr to a file and export tags to file -node ${cliFilePath} --manifest-package package.json --manifest-plugin opensearch_dashboards.json --ignore-confirmation --revision 02 --export-tags tags.log &> /path/to/create_tags.log -`); -} - -async function question(question) { - return new Promise(res => { - const rd = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - - rd.question(question, input => { - rd.close(); - res(input); - }); - }); -} - -async function requireConfirmation({ ignoreConfirmation }) { - logger.warn( - 'Ensure the base branches are created in the remote and they have updated the files: ' + - 'README.md, CHANGELOG.md, unit tests files, API data files. ' + - 'It does not modify these files.', - ); - - logger.warn( - 'This script will commit and push the tags to the remote repository, ' + - 'deleting any unpushed changes.', - ); - - if (!ignoreConfirmation) { - const response = await question('Do you want to continue? [y/N] '); - if (response.toLowerCase() !== 'y') { - logger.info('Aborting...'); - process.exit(0); - } - } -} - -async function run(configuration) { - let { - version, - revision, - platformVersion, - tagSuffix, - exportTagsToFile, - ignoreConfirmation, - } = configuration; - if (!version || !revision) { - const { version: manifestVersion, revision: manifestRevision } = - readPackageManifest(configuration.manifestPackage); - if (!version) { - logger.warn( - `version is not defined. Using from the current package manifest ${configuration.manifestPackage}: ${manifestVersion}`, - ); - configuration.version = version = manifestVersion; - } - if (!revision) { - logger.warn( - `revision is not defined. Using from the current package manifest ${configuration.manifestPackage}: ${manifestRevision}`, - ); - configuration.revision = revision = manifestRevision; - } - } - version && logger.info(`Version: ${version}`); - revision && logger.info(`Revision: ${revision}`); - platformVersion && logger.info(`Platform version: ${platformVersion}`); - tagSuffix && logger.info(`Tag suffix: ${tagSuffix}`); - exportTagsToFile && logger.info(`Export tags to file: ${exportTagsToFile}`); - - const supportedVersions = getSupportedVersions(version); - logger.info('Supported platforms'); - for (const platformID in supportedVersions) { - const { - branch, - versions: pluginPlatformVersions, - manifestPluginPath, - } = supportedVersions[platformID]; - logger.info( - `Platform: ${platformID} - Base branch: ${branch} - Versions: [${pluginPlatformVersions.join( - ', ', - )}] - Manifest plugin path: ${manifestPluginPath}`, - ); - } - - await requireConfirmation({ ignoreConfirmation }); - - const { execSync } = require('child_process'); - - function execSystem(command) { - logger.info(`Run command: ${command}`); - return execSync(command); - } - - for (const platformID in supportedVersions) { - const { - branch, - versions: pluginPlatformVersions, - manifestPluginPath, - } = supportedVersions[platformID]; - - for (const pluginPlatformVersion of pluginPlatformVersions) { - logger.debug(`Switching to branch: ${branch}`); - execSystem(`git checkout ${branch}`); - logger.info(`Switched to branch: ${branch}`); - logger.debug('Pruning local branches and tags'); - execSystem('git fetch --prune --prune-tags'); - logger.info('Pruned local branches and tags'); - - const tag = `v${version}-${pluginPlatformVersion}${tagSuffix}`; - logger.info(`Generating tag: ${tag}...`); - logger.info('Calling to bump script'); - const configurationBump = { - ...configuration, - manifestPlugin: manifestPluginPath, - platformVersion: pluginPlatformVersion, - }; - logger.debug( - `Configuration to use with the bump script: ${configurationBump}`, - ); - - bump(configurationBump); - - logger.debug('Checking if there are changes to commit'); - const thereChangesToCommit = - execSystem('git diff --exit-code --no-patch;echo -n $?').toString() === - '1'; - logger.debug(`Are there changes to commit?: ${thereChangesToCommit}`); - - if (thereChangesToCommit) { - logger.info('There are changes to commit.'); - logger.debug('Commiting'); - execSystem(`git commit -am "Bump ${tag}"`); - logger.info('Commited'); - } else { - logger.info('There are not changes to commit.'); - } - - logger.debug(`Creating tag: ${tag}`); - execSystem( - `git tag -a ${tag} -m "Wazuh ${version} for ${platformID} ${pluginPlatformVersion}"`, - ); - logger.info(`Created tag: ${tag}`); - logger.debug(`Pushing tag ${tag} to remote`); - execSystem(`git push origin ${tag}`); - logger.info(`Pushed tag ${tag} to remote`); - logger.debug('Undoing changes'); - execSystem(`git reset --hard origin/${branch}`); - logger.info('Undone changes'); - } - } - - if (exportTagsToFile) { - logger.debug(`Exporting tags to file ${exportTagsToFile}`); - execSystem( - `git tag | grep -P -i "^v${version}-.*${tagSuffix}" > ${exportTagsToFile}`, - ); - logger.info(`Exported tags to file ${exportTagsToFile}`); - } -} - -async function main(input) { - try { - // Display the help information and exit if there is no parameters - if (input.length === 0) { - displayHelp(); - process.exit(1); - } - - const configuration = { - ...defaultConfiguration, - ...parse(input), - }; - - // Display the configuration - if (configuration.displayConfiguration) { - console.error(configuration); // Send to stderr. This does the configuration can be displayed and redirect the stdout output to a file - } - - // Display the help - if (configuration.displayHelp) { - displayHelp(); - process.exit(0); - } - - // Display the examples of usage - if (configuration.displayExamples) { - displayExamples(); - process.exit(0); - } - - await run(configuration); - } catch (error) { - logger.error(`An unexpected error: ${error}. ${error.stack}`); - process.exit(1); - } -} - -module.exports = run; - -let cliFilePath; - -if (require.main === module) { - cliFilePath = process.argv[1]; - const consoleInputParameters = [...process.argv].slice(2); - main(consoleInputParameters); -}