Skip to content

ci: update changelog release automation #16358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/release-notes/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ mapped_pages:

Breaking changes can impact your Elastic applications, potentially disrupting normal operations. Before you upgrade, carefully review the Elastic APM breaking changes and take the necessary steps to mitigate any issues. To learn how to upgrade, check [Upgrade](docs-content://deploy-manage/upgrade.md).

% ## Next version [next-version]
## Next version [next-version]
% **Release date:** Month day, year

% ::::{dropdown} Title of breaking change
% Description of the breaking change.
% For more information, check [#PR-number]({{apm-pull}}PR-number).

%
% **Impact**<br> Impact of the breaking change.

%
% **Action**<br> Steps for mitigating deprecation impact.
% ::::

Expand Down
4 changes: 2 additions & 2 deletions docs/release-notes/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Over time, certain Elastic functionality becomes outdated and is replaced or rem

Review the deprecated functionality for Elastic APM. While deprecations have no immediate impact, we strongly encourage you update your implementation after you upgrade. To learn how to upgrade, check out [Upgrade](docs-content://deploy-manage/upgrade.md).

% ## Next version [next-version]
## Next version [next-version]
% **Release date:** Month day, year

% ::::{dropdown} Deprecation title
Expand All @@ -25,4 +25,4 @@ Review the deprecated functionality for Elastic APM. While deprecations have no
% For more information, check [PR #](PR link).
% **Impact**<br> Impact of deprecation.
% **Action**<br> Steps for mitigating deprecation impact.
% ::::
% ::::
6 changes: 3 additions & 3 deletions docs/release-notes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ To check for security updates, go to [Security announcements for the Elastic sta
% Release notes include only features, enhancements, and fixes. Add breaking changes, deprecations, and known issues to the applicable release notes sections.
% For each new version section, include the Elastic APM and Kibana changes.

% ## version.next [elastic-apm-next-release-notes]
## version.next [elastic-apm-next-release-notes]
% **Release date:** Month day, year

% ### Features and enhancements [elastic-apm-next-features-enhancements]
### Features and enhancements [elastic-apm-next-features-enhancements]

% ### Fixes [elastic-apm-next-fixes]
### Fixes [elastic-apm-next-fixes]

## 9.0.0 [9-0-0]
**Release date:** April 2, 2025
Expand Down
81 changes: 4 additions & 77 deletions release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ NEXT_RELEASE ?= $(RELEASE_BRANCH).$(shell expr $(PROJECT_PATCH_VERSION) + 1)
BRANCH_PATCH = update-$(NEXT_RELEASE)
endif

# for the view commits
# NOTE: as long as 8.x is the branch to run releases, then we use base branch 8.x
# when 8.x is not available then we use the main base branch.
CHANGELOG_BRANCH = 8.x

# BASE_BRANCH select by release type (default patch)
ifeq ($(RELEASE_TYPE),minor)
# NOTE: as long as 8.x is the branch to run releases, then we use base branch 8.x
Expand All @@ -68,50 +63,9 @@ endif

ifeq ($(RELEASE_TYPE),major)
BASE_BRANCH ?= main
CHANGELOG_BRANCH = main
UPDATE_MERGIFY = true
endif

#######################
## Templates
#######################
## Changelog template
define CHANGELOG_TMPL
[[release-notes-head]]
== APM version HEAD

https://github.com/elastic/apm-server/compare/$(RELEASE_BRANCH)\...$(CHANGELOG_BRANCH)[View commits]

[float]
==== Breaking Changes

[float]
==== Bug fixes

[float]
==== Deprecations

[float]
==== Intake API Changes

[float]
==== Added
endef

## Changelog template for new minors
define CHANGELOG_MINOR_TMPL
[[apm-release-notes-$(RELEASE_BRANCH)]]
== APM version $(RELEASE_BRANCH)
* <<apm-release-notes-$(RELEASE_BRANCH).0>>

[float]
[[apm-release-notes-$(RELEASE_BRANCH).0]]
=== APM version $(RELEASE_BRANCH).0

https://github.com/elastic/apm-server/compare/v$(CURRENT_RELEASE)\...v$(RELEASE_BRANCH).0[View commits]

endef

#######################
## Public make goals
#######################
Expand All @@ -137,8 +91,7 @@ minor-release:
# BASE=$(RELEASE_BRANCH)
# Target main and use the backport strategy
$(MAKE) create-branch NAME=changelog-$(RELEASE_BRANCH) BASE=main
$(MAKE) update-changelog VERSION=$(RELEASE_BRANCH)
$(MAKE) rename-changelog VERSION=$(RELEASE_BRANCH)
$(MAKE) update-changelog VERSION=$(RELEASE_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="docs: Update changelogs for $(RELEASE_BRANCH) release"

# NOTE: as long as 8.x is the branch to run releases, then we update mergify
Expand All @@ -161,7 +114,7 @@ endif
#endif
$(MAKE) update-version VERSION=$(NEXT_PROJECT_MINOR_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="[Release] update version $(NEXT_PROJECT_MINOR_VERSION)"
$(MAKE) rename-changelog VERSION=$(RELEASE_BRANCH)
$(MAKE) update-changelog VERSION=$(RELEASE_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="[Release] update changelogs for $(RELEASE_BRANCH) release"

@echo "INFO: Push changes to $(PROJECT_OWNER)/apm-server and create the relevant Pull Requests"
Expand All @@ -183,7 +136,7 @@ endif
#
.PHONY: major-release
major-release:
# NOTE: major release uses minor-release with BASE_BRANCH=main and CHANGELOG_BRANCH=main
# NOTE: major release uses minor-release with BASE_BRANCH=main
$(MAKE) minor-release

# This is the contract with the GitHub action .github/workflows/run-patch-release.yml
Expand All @@ -205,38 +158,12 @@ patch-release:
## Internal make goals to bump versions
############################################

# Rename changelog file to generate something similar to https://github.com/elastic/apm-server/pull/12172
.PHONY: rename-changelog
export CHANGELOG_TMPL
rename-changelog: VERSION=$${VERSION}
rename-changelog:
$(MAKE) common-changelog
@echo ">> rename-changelog"
echo "$$CHANGELOG_TMPL" > changelogs/head.asciidoc
@if ! grep -q 'apm-release-notes-$(VERSION)' CHANGELOG.asciidoc ; then \
awk "NR==2{print \"* <<apm-release-notes-$(VERSION)>>\"}1" CHANGELOG.asciidoc > CHANGELOG.asciidoc.new; \
mv CHANGELOG.asciidoc.new CHANGELOG.asciidoc ; \
fi
@if ! grep -q '$(VERSION).asciidoc' CHANGELOG.asciidoc ; then \
$(SED) -E -e 's#(head.asciidoc\[\])#\1\ninclude::.\/changelogs\/$(VERSION).asciidoc[]#g' CHANGELOG.asciidoc; \
fi

# Update changelog file to generate something similar to https://github.com/elastic/apm-server/pull/12220
.PHONY: update-changelog
update-changelog: VERSION=$${VERSION}
update-changelog:
$(MAKE) common-changelog
@echo ">> update-changelog"
$(SED) 's#head#$(VERSION)#g' CHANGELOG.asciidoc

# Common changelog file steps
.PHONY: common-changelog
export CHANGELOG_MINOR_TMPL
common-changelog: VERSION=$${VERSION}
common-changelog:
@echo ">> common-changelog"
echo "$$CHANGELOG_MINOR_TMPL" > changelogs/$(VERSION).asciidoc
tail -n +6 changelogs/head.asciidoc >> changelogs/$(VERSION).asciidoc
bash ./tools/scripts/changelog.sh $(VERSION)

## Update the references on .mergify.yml with the new minor release.
.PHONY: update-mergify
Expand Down
105 changes: 105 additions & 0 deletions tools/scripts/changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/bash
#
# This script:
# - updates the 'Next version' in breaking-changes.md to match the specified version
# - add back the 'Next version' section, with template

set -eou pipefail

# Ugly but needed for MacOS. Sed on MacOS fails when calling sed --help with an illegal argument exception.
# Exploit this to check if the user has a bad sed version and exit early.
if ! sed --help >/dev/null 2>&1; then
echo "sed does not look like GNU sed. Are you running on MacOS perhaps? Install GNU sed, make it so you can call it with sed and retry"
exit 8
fi

updateFile() {
local file
file=$1

newfile="newfile.md"

# get the line where we will introduce back the next version section
LN=$(grep -n "## Next version" "$file" | head -1 | grep -Eo '^[^:]+')
# replace next version with actual version (with HTTP anchor)
anchor=$(echo "$VERSION" | tr . -)

# create the new file content
# take lines up to next version
head -n "$(($LN - 1))" "$file" > "$newfile"
# add back the next version section
cat >> "$newfile" << 'EOS'
## Next version [next-version]
% **Release date:** Month day, year

% ::::{dropdown} Title of breaking change
% Description of the breaking change.
% For more information, check [#PR-number]({{apm-pull}}PR-number).
%
% **Impact**<br> Impact of the breaking change.
%
% **Action**<br> Steps for mitigating deprecation impact.
% ::::

EOS
# add the rest of the file, replace next section with version
tail -n+$LN "$file" | \
sed "s|## Next version.*|## $VERSION [$anchor]|g" /dev/stdin >> "$newfile"
# replace breaking change file with new content
mv "$newfile" "$file"
}

updateBreakingChanges() {
updateFile "./docs/release-notes/breaking-changes.md"
}

updateDeprecations() {
updateFile "./docs/release-notes/deprecations.md"
}

updateIndex() {
file=./docs/release-notes/index.md
newfile="newfile.md"

# get the line where we will introduce back the next version section
LN=$(grep -n "## version.next" "$file" | head -1 | grep -Eo '^[^:]+')
# replace next version with actual version (with HTTP anchor)
anchor=$(echo "$VERSION" | tr . -)

# create the new file content
# take lines up to next version
head -n "$(($LN - 1))" "$file" > "$newfile"
# add back the next version section
cat >> "$newfile" << 'EOS'
## version.next [elastic-apm-next-release-notes]
% **Release date:** Month day, year

### Features and enhancements [elastic-apm-next-features-enhancements]

%* 1 sentence describing the change. ([#PR number](https://github.com/elastic/apm-server/pull/PR number))

### Fixes [elastic-apm-next-fixes]

%* 1 sentence describing the change. ([#PR number](https://github.com/elastic/apm-server/pull/PR number))

EOS
# add the rest of the file, replace next section with version
tail -n+$LN "$file" | \
sed "s|## version.next.*|## $VERSION [$anchor]|g" /dev/stdin >> "$newfile"
# replace breaking change file with new content
mv "$newfile" "$file"
}


VERSION=${1:-}

test -z VERSION && {
echo "VERSION is required"
exit 2
}

echo ">> updating changelog for $VERSION"

updateBreakingChanges
updateDeprecations
updateIndex
Loading