@@ -10,6 +10,7 @@ SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
10
REPO_PATH=$( git rev-parse --show-toplevel 2> /dev/null)
11
11
DATE_TIME=$( date " +%Y-%m-%d_%H-%M-%S-%3N" )
12
12
LOG_FILE=" ${SCRIPT_PATH} /repository_bumper_${DATE_TIME} .log"
13
+ PACKAGE_JSON=" ${REPO_PATH} /package.json"
13
14
WAZUH_DASHBOARD_ML_COMMONS_WORKFLOW_FILE=" ${REPO_PATH} /.github/workflows/4_builderpackage_ml_commons_plugin.yml"
14
15
VERSION_FILE=" ${REPO_PATH} /VERSION.json"
15
16
VERSION=" "
@@ -370,6 +371,62 @@ update_package_json() {
370
371
fi
371
372
}
372
373
374
+ # Function to update CHANGELOG.md
375
+ update_changelog () {
376
+ log " Updating CHANGELOG.md..."
377
+ local changelog_file=" ${REPO_PATH} /CHANGELOG.md"
378
+
379
+ # Extract OpenSearch Dashboards version from package.json
380
+ # Attempt to extract OpenSearch Dashboards version using sed (WARNING: Fragile!)
381
+ # This assumes "pluginPlatform": { ... "version": "x.y.z" ... } structure
382
+ # It looks for the block starting with "pluginPlatform": { and ending with }
383
+ # Within that block, it finds the line starting with "version": "..." and extracts the value.
384
+ # This is significantly less reliable than using jq.
385
+ log " Attempting to extract .version from $VERSION_FILE using sed (Note: This is fragile)"
386
+ # Extract OpenSearch Dashboards version from package.json (first occurrence of "version")
387
+ OPENSEARCH_VERSION=$( sed -n ' s/^[[:space:]]*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*$/\1/p' " $PACKAGE_JSON " | head -n 1)
388
+ if [ -z " $OPENSEARCH_VERSION " ] || [ " $OPENSEARCH_VERSION " == " null" ]; then
389
+ log " ERROR: Could not extract pluginPlatform.version from $PACKAGE_JSON for changelog"
390
+ exit 1
391
+ fi
392
+ log " Detected OpenSearch Dashboards version for changelog: $OPENSEARCH_VERSION "
393
+
394
+ # Construct the new changelog entry
395
+ # Note: Using printf for better handling of newlines and potential special characters
396
+ # Use the calculated REVISION variable here
397
+ # Prepare the header to search for
398
+ local changelog_header=" ## Wazuh dashboard v${VERSION} - OpenSearch Dashboards ${OPENSEARCH_VERSION} - Revision "
399
+ local changelog_header_regex=" ^${changelog_header} [0-9]+"
400
+
401
+ # Check if an entry for this version and OpenSearch version already exists
402
+ if grep -qE " $changelog_header_regex " " $changelog_file " ; then
403
+ if [ -n " $STAGE " ]; then
404
+ log " Changelog entry for this version and OpenSearch Dashboards version exists. Updating revision only."
405
+ # Use sed to update only the revision number in the header
406
+ sed_inplace -E " s|(${changelog_header_regex} )|${changelog_header}${REVISION} |" " $changelog_file " &&
407
+ log " CHANGELOG.md revision updated successfully." || {
408
+ log " ERROR: Failed to update revision in $changelog_file "
409
+ exit 1
410
+ }
411
+ fi
412
+ else
413
+ log " No existing changelog entry for this version and OpenSearch Dashboards version. Inserting new entry."
414
+
415
+ # Create the new entry directly in the changelog using sed
416
+ local temp_file=$( mktemp)
417
+ head -n 4 " $changelog_file " > " $temp_file "
418
+ printf " \n## Wazuh v%s - OpenSearch Dashboards %s - Revision %s\n\n### Added\n\n- Support for Wazuh %s\n\n" " $VERSION " " $OPENSEARCH_VERSION " " $REVISION " " $VERSION " >> " $temp_file "
419
+ tail -n +5 " $changelog_file " >> " $temp_file "
420
+
421
+ mv " $temp_file " " $changelog_file " || {
422
+ log " ERROR: Failed to update $changelog_file "
423
+ rm -f " $temp_file " # Clean up temp file on error
424
+ exit 1
425
+ }
426
+ log " CHANGELOG.md updated successfully."
427
+ fi
428
+ }
429
+
373
430
update_manual_build_workflow () {
374
431
local WORKFLOW_FILE=" $WAZUH_DASHBOARD_ML_COMMONS_WORKFLOW_FILE "
375
432
if [ -f " $WORKFLOW_FILE " ]; then
@@ -489,6 +546,7 @@ main() {
489
546
490
547
update_root_version_json
491
548
update_package_json
549
+ update_changelog
492
550
update_manual_build_workflow
493
551
494
552
# Update docker/imposter/wazuh-config.yml
0 commit comments