-
Notifications
You must be signed in to change notification settings - Fork 523
/
release.mk
295 lines (256 loc) · 11.6 KB
/
release.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
.SILENT:
MAKEFLAGS += --no-print-directory
.SHELLFLAGS = -euc
SHELL = /bin/bash
export PATH := $(CURDIR)/bin:$(PATH)
#######################
## Tools
#######################
ARCH = $(shell uname -m)
OS = $(shell uname)
ifeq ($(OS),Darwin)
SED ?= sed -i ".bck"
else
SED ?= sed -i
endif
ifeq ($(ARCH),x86_64)
YQ_ARCH ?= amd64
else
YQ_ARCH ?= arm64
endif
ifeq ($(OS),Darwin)
YQ_BINARY ?= yq_darwin_$(YQ_ARCH)
else
YQ_BINARY ?= yq_linux_$(YQ_ARCH)
endif
YQ ?= yq
YQ_VERSION ?= v4.13.2
#######################
## Properties
#######################
PROJECT_MAJOR_VERSION ?= $(shell echo $(RELEASE_VERSION) | cut -f1 -d.)
PROJECT_MINOR_VERSION ?= $(shell echo $(RELEASE_VERSION) | cut -f2 -d.)
PROJECT_PATCH_VERSION ?= $(shell echo $(RELEASE_VERSION) | cut -f3 -d.)
PROJECT_OWNER ?= elastic
RELEASE_TYPE ?= minor
# if gh is installed only
ifneq ($(shell command -v gh 2>/dev/null),)
CURRENT_RELEASE ?= $(shell gh release list --exclude-drafts --exclude-pre-releases --repo elastic/apm-server --limit 10 --json tagName --jq '.[].tagName|select(. | startswith("v$(PROJECT_MAJOR_VERSION)"))' | sed 's|v||g' | sort -r | head -n 1)
RELEASE_BRANCH ?= $(PROJECT_MAJOR_VERSION).$(PROJECT_MINOR_VERSION)
NEXT_PROJECT_MINOR_VERSION ?= $(PROJECT_MAJOR_VERSION).$(shell expr $(PROJECT_MINOR_VERSION) + 1).0
NEXT_RELEASE ?= $(RELEASE_BRANCH).$(shell expr $(PROJECT_PATCH_VERSION) + 1)
BRANCH_PATCH = update-$(NEXT_RELEASE)
endif
# for the view commits
# as long as 8.x is the branch to run releases, then the base branch is 8.x
# when 8.x is not available the we should use main as the base branch.
CHANGELOG_BRANCH = 8.x
# BASE_BRANCH select by release type (default patch)
ifeq ($(RELEASE_TYPE),minor)
# as long as 8.x is the branch to run releases, then the base branch is 8.x
# when 8.x is not available the we should use main as the base branch.
BASE_BRANCH ?= 8.x
endif
ifeq ($(RELEASE_TYPE),patch)
BASE_BRANCH ?= $(RELEASE_BRANCH)
LATEST_RELEASE ?= $(RELEASE_BRANCH).$(shell expr $(PROJECT_PATCH_VERSION) - 1)
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]
==== 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
#######################
# This is the contract with the GitHub action .github/workflows/run-minor-release.yml.
# The GitHub action will provide the below environment variables:
# - RELEASE_VERSION
#
.PHONY: minor-release
minor-release:
@echo "INFO: Create release branch and update new version $(RELEASE_VERSION)"
$(MAKE) create-branch NAME=$(RELEASE_BRANCH) BASE=$(BASE_BRANCH)
$(MAKE) update-version VERSION=$(RELEASE_VERSION)
$(MAKE) update-version-makefile VERSION=$(PROJECT_MAJOR_VERSION)\.$(PROJECT_MINOR_VERSION)
$(MAKE) create-commit COMMIT_MESSAGE="[Release] update version $(RELEASE_VERSION)"
@echo "INFO: Create feature branch and update the versions. Target branch $(RELEASE_BRANCH)"
$(MAKE) create-branch NAME=changelog-$(RELEASE_BRANCH) BASE=$(RELEASE_BRANCH)
$(MAKE) update-changelog VERSION=$(RELEASE_BRANCH)
$(MAKE) rename-changelog VERSION=$(RELEASE_BRANCH)
$(MAKE) create-commit COMMIT_MESSAGE="docs: Update changelogs for $(RELEASE_BRANCH) release"
@echo "INFO: Create feature branch and update the versions. Target branch $(BASE_BRANCH)"
$(MAKE) create-branch NAME=update-$(RELEASE_VERSION) BASE=$(BASE_BRANCH)
$(MAKE) update-mergify VERSION=$(RELEASE_BRANCH)
$(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) 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"
git push origin $(RELEASE_BRANCH)
$(MAKE) create-pull-request BRANCH=update-$(RELEASE_VERSION) TARGET_BRANCH=$(BASE_BRANCH) TITLE="$(RELEASE_BRANCH): update docs, mergify, versions and changelogs" BODY="Merge as soon as the GitHub checks are green."
$(MAKE) create-pull-request BRANCH=changelog-$(RELEASE_BRANCH) TARGET_BRANCH=$(RELEASE_BRANCH) TITLE="$(RELEASE_BRANCH): update docs" BODY="Merge as soon as $(TARGET_BRANCH) branch is created and the GitHub checks are green."
# This is the contract with the GitHub action .github/workflows/run-patch-release.yml
# The GitHub action will provide the below environment variables:
# - RELEASE_VERSION
#
.PHONY: patch-release
patch-release:
@echo "INFO: Create feature branch and update the versions. Target branch $(RELEASE_BRANCH)"
$(MAKE) create-branch NAME=$(BRANCH_PATCH) BASE=$(RELEASE_BRANCH)
$(MAKE) update-version VERSION=$(RELEASE_VERSION)
$(MAKE) update-version-makefile VERSION=$(PROJECT_MAJOR_VERSION)\.$(PROJECT_MINOR_VERSION)
$(MAKE) update-version-legacy VERSION=$(NEXT_RELEASE) PREVIOUS_VERSION=$(CURRENT_RELEASE)
$(MAKE) create-commit COMMIT_MESSAGE="$(RELEASE_BRANCH): update versions to $(RELEASE_VERSION)"
@echo "INFO: Push changes to $(PROJECT_OWNER)/apm-server and create the relevant Pull Requests"
$(MAKE) create-pull-request BRANCH=$(BRANCH_PATCH) TARGET_BRANCH=$(RELEASE_BRANCH) TITLE="$(RELEASE_VERSION): update versions" BODY="Merge on request by the Release Manager."
############################################
## 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
## Update the references on .mergify.yml with the new minor release.
.PHONY: update-mergify
update-mergify: VERSION=$${VERSION}
update-mergify:
@echo ">> update-mergify"
@if ! grep -q 'backport-$(VERSION)' .mergify.yml ; then \
echo "Update mergify with backport-$(VERSION)" ; \
echo ' - name: backport patches to $(VERSION) branch' >> .mergify.yml ; \
echo ' conditions:' >> .mergify.yml; \
echo ' - merged' >> .mergify.yml; \
echo ' - base=8.x' >> .mergify.yml; \
echo ' - label=backport-$(VERSION)' >> .mergify.yml; \
echo ' actions:' >> .mergify.yml; \
echo ' backport:' >> .mergify.yml; \
echo ' assignees:' >> .mergify.yml; \
echo ' - "{{ author }}"' >> .mergify.yml; \
echo ' branches:' >> .mergify.yml; \
echo ' - "$(VERSION)"' >> .mergify.yml; \
echo ' labels:' >> .mergify.yml; \
echo ' - "backport"' >> .mergify.yml; \
echo ' title: "[{{ destination_branch }}] {{ title }} (backport #{{ number }})"' >> .mergify.yml; \
else \
echo "::warn::Mergify already contains backport-$(VERSION)"; \
fi
## Update the version in the different files with the hardcoded version.
.PHONY: update-version
update-version: VERSION=$${VERSION}
update-version:
@echo ">> update-version"
if [ -f "cmd/intake-receiver/version.go" ]; then \
$(SED) -E -e 's#(version[[:blank:]]*)=[[:blank:]]*"[0-9]+\.[0-9]+\.[0-9]+#\1= "$(VERSION)#g' cmd/intake-receiver/version.go; \
fi
if [ -f "internal/version/version.go" ]; then \
$(SED) -E -e 's#(Version[[:blank:]]*)=[[:blank:]]*"[0-9]+\.[0-9]+\.[0-9]+#\1= "$(VERSION)#g' internal/version/version.go; \
fi
## Update the version in the different files with the hardcoded version. Legacy stuff
## @DEPRECATED: likely in the 7.17 branch
.PHONY: update-version-legacy
update-version-legacy: VERSION=$${VERSION} PREVIOUS_VERSION=$${PREVIOUS_VERSION}
update-version-legacy:
@echo ">> update-version-legacy"
if [ -f "cmd/version.go" ]; then \
$(SED) -E -e 's#(defaultBeatVersion[[:blank:]]*)=[[:blank:]]*"[0-9]+\.[0-9]+\.[0-9]+#\1= "$(VERSION)#g' cmd/version.go; \
fi
## Update project version in the Makefile.
.PHONY: update-version-makefile
update-version-makefile: VERSION=$${VERSION}
update-version-makefile:
@echo ">> update-version-makefile"
$(SED) -E -e 's#BEATS_VERSION\s*\?=\s*(([0-9]+\.[0-9]+)|main)#BEATS_VERSION\?=$(VERSION)#g' Makefile
############################################
## Internal make goals to interact with Git
############################################
## Create a new branch
## It will delete the branch if it already exists before the creation.
.PHONY: create-branch
create-branch: NAME=$${NAME} BASE=$${BASE}
create-branch:
@echo "::group::create-branch $(NAME)"
git checkout $(BASE)
git branch -D $(NAME) &>/dev/null || true
git checkout $(BASE) -b $(NAME)
@echo "::endgroup::"
## Create a new commit only if there is a diff.
.PHONY: create-commit
create-commit:
$(MAKE) git-diff
@echo "::group::create-commit"
if [ ! -z "$$(git status -s)" ]; then \
git status -s; \
git add --all; \
git commit --gpg-sign -a -m "$(COMMIT_MESSAGE)"; \
fi
@echo "::endgroup::"
## @help:create-pull-request:Create pull request
.PHONY: create-pull-request
create-pull-request: BRANCH=$${BRANCH} TITLE=$${TITLE} TARGET_BRANCH=$${TARGET_BRANCH} BODY=$${BODY}
create-pull-request:
@echo "::group::create-pull-request"
git push origin $(BRANCH)
gh pr create \
--title "$(TITLE)" \
--body "$(BODY)" \
--base $(TARGET_BRANCH) \
--head $(BRANCH) \
--label 'release' \
--reviewer "$(PROJECT_REVIEWERS)" \
--repo $(PROJECT_OWNER)/apm-server || echo "There is no changes"
@echo "::endgroup::"
## Diff output
.PHONY: git-diff
git-diff:
@echo "::group::git-diff"
git --no-pager diff || true
@echo "::endgroup::"