Skip to content

Commit

Permalink
Bump the changelog file using the bump script (#5963)
Browse files Browse the repository at this point in the history
* feat: bump changelgo file with bump utility

* feat: adapt package scripts to use the manifest changelog

* feat: add references to the releasing documentation about bump script and others enhancement

* feat: enhance regular expression in bump utility
  • Loading branch information
Desvelao authored Oct 30, 2023
1 parent 7385d04 commit 250d234
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 19 deletions.
64 changes: 50 additions & 14 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <api_spec_file_URL>
```

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`.

Expand Down Expand Up @@ -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 <tag-suffix>` flag.

```
```console
yarn release:tag --tag-suffix <tag-suffix> <options>
```

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 <file>`.

```
```console
yarn release:tag --revision <bump_revision> --export-tags <file>
```

Example:

```
```console
yarn release:tag --version 4.5.0 --export-tags tags.log
```

Expand Down Expand Up @@ -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 <version/revision/platform version>"
git push origin <branch_name>
```

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 <base_branch> -t "Bump Wazuh version <version>"
```
4 changes: 2 additions & 2 deletions plugins/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
24 changes: 24 additions & 0 deletions plugins/main/scripts/release/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ const defaultConfiguration = {
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');

/**
*
Expand Down Expand Up @@ -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: {
}
}
Expand All @@ -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 <manifest-changelog> Set the changelog manifest file location.
--manifest-package <manifest-package> Set the package manifest file location.
--manifest-plugin <manifest-plugin> Set the plugin platform manifest file location.
--platform-version <platform-version> Set the platform version.
Expand Down Expand Up @@ -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.',
Expand All @@ -233,6 +251,12 @@ function run(configuration) {
revision,
});

updateChangelog(manifestChangelog, {
version,
revision,
platformVersion,
});

displayMessageManualChanges();
}

Expand Down
63 changes: 63 additions & 0 deletions plugins/main/scripts/release/lib/update-changelog.js
Original file line number Diff line number Diff line change
@@ -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 <path/to/file>.`,
);
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,
};
21 changes: 18 additions & 3 deletions plugins/main/scripts/release/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const defaultConfiguration = {
ignoreConfirmation: false,
manifestPackage: '',
manifestPlugin: '',
manifestChangelog: '',
tagSuffix: '',
exportTagsToFile: '',
};
Expand Down Expand Up @@ -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: {
}
}
Expand All @@ -226,6 +240,7 @@ const usageOptionsMessage = `Options:
--export-tags <path/to/file> Export tags to file.
--help Display the help.
--ignore-confirmation Ignore the confirmation.
--manifest-changelog <manifest-changelog> Set the changelog manifest file location.
--manifest-package <manifest-package> Set the package manifest file location.
--manifest-plugin <manifest-plugin> Set the plugin platform manifest file location.
--platform-version <platform-version> Set the platform version.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 250d234

Please sign in to comment.