diff --git a/RELEASING.md b/RELEASING.md index b6e18cab94..fb8ae04435 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -24,11 +24,35 @@ The following files must be updated: 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 +file that is stored in the GitHub repository of [wazuh/wazuh](https://github.com/wazuh/wazuh) repository. This must run for each version. + +```console +yarn generate:api-data --spec +``` + +Examples: + +- Update the files with a final tag + +``` +yarn generate:api-data --spec https://raw.githubusercontent.com/wazuh/wazuh/v4.6.0/api/api/spec/spec.yaml +``` + +- Update the files with a pre-release tag + +``` +yarn generate:api-data --spec https://raw.githubusercontent.com/wazuh/wazuh/v4.6.0-rc1/api/api/spec/spec.yaml +``` + #### Create tags After the base branches have set the expected [# Files](#files), we must create the tags. The tag name follows the pattern: + - final release tag: `v{version}-{platform version}`. Example: `v4.4.5-2.6.0`. - non-final release tag: `v{version}-{platform version}{suffix}`. Example: `v4.4.5-2.6.0-pre-alpha1`, `v4.4.5-2.6.0-alpha1`, `v4.4.5-2.6.0-rc1`. @@ -112,45 +136,49 @@ Examples: - Change the plugin version -``` +```console yarn release:tag --version 4.5.0 ``` + - Change the plugin revision -``` +```console yarn release:tag --revision 02 ``` + - Change the platform version -``` +```console yarn release:tag --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 ``` + For tags that needs a suffix, use the `--tag-suffix ` flag. -``` +```console yarn release:tag --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 ``` @@ -208,36 +236,44 @@ Examples: - Change the plugin version -``` +```console yarn release:bump --version 4.5.0 ``` - Change the plugin revision -``` +```console yarn release:bump --revision 02 ``` - Change the platform version -``` +```console yarn release:bump --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 ``` 3. Apply manually the changes to the rest of files if needed it. See [# Files](#Files). -4. Optional. Commit and push the new branch to the remote repository. +4. Commit and push the new branch to the remote repository. -``` +```console git add . git commit -m "bump: Bump version/revision/platform version to " git push origin ``` A new branch will be created in the remote and will be ready to receive pull requests or use as source to create the tags. + +5. Create a pull request + +If you have installed the [GitHub CLI](https://cli.github.com/): + +```console +gh pr create -a @me -B -t "Bump Wazuh version " +``` diff --git a/plugins/main/package.json b/plugins/main/package.json index 1b3f7c4ca5..5c79eae172 100644 --- a/plugins/main/package.json +++ b/plugins/main/package.json @@ -41,8 +41,8 @@ "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", - "release:tag": "node scripts/release/tag --manifest-package package.json", + "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": { diff --git a/plugins/main/scripts/release/bump.js b/plugins/main/scripts/release/bump.js index 68fa65b65c..27c4ec0409 100644 --- a/plugins/main/scripts/release/bump.js +++ b/plugins/main/scripts/release/bump.js @@ -23,6 +23,7 @@ const defaultConfiguration = { platformVersion: '', manifestPackage: '', manifestPlugin: '', + manifestChangelog: '', }; const logger = require('./lib/logger'); @@ -30,6 +31,7 @@ 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'); /** * @@ -147,6 +149,19 @@ function parse(input) { } 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: { } } @@ -159,6 +174,7 @@ const usageOptionsMessage = `Options: --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. @@ -211,12 +227,14 @@ function run(configuration) { 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.', @@ -233,6 +251,12 @@ function run(configuration) { revision, }); + updateChangelog(manifestChangelog, { + version, + revision, + platformVersion, + }); + displayMessageManualChanges(); } diff --git a/plugins/main/scripts/release/lib/update-changelog.js b/plugins/main/scripts/release/lib/update-changelog.js new file mode 100644 index 0000000000..cb24a07d13 --- /dev/null +++ b/plugins/main/scripts/release/lib/update-changelog.js @@ -0,0 +1,63 @@ +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/tag.js b/plugins/main/scripts/release/tag.js index 8d89315709..50bd2ff1d4 100644 --- a/plugins/main/scripts/release/tag.js +++ b/plugins/main/scripts/release/tag.js @@ -33,6 +33,7 @@ const defaultConfiguration = { ignoreConfirmation: false, manifestPackage: '', manifestPlugin: '', + manifestChangelog: '', tagSuffix: '', exportTagsToFile: '', }; @@ -212,6 +213,19 @@ function parse(input) { } 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: { } } @@ -226,6 +240,7 @@ const usageOptionsMessage = `Options: --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. @@ -294,13 +309,13 @@ async function question(question) { 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.', + '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.', + 'deleting any unpushed changes.', ); if (!ignoreConfirmation) {